Skip to content

Commit 2937bcf

Browse files
authored
test framework: small touchups (#236)
* test framework: small touchups * more space in doc
1 parent e2781a1 commit 2937bcf

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@ class StateTransitionTest(BaseConsensusFixture):
6161
"""
6262
The filled Blocks, processed through the specs.
6363
64-
This is a private attribute not part of the model schema. Tests cannot set
65-
this. The framework populates it during make_fixture().
64+
This is a private attribute not part of the model schema.
65+
66+
Tests cannot set this.
67+
68+
The framework populates it during make_fixture().
6669
"""
6770

6871
post: StateExpectation | None = None
@@ -215,11 +218,11 @@ def _build_block_from_spec(self, spec: BlockSpec, state: State) -> tuple[Block,
215218
if not spec.skip_slot_processing:
216219
temp_state = state.process_slots(spec.slot)
217220

218-
# Use provided parent_root or compute it
221+
# Use provided parent root or compute it
219222
if spec.parent_root is not None:
220223
parent_root = spec.parent_root
221224
else:
222-
source_state = temp_state if temp_state is not None else state
225+
source_state = temp_state or state
223226
parent_root = hash_tree_root(source_state.latest_block_header)
224227

225228
# Extract attestations from body if provided
@@ -238,16 +241,15 @@ def _build_block_from_spec(self, spec: BlockSpec, state: State) -> tuple[Block,
238241
)
239242
return block, None
240243

241-
temp_block = Block(
242-
slot=spec.slot,
243-
proposer_index=proposer_index,
244-
parent_root=parent_root,
245-
state_root=Bytes32.zero(),
246-
body=spec.body or BlockBody(attestations=aggregated_attestations),
247-
)
248-
244+
# For invalid tests, return incomplete block without processing
249245
if self.expect_exception is not None or spec.skip_slot_processing:
250-
return temp_block, None
246+
return Block(
247+
slot=spec.slot,
248+
proposer_index=proposer_index,
249+
parent_root=parent_root,
250+
state_root=Bytes32.zero(),
251+
body=spec.body or BlockBody(attestations=aggregated_attestations),
252+
), None
251253

252254
# Convert aggregated attestations to plain attestations to build block
253255
plain_attestations = [

packages/testing/src/consensus_testing/test_types/block_spec.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ class BlockSpec(CamelModel):
113113

114114
skip_slot_processing: bool = False
115115
"""
116-
If True, the state transition fixture skips automatic slot advancement before
117-
processing this block. Useful for tests that intentionally exercise slot
118-
mismatch failures.
116+
If True, the state transition fixture skips automatic slot advancement
117+
before processing this block.
118+
119+
Useful for tests that intentionally exercise slot mismatch failures.
119120
"""

0 commit comments

Comments
 (0)