Skip to content

Commit 7d9ca7a

Browse files
tcoratgerclaude
andauthored
refactor(testing): dispatch max-slot derivation with a match (#1161)
The key-slot scan filtered steps by isinstance and re-tested the type in a ternary. A local match tests each step type once and makes the two attestation cases explicit. Same slots, vectors byte-identical. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 976743f commit 7d9ca7a

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,19 @@ def _resolved_max_slot(self) -> Slot:
9494
return self.max_slot
9595

9696
# XMSS signatures are slot-dependent, so keys must exist up to the highest signed slot.
97-
slots_needing_keys = (
98-
step.block.slot if isinstance(step, BlockStep) else step.attestation.slot
99-
for step in self.steps
100-
if isinstance(step, (BlockStep, AttestationStep, GossipAggregatedAttestationStep))
97+
def slot_needing_keys(step: ForkChoiceStep) -> Slot | None:
98+
match step:
99+
case BlockStep():
100+
return step.block.slot
101+
case AttestationStep() | GossipAggregatedAttestationStep():
102+
return step.attestation.slot
103+
case _:
104+
return None
105+
106+
return max(
107+
(slot for step in self.steps if (slot := slot_needing_keys(step)) is not None),
108+
default=Slot(0),
101109
)
102-
return max(slots_needing_keys, default=Slot(0))
103110

104111
def generate(self) -> ForkChoiceFixture:
105112
"""

0 commit comments

Comments
 (0)