Skip to content

Commit 68d7fb9

Browse files
committed
feat(mnemonic): improve invalid size test strategies
Refactor property-based tests for mnemonic generation to better handle invalid word counts. Ensures zero is excluded from wrong count cases and removes redundant hypothesis assumptions. This enhances test clarity and coverage for edge cases.
1 parent 4e7ce5e commit 68d7fb9

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

cardano_node_tests/tests/test_mnemonic.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ def maybe_reencode(text: str) -> st.SearchStrategy[bytes]:
160160
@st.composite
161161
def wrong_count_files(draw: st.DrawFn) -> BadMnemonicCase:
162162
"""Wrong number of words (not in {12, 15, 18, 21, 24})."""
163-
count = draw(st.integers(min_value=0, max_value=48).filter(lambda n: n not in _ALLOWED_COUNTS))
164-
hypothesis.assume(count != 0) # Zero handled by empty_file elsewhere
163+
# Zero handled by empty_file elsewhere
164+
count = draw(st.integers(min_value=1, max_value=48).filter(lambda n: n not in _ALLOWED_COUNTS))
165165
tokens = draw(word_sequence(count=count, ensure_invalid=False))
166166
line = draw(join_with_weirdness(tokens=tokens))
167167
content = draw(maybe_reencode(line))
@@ -429,7 +429,7 @@ def tmp_case_path(self) -> tp.Generator[pl.Path, None, None]:
429429
shutil.rmtree(d)
430430

431431
@allure.link(helpers.get_vcs_link())
432-
@hypothesis.given(size=st.integers())
432+
@hypothesis.given(size=st.integers().filter(lambda n: n not in _ALLOWED_COUNTS))
433433
@common.hypothesis_settings(max_examples=1_000)
434434
@pytest.mark.smoke
435435
def test_gen_invalid_size(
@@ -438,8 +438,6 @@ def test_gen_invalid_size(
438438
size: int,
439439
):
440440
"""Test generating a mnemonic with an invalid size."""
441-
hypothesis.assume(size not in _ALLOWED_COUNTS)
442-
443441
common.get_test_id(cluster)
444442
with pytest.raises(clusterlib.CLIError) as excinfo:
445443
cluster.g_key.gen_mnemonic(size=size) # type: ignore

0 commit comments

Comments
 (0)