Skip to content

Commit c8e0caa

Browse files
marioevzspencer-tb
andauthored
feat(fw): add optional verify_sync flag to hive blockchain tests (#431)
* feat(fw): add optional `verify_sync` flag to hive blockchain tests * fix: Don't convert flag to a string * fix: Add a sync payload instead * chore: add changelog. * chore: fix spelling in changelog :P --------- Co-authored-by: spencer-tb <[email protected]>
1 parent 06ed07f commit c8e0caa

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Test fixtures for use by clients are available for each release on the [Github r
2222
- 🔀 Locally calculate state root for the genesis blocks in the blockchain tests instead of calling t8n ([#450](https://github.com/ethereum/execution-spec-tests/pull/450)).
2323
- 🐞 Fix bug that causes an exception during test collection because the fork parameter contains `None` ([#452](https://github.com/ethereum/execution-spec-tests/pull/452)).
2424
- ✨ The `_info` field in the test fixtures now contains a `hash` field, which is the hash of the test fixture, and a `hasher` script has been added which prints and performs calculations on top of the hashes of all fixtures (see `hasher -h`) ([#454](https://github.com/ethereum/execution-spec-tests/pull/454)).
25+
- ✨ Adds an optional `verify_sync` field to hive blockchain tests (EngineAPI). When set to true a second client attempts to sync to the first client that executed the tests.([#431](https://github.com/ethereum/execution-spec-tests/pull/431)).
2526

2627
### 🔧 EVM Tools
2728

src/ethereum_test_tools/spec/blockchain/blockchain_test.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class BlockchainTest(BaseTest):
101101
post: Mapping
102102
blocks: List[Block]
103103
genesis_environment: Environment = field(default_factory=Environment)
104+
verify_sync: Optional[bool] = None
104105
tag: str = ""
105106
chain_id: int = 1
106107

@@ -393,6 +394,7 @@ def make_hive_fixture(
393394
pre, _, genesis = self.make_genesis(t8n, fork)
394395
alloc = to_json(pre)
395396
env = environment_from_parent_header(genesis)
397+
head_hash = genesis.hash
396398

397399
for block in self.blocks:
398400
header, _, txs, new_alloc, new_env = self.generate_block_data(
@@ -412,20 +414,50 @@ def make_hive_fixture(
412414
if block.exception is None:
413415
alloc = new_alloc
414416
env = apply_new_parent(env, header)
417+
head_hash = header.hash
415418
fcu_version = fork.engine_forkchoice_updated_version(header.number, header.timestamp)
416419
assert (
417420
fcu_version is not None
418421
), "A hive fixture was requested but no forkchoice update is defined. The framework should"
419422
" never try to execute this test case."
420423

421424
self.verify_post_state(t8n, alloc)
425+
426+
sync_payload: Optional[FixtureEngineNewPayload] = None
427+
if self.verify_sync:
428+
# Test is marked for syncing verification.
429+
assert (
430+
genesis.hash != head_hash
431+
), "Invalid payload tests negative test via sync is not supported yet."
432+
433+
# Most clients require the header to start the sync process, so we create an empty
434+
# block on top of the last block of the test to send it as new payload and trigger the
435+
# sync process.
436+
sync_header, _, _, _, _ = self.generate_block_data(
437+
t8n=t8n,
438+
fork=fork,
439+
block=Block(),
440+
previous_env=env,
441+
previous_alloc=alloc,
442+
eips=eips,
443+
)
444+
sync_payload = FixtureEngineNewPayload.from_fixture_header(
445+
fork=fork,
446+
header=sync_header,
447+
transactions=[],
448+
withdrawals=[],
449+
validation_error=None,
450+
error_code=None,
451+
)
452+
422453
return HiveFixture(
423454
fork=self.network_info(fork, eips),
424455
genesis=genesis,
425456
payloads=fixture_payloads,
426457
fcu_version=fcu_version,
427458
pre_state=pre,
428459
post_state=alloc_to_accounts(alloc),
460+
sync_payload=sync_payload,
429461
name=self.tag,
430462
)
431463

src/ethereum_test_tools/spec/blockchain/types.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,13 @@ class HiveFixture(FixtureCommon):
11221122
name="engineFcuVersion",
11231123
),
11241124
)
1125+
sync_payload: Optional[FixtureEngineNewPayload] = field(
1126+
default=None,
1127+
json_encoder=JSONEncoder.Field(
1128+
name="syncPayload",
1129+
to_json=True,
1130+
),
1131+
)
11251132
pre_state: Mapping[str, Account] = field(
11261133
json_encoder=JSONEncoder.Field(
11271134
name="pre",

whitelist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ eip
8181
eips
8282
EIPs
8383
endianness
84+
EngineAPI
8485
enum
8586
env
8687
eof

0 commit comments

Comments
 (0)