Skip to content

Commit cf5eb0f

Browse files
committed
tests: ensure historical padding does not win correction ties
1 parent 8763378 commit cf5eb0f

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

‎tests/test_crc.py‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@
1010
from codex32.checksums import _CRC, _crc_pad
1111
from codex32.correction import _best
1212
from codex32.gf32 import _multiply as _gf32_multiply
13-
from codex32.profiles.ms32 import (
14-
SEED_BYTE_LENGTHS,
15-
_has_generation_padding,
16-
_has_legacy_generation_padding,
17-
_payload_padding,
18-
)
13+
from codex32.profiles.ms32 import SEED_BYTE_LENGTHS, _has_generation_padding, _payload_padding
1914

2015

2116
@pytest.mark.parametrize(
@@ -65,19 +60,24 @@ def test_parsed_master_seed_validity_is_independent_of_crc() -> None:
6560
assert generated.payload_symbols in {secret.payload_symbols for secret in parsed}
6661

6762

68-
def test_tie_break_prefers_current_then_legacy_crc_padding() -> None:
63+
def test_tie_break_prefers_only_current_crc_padding() -> None:
6964
parsed = [parse_codex32(VECTOR_4[f"secret_s_alternate_{padding}"]) for padding in range(16)]
7065
assert all(isinstance(secret, MasterSeed) for secret in parsed)
7166
current = next(secret for secret in parsed if _has_generation_padding(secret))
72-
legacy = next(secret for secret in parsed if _has_legacy_generation_padding(secret))
73-
other = next(secret for secret in parsed if secret not in (current, legacy))
74-
75-
def best(*secrets: MasterSeed) -> tuple[MasterSeed, ...]:
76-
candidates = [CorrectionCandidate(s, (), 1, 0, 0, _has_generation_padding(s)) for s in secrets]
77-
return tuple(candidate.artifact for candidate in _best(candidates))
78-
79-
assert best(other, legacy, current) == (current,)
80-
assert best(other, legacy) == (legacy,)
67+
previous = parsed[8] # Pad suffix produced before the final XOR was added.
68+
other = parsed[0]
69+
assert current not in (previous, other)
70+
71+
def candidates(*secrets: MasterSeed) -> list[CorrectionCandidate]:
72+
return [CorrectionCandidate(s, (), 1, 0, 0, _has_generation_padding(s)) for s in secrets]
73+
74+
assert tuple(item.artifact for item in _best(candidates(other, previous, current))) == (current,)
75+
# Without a current CRC match, neither historical nor arbitrary padding wins.
76+
tied = tuple(item.artifact for item in _best(candidates(other, previous)))
77+
assert tied == tuple(sorted((other, previous), key=lambda secret: secret.text.lower()))
78+
# The wallet hint can decide the tie without being overridden by historical padding.
79+
hinted = _best(candidates(other, previous), fingerprint_match=lambda item: item.artifact == other)
80+
assert tuple(item.artifact for item in hinted) == (other,)
8181

8282

8383
def test_padding_acceptance_is_balanced_for_every_nonzero_lagrange_weight() -> None:

0 commit comments

Comments
 (0)