Skip to content

Commit 341ccc7

Browse files
committed
Tests: keep wallet fingerprints seed-sensitive
Separate wallet-derived fingerprints from BIP93 vector semantics while retaining one central fixture table. Unknown seeds now use a deterministic seed-sensitive test double, so generation tests still catch passing the wrong seed to the fingerprint callback without restoring the removed Python wallet dependency. Real Core-derived fixtures remain the oracle for known seeds; tools/bitcoin_core_regtest.py verifies those values. CI integration of that verifier remains tracked separately in #9. refs #3 Validation: 336 focused tests passed; ruff check passed; git diff --check passed.
1 parent 8280e21 commit 341ccc7

4 files changed

Lines changed: 53 additions & 13 deletions

File tree

‎tests/test_correction_indel.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
_search_target,
3333
)
3434
from codex32.profiles.ms32 import TEXT_LENGTHS
35-
from tools._wallet_test_vectors import core_fingerprint
35+
from tools._wallet_test_vectors import FIXTURE_SEED, core_fingerprint
3636
from tools.correction_capture import cross_length_classes
3737

3838
SOURCE = VECTOR_1["secret_s"]
@@ -410,7 +410,7 @@ def test_duplicate_reconstruction_keeps_lower_hamming_path() -> None:
410410

411411

412412
def test_cli_tie_breaks_follow_hamming_crc_then_fingerprint() -> None:
413-
seed = bytes.fromhex(VECTOR_1["secret_hex"])
413+
seed = FIXTURE_SEED[16]
414414
fingerprint = MasterSeed.from_seed(seed, identifier=_fingerprint_identifier(core_fingerprint(seed)))
415415
mismatch = MasterSeed.from_seed(seed, identifier="test")
416416
high_hamming = CorrectionCandidate(mismatch, (), 10, 0, 3, True)

‎tests/test_generation.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import pytest
88
from _codex32_oracle import oracle_encode
9-
from data.bip93_vectors import VECTOR_1, VECTOR_2, VECTOR_3, VECTOR_4, VECTOR_6
9+
from data.bip93_vectors import VECTOR_2, VECTOR_4, VECTOR_6
1010
from data.sharing_vectors import SHARING_VECTORS
1111
from hypothesis import given, settings
1212
from hypothesis import strategies as st
@@ -33,7 +33,7 @@
3333
)
3434
from codex32.generation import ORDINARY_INDICES, _fingerprint_identifier
3535
from codex32.profiles.ms32 import SEED_BYTE_LENGTHS, _has_generation_padding
36-
from tools._wallet_test_vectors import core_fingerprint, stub_fingerprint
36+
from tools._wallet_test_vectors import FIXTURE_SEED, core_fingerprint, stub_fingerprint
3737

3838

3939
def _complete(ceremony: CreationCeremony) -> tuple[MasterSeed | CoreLightningSecret, tuple[Share, ...]]:
@@ -67,11 +67,11 @@ def test_fresh_unshared_ms_supports_every_bip93_size() -> None:
6767

6868

6969
@pytest.mark.parametrize(
70-
("vector", "expected"),
71-
((VECTOR_1, "8u6j"), (VECTOR_2, "l2mg"), (VECTOR_3, "regv")),
70+
("byte_length", "expected"),
71+
((16, "3mga"), (20, "ex5l"), (24, "fhrx"), (28, "5hu7"), (32, "jef7"), (64, "48dx")),
7272
)
73-
def test_unshared_identifier_from_core_fingerprint(vector: dict[str, str], expected: str) -> None:
74-
seed = bytes.fromhex(vector["secret_hex"])
73+
def test_unshared_identifier_from_core_fingerprint(byte_length: int, expected: str) -> None:
74+
seed = FIXTURE_SEED[byte_length]
7575
assert _fingerprint_identifier(core_fingerprint(seed)) == expected
7676

7777

‎tests/test_generic_hrp.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
)
2020
from codex32.cli import main, ms_main
2121
from codex32.errors import MismatchedHrp, MismatchedProfile
22+
from tools._wallet_test_vectors import STUB_FINGERPRINT
2223

2324
UNKNOWN = {
2425
"short": {
@@ -170,7 +171,7 @@ def test_cli_share_is_generic_and_ms32_share_is_scoped(monkeypatch) -> None:
170171
class _FakeCore:
171172
@staticmethod
172173
def fingerprint(_secret: object) -> bytes:
173-
return b"\0\0\0\0"
174+
return STUB_FINGERPRINT
174175

175176
monkeypatch.setattr("codex32.cli.BitcoinCore.connect", lambda *args, **kwargs: _FakeCore())
176177
basis = UNKNOWN["short"]["S"] + "\n" + UNKNOWN["short"]["A"] + "\n"

‎tools/_wallet_test_vectors.py‎

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,47 @@
1-
"""Bitcoin Core-derived public wallet fixtures used by tests and integration checks."""
1+
"""Bitcoin Core-derived public wallet fixtures used by tests and integration checks.
22
3-
CORE_FINGERPRINTS = {
3+
Everything here is a BIP32 master fingerprint, which is a wallet property and not a
4+
codex32 one. Some seeds below also appear as BIP93 test vectors, but only as convenient
5+
public seed material: BIP93 assigns those vectors identifiers of its own (``test``,
6+
``name``, ``cash``) that have nothing to do with these fingerprints. An identifier
7+
derived from a fingerprint is therefore never a BIP93-specified value, so assert such
8+
identifiers against ``FIXTURE_SEED`` rather than against vector material.
9+
10+
``tools/bitcoin_core_regtest.py`` verifies every fingerprint below against real Core.
11+
"""
12+
13+
import hashlib
14+
15+
# BIP93 vector seeds, reused here only as wallet fixtures.
16+
_VECTOR_FINGERPRINTS = {
417
bytes.fromhex("318c6318c6318c6318c6318c6318c631"): bytes.fromhex("3f3521a6"),
518
bytes.fromhex("d1808e096b35b209ca12132b264662a5"): bytes.fromhex("fab6868a"),
619
bytes.fromhex("ffeeddccbbaa99887766554433221100"): bytes.fromhex("1e50c111"),
720
}
821

22+
# Arbitrary fixtures, one per BIP93 seed length, carrying no test-vector meaning.
23+
_FIXTURE_FINGERPRINTS = {
24+
bytes.fromhex("107dea57c4319e0b78e552bf2c990673"): bytes.fromhex("8ed1dab8"),
25+
bytes.fromhex("1481ee5bc835a20f7ce956c3309d0a77e451be2b"): bytes.fromhex("c9a9f9c8"),
26+
bytes.fromhex("1885f25fcc39a61380ed5ac734a10e7be855c22f9c0976e3"): bytes.fromhex("4dc66f0e"),
27+
bytes.fromhex("1c89f663d03daa1784f15ecb38a5127fec59c633a00d7ae754c12e9b"): bytes.fromhex("a5f9e972"),
28+
bytes.fromhex("208dfa67d441ae1b88f562cf3ca91683f05dca37a4117eeb58c5329f0c79e653"): bytes.fromhex(
29+
"9653e4ec"
30+
),
31+
bytes.fromhex(
32+
"40ad1a87f461ce3ba81582ef5cc936a3107dea57c4319e0b78e552bf2c990673"
33+
"e04dba2794016edb48b5228ffc69d643b01d8af764d13eab1885f25fcc39a613"
34+
): bytes.fromhex("a9da6294"),
35+
}
36+
37+
CORE_FINGERPRINTS = _VECTOR_FINGERPRINTS | _FIXTURE_FINGERPRINTS
38+
39+
# Arbitrary fixture seed by byte length; excludes vector material by construction.
40+
FIXTURE_SEED = {len(seed): seed for seed in _FIXTURE_FINGERPRINTS}
41+
42+
# Stands in where the fingerprint value itself is irrelevant to the test.
43+
STUB_FINGERPRINT = b"\x00\x00\x00\x01"
44+
945

1046
def core_fingerprint(seed: bytes) -> bytes:
1147
"""Return a frozen fingerprint that the real-Core regtest verifies."""
@@ -16,5 +52,8 @@ def core_fingerprint(seed: bytes) -> bytes:
1652

1753

1854
def stub_fingerprint(seed: bytes) -> bytes:
19-
"""Return real fixture data when known, otherwise a stable test-double value."""
20-
return CORE_FINGERPRINTS.get(seed, b"\x00\x00\x00\x01")
55+
"""Return real fixture data when known, otherwise a seed-sensitive test double."""
56+
fixture = CORE_FINGERPRINTS.get(seed)
57+
if fixture is not None:
58+
return fixture
59+
return hashlib.sha256(b"codex32 test fingerprint\0" + seed).digest()[:4]

0 commit comments

Comments
 (0)