Skip to content

Commit 150d8cb

Browse files
committed
src/ethereum_test_tools: move fcuVersion last valid block logic to spec.
1 parent b363ee8 commit 150d8cb

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

src/ethereum_test_tools/filling/fill.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,14 @@ def fill_test(
2626

2727
pre, genesis_rlp, genesis = test_spec.make_genesis(t8n, fork)
2828

29-
(blocks, head, alloc) = test_spec.make_blocks(
29+
(blocks, head, alloc, fcu_version) = test_spec.make_blocks(
3030
t8n,
3131
genesis,
3232
pre,
3333
fork,
3434
eips=eips,
3535
)
3636

37-
fcu_version: int | None = None
38-
if not test_spec.base_test_config.disable_hive:
39-
last_valid_block = next(
40-
(block.block_header for block in reversed(blocks) if block.expected_exception is None),
41-
None,
42-
)
43-
fcu_version = (
44-
fork.engine_forkchoice_updated_version(
45-
last_valid_block.number, last_valid_block.timestamp
46-
)
47-
if last_valid_block
48-
else None
49-
)
50-
5137
fork_name = fork.name()
5238
fixture = Fixture(
5339
blocks=blocks,

src/ethereum_test_tools/spec/base_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def make_blocks(
127127
fork: Fork,
128128
chain_id: int = 1,
129129
eips: Optional[List[int]] = None,
130-
) -> Tuple[List[FixtureBlock], Hash, Dict[str, Any]]:
130+
) -> Tuple[List[FixtureBlock], Hash, Dict[str, Any], Optional[int]]:
131131
"""
132132
Generate the blockchain that must be executed sequentially during test.
133133
"""

src/ethereum_test_tools/spec/blockchain_test.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def make_blocks(
264264
fork: Fork,
265265
chain_id=1,
266266
eips: Optional[List[int]] = None,
267-
) -> Tuple[List[FixtureBlock], Hash, Dict[str, Any]]:
267+
) -> Tuple[List[FixtureBlock], Hash, Dict[str, Any], Optional[int]]:
268268
"""
269269
Create a block list from the blockchain test definition.
270270
Performs checks against the expected behavior of the test.
@@ -273,6 +273,9 @@ def make_blocks(
273273
alloc = to_json(pre)
274274
env = Environment.from_parent_header(genesis)
275275
blocks: List[FixtureBlock] = []
276+
fcu_version: Optional[int] = None
277+
last_valid: Optional[FixtureHeader] = None
278+
276279
head = genesis.hash if genesis.hash is not None else Hash(0)
277280
for block in self.blocks:
278281
fixture_block, env, alloc, head = self.make_block(
@@ -286,14 +289,22 @@ def make_blocks(
286289
eips=eips,
287290
)
288291
blocks.append(fixture_block)
292+
if block.exception is None:
293+
last_valid = fixture_block.block_header
294+
295+
if not self.base_test_config.disable_hive and last_valid is not None:
296+
fcu_version = fork.engine_forkchoice_updated_version(
297+
block_number=last_valid.number,
298+
timestamp=last_valid.timestamp,
299+
)
289300

290301
try:
291302
verify_post_alloc(self.post, alloc)
292303
except Exception as e:
293304
print_traces(t8n.get_traces())
294305
raise e
295306

296-
return (blocks, head, alloc)
307+
return (blocks, head, alloc, fcu_version)
297308

298309

299310
BlockchainTestSpec = Callable[[str], Generator[BlockchainTest, None, None]]

src/ethereum_test_tools/spec/state_test.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def make_blocks(
127127
fork: Fork,
128128
chain_id=1,
129129
eips: Optional[List[int]] = None,
130-
) -> Tuple[List[FixtureBlock], Hash, Dict[str, Any]]:
130+
) -> Tuple[List[FixtureBlock], Hash, Dict[str, Any], Optional[int]]:
131131
"""
132132
Create a block from the state test definition.
133133
Performs checks against the expected behavior of the test.
@@ -178,15 +178,18 @@ def make_blocks(
178178
withdrawals=env.withdrawals,
179179
)
180180

181+
# Hive specific fields
181182
new_payload: FixtureEngineNewPayload | None = None
183+
fcu_version: int | None = None
182184
if not self.base_test_config.disable_hive:
183185
new_payload = FixtureEngineNewPayload.from_fixture_header(
184186
fork=fork,
185187
header=header,
186188
transactions=txs,
187189
withdrawals=env.withdrawals,
188-
error_code=self.engine_api_error_code,
190+
error_code=None,
189191
)
192+
fcu_version = fork.engine_forkchoice_updated_version(header.number, header.timestamp)
190193

191194
return (
192195
[
@@ -201,6 +204,7 @@ def make_blocks(
201204
],
202205
header.hash,
203206
alloc,
207+
fcu_version,
204208
)
205209

206210

0 commit comments

Comments
 (0)