Skip to content

Commit 795a4f9

Browse files
committed
refactor(test): cleanup based on comments on PR #2679
1 parent 679ff43 commit 795a4f9

2 files changed

Lines changed: 32 additions & 46 deletions

File tree

packages/testing/src/execution_testing/cli/pytest_commands/plugins/consume/simulators/simulator_logic/test_via_build.py

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from execution_testing.base_types import Bytes
1717
from execution_testing.fixtures import BlockchainEngineFixture
1818
from execution_testing.fixtures.blockchain import (
19-
FixtureEngineNewPayload,
2019
FixtureExecutionPayload,
2120
FixtureHeader,
2221
)
@@ -29,7 +28,6 @@
2928
)
3029
from execution_testing.rpc.rpc_types import (
3130
ForkchoiceState,
32-
PayloadAttributes,
3331
PayloadStatusEnum,
3432
)
3533
from execution_testing.test_types.block_access_list import BlockAccessList
@@ -42,30 +40,6 @@
4240

4341
logger = get_logger(__name__)
4442

45-
# Execution-dependent fields that must match exactly between the built
46-
# and expected payloads. Excluded:
47-
# - gas_limit: testing_buildBlockV1 doesn't accept it; the client
48-
# picks its own via EIP-1559 (validated separately by range check).
49-
# - block_hash: depends on gas_limit, so it will differ too.
50-
_VALIDATED_FIELDS = (
51-
"state_root",
52-
"receipts_root",
53-
"gas_used",
54-
"logs_bloom",
55-
"base_fee_per_gas",
56-
"blob_gas_used",
57-
"excess_blob_gas",
58-
"block_access_list",
59-
"fee_recipient",
60-
"number",
61-
"timestamp",
62-
"extra_data",
63-
"prev_randao",
64-
"parent_hash",
65-
"transactions",
66-
"withdrawals",
67-
)
68-
6943

7044
def _format_block_access_list_diff(
7145
expected_rlp: bytes | None,
@@ -114,23 +88,6 @@ def _format_block_access_list_diff(
11488
)
11589

11690

117-
def _payload_attributes(
118-
payload: FixtureEngineNewPayload,
119-
) -> PayloadAttributes:
120-
"""Extract PayloadAttributes from a fixture payload."""
121-
execution_payload = payload.params[0]
122-
parent_beacon_block_root = (
123-
payload.params[2] if len(payload.params) >= 3 else None
124-
)
125-
return PayloadAttributes(
126-
timestamp=execution_payload.timestamp,
127-
prev_randao=execution_payload.prev_randao,
128-
suggested_fee_recipient=execution_payload.fee_recipient,
129-
withdrawals=execution_payload.withdrawals,
130-
parent_beacon_block_root=parent_beacon_block_root,
131-
)
132-
133-
13491
def _validate_gas_limit(
13592
built: FixtureExecutionPayload,
13693
parent_gas_limit: int,
@@ -161,7 +118,17 @@ def _validate_built_block(
161118
_validate_gas_limit(built, parent_gas_limit)
162119

163120
mismatches: List[str] = []
164-
for field in _VALIDATED_FIELDS:
121+
122+
# All FixtureExecutionPayload fields are validated except:
123+
# - gas_limit: testing_buildBlockV1 doesn't accept it; the client
124+
# picks its own via EIP-1559 (validated separately by range check).
125+
# - block_hash: depends on gas_limit, so it will differ too.
126+
validated_fields = tuple(
127+
name
128+
for name in FixtureExecutionPayload.model_fields
129+
if name not in {"gas_limit", "block_hash"}
130+
)
131+
for field in validated_fields:
165132
built_val = getattr(built, field)
166133
expected_val = getattr(expected, field)
167134
if built_val != expected_val:
@@ -257,10 +224,9 @@ def test_blockchain_via_build(
257224
with total_build_timing.time(f"Block {i + 1}") as block_timing:
258225
# 1. Build the block
259226
with block_timing.time("testing_buildBlockV1"):
260-
attributes = _payload_attributes(payload)
261227
build_response = testing_rpc.build_block(
262228
parent_block_hash=(expected_payload.parent_hash),
263-
payload_attributes=attributes,
229+
payload_attributes=payload.get_payload_attributes(),
264230
transactions=(expected_payload.transactions),
265231
extra_data=expected_payload.extra_data,
266232
)

packages/testing/src/execution_testing/fixtures/blockchain.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from functools import cached_property
44
from typing import (
5+
TYPE_CHECKING,
56
Annotated,
67
Any,
78
ClassVar,
@@ -69,6 +70,9 @@
6970
FixtureTransactionReceipt,
7071
)
7172

73+
if TYPE_CHECKING:
74+
from execution_testing.rpc.rpc_types import PayloadAttributes
75+
7276

7377
def post_state_validator(
7478
alternate_field: str | None = None, mode: str = "after"
@@ -472,6 +476,22 @@ def valid(self) -> bool:
472476
"""Return whether the payload is valid."""
473477
return self.validation_error is None
474478

479+
def get_payload_attributes(self) -> "PayloadAttributes":
480+
"""Return the ``PayloadAttributes`` corresponding to this payload."""
481+
from execution_testing.rpc.rpc_types import PayloadAttributes
482+
483+
execution_payload = self.params[0]
484+
parent_beacon_block_root = (
485+
self.params[2] if len(self.params) >= 3 else None
486+
)
487+
return PayloadAttributes(
488+
timestamp=execution_payload.timestamp,
489+
prev_randao=execution_payload.prev_randao,
490+
suggested_fee_recipient=execution_payload.fee_recipient,
491+
withdrawals=execution_payload.withdrawals,
492+
parent_beacon_block_root=parent_beacon_block_root,
493+
)
494+
475495
@classmethod
476496
def from_fixture_header(
477497
cls,

0 commit comments

Comments
 (0)