diff --git a/packages/testing/src/consensus_testing/test_fixtures/state_transition.py b/packages/testing/src/consensus_testing/test_fixtures/state_transition.py index 3bec4630..ad6bca27 100644 --- a/packages/testing/src/consensus_testing/test_fixtures/state_transition.py +++ b/packages/testing/src/consensus_testing/test_fixtures/state_transition.py @@ -61,8 +61,11 @@ class StateTransitionTest(BaseConsensusFixture): """ The filled Blocks, processed through the specs. - This is a private attribute not part of the model schema. Tests cannot set - this. The framework populates it during make_fixture(). + This is a private attribute not part of the model schema. + + Tests cannot set this. + + The framework populates it during make_fixture(). """ post: StateExpectation | None = None @@ -215,11 +218,11 @@ def _build_block_from_spec(self, spec: BlockSpec, state: State) -> tuple[Block, if not spec.skip_slot_processing: temp_state = state.process_slots(spec.slot) - # Use provided parent_root or compute it + # Use provided parent root or compute it if spec.parent_root is not None: parent_root = spec.parent_root else: - source_state = temp_state if temp_state is not None else state + source_state = temp_state or state parent_root = hash_tree_root(source_state.latest_block_header) # Extract attestations from body if provided @@ -238,16 +241,15 @@ def _build_block_from_spec(self, spec: BlockSpec, state: State) -> tuple[Block, ) return block, None - temp_block = Block( - slot=spec.slot, - proposer_index=proposer_index, - parent_root=parent_root, - state_root=Bytes32.zero(), - body=spec.body or BlockBody(attestations=aggregated_attestations), - ) - + # For invalid tests, return incomplete block without processing if self.expect_exception is not None or spec.skip_slot_processing: - return temp_block, None + return Block( + slot=spec.slot, + proposer_index=proposer_index, + parent_root=parent_root, + state_root=Bytes32.zero(), + body=spec.body or BlockBody(attestations=aggregated_attestations), + ), None # Convert aggregated attestations to plain attestations to build block plain_attestations = [ diff --git a/packages/testing/src/consensus_testing/test_types/block_spec.py b/packages/testing/src/consensus_testing/test_types/block_spec.py index d372c91d..3efbab79 100644 --- a/packages/testing/src/consensus_testing/test_types/block_spec.py +++ b/packages/testing/src/consensus_testing/test_types/block_spec.py @@ -113,7 +113,8 @@ class BlockSpec(CamelModel): skip_slot_processing: bool = False """ - If True, the state transition fixture skips automatic slot advancement before - processing this block. Useful for tests that intentionally exercise slot - mismatch failures. + If True, the state transition fixture skips automatic slot advancement + before processing this block. + + Useful for tests that intentionally exercise slot mismatch failures. """