Skip to content

Commit 2d7548a

Browse files
tcoratgerclaude
andauthored
refactor(testing): replace the stringly-typed signature tamper with a typed union (leanEthereum#859)
The signed-block tamper hook was a dict of magic operation strings dispatched through a 130-line if ladder, while the proof fixtures already model tampers as a typed union matched with structural patterns. Migrate the laggard to the same pattern: - one Pydantic model per mutation, each documenting the rejection path it exercises, - a closed union replacing the raw dict, so a misspelled operation or missing argument fails at construction instead of at fill time, - structural pattern matching replacing the if ladder. Fixture JSON is unchanged: the tamper field is excluded from output. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 863dd1e commit 2d7548a

6 files changed

Lines changed: 247 additions & 170 deletions

File tree

packages/testing/src/consensus_testing/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,24 @@
66
from consensus_testing.genesis import build_anchor, generate_pre_state
77
from consensus_testing.test_fixtures import (
88
ApiEndpointTest,
9+
AppendPhantomAttestation,
910
BaseConsensusFixture,
11+
ClearFirstAttestationBits,
12+
CorruptProof,
1013
DropMessageBinding,
1114
ForkChoiceTest,
1215
GossipsubHandlerTest,
1316
IncrementEmittedSlot,
1417
JustifiabilityTest,
18+
MutateStateRoot,
1519
NetworkingCodecTest,
1620
PoseidonPermutationTest,
1721
RebindToAlternateHeadRoot,
22+
SetProposerIndex,
1823
SlotClockTest,
1924
SSZTest,
2025
StateTransitionTest,
26+
SwapFirstTwoAttestations,
2127
SwapMessageBindings,
2228
SwapParticipantPublicKey,
2329
SyncTest,
@@ -76,6 +82,12 @@
7682
"SwapMessageBindings",
7783
"DropMessageBinding",
7884
"VerifySignaturesTest",
85+
"SetProposerIndex",
86+
"ClearFirstAttestationBits",
87+
"CorruptProof",
88+
"AppendPhantomAttestation",
89+
"MutateStateRoot",
90+
"SwapFirstTwoAttestations",
7991
"SSZTest",
8092
"NetworkingCodecTest",
8193
"GossipsubHandlerTest",

packages/testing/src/consensus_testing/test_fixtures/__init__.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@
2020
VerifyMultiMessageProofsTest,
2121
VerifySingleMessageProofsTest,
2222
)
23-
from consensus_testing.test_fixtures.verify_signatures import VerifySignaturesTest
23+
from consensus_testing.test_fixtures.verify_signatures import (
24+
AppendPhantomAttestation,
25+
ClearFirstAttestationBits,
26+
CorruptProof,
27+
MutateStateRoot,
28+
SetProposerIndex,
29+
SwapFirstTwoAttestations,
30+
VerifySignaturesTest,
31+
)
2432

2533
__all__ = [
2634
"BaseConsensusFixture",
@@ -34,6 +42,12 @@
3442
"SwapMessageBindings",
3543
"DropMessageBinding",
3644
"VerifySignaturesTest",
45+
"SetProposerIndex",
46+
"ClearFirstAttestationBits",
47+
"CorruptProof",
48+
"AppendPhantomAttestation",
49+
"MutateStateRoot",
50+
"SwapFirstTwoAttestations",
3751
"SSZTest",
3852
"NetworkingCodecTest",
3953
"GossipsubHandlerTest",

0 commit comments

Comments
 (0)