Skip to content

Commit

Permalink
feat(fw): add optional verify_sync flag to hive blockchain tests (#431
Browse files Browse the repository at this point in the history
)

* 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 <spencer@spencertaylorbrown.uk>
  • Loading branch information
marioevz and spencer-tb authored Mar 9, 2024
1 parent 06ed07f commit c8e0caa
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Test fixtures for use by clients are available for each release on the [Github r
- 🔀 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)).
- 🐞 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)).
- ✨ 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)).
- ✨ 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)).

### 🔧 EVM Tools

Expand Down
32 changes: 32 additions & 0 deletions src/ethereum_test_tools/spec/blockchain/blockchain_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class BlockchainTest(BaseTest):
post: Mapping
blocks: List[Block]
genesis_environment: Environment = field(default_factory=Environment)
verify_sync: Optional[bool] = None
tag: str = ""
chain_id: int = 1

Expand Down Expand Up @@ -393,6 +394,7 @@ def make_hive_fixture(
pre, _, genesis = self.make_genesis(t8n, fork)
alloc = to_json(pre)
env = environment_from_parent_header(genesis)
head_hash = genesis.hash

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

self.verify_post_state(t8n, alloc)

sync_payload: Optional[FixtureEngineNewPayload] = None
if self.verify_sync:
# Test is marked for syncing verification.
assert (
genesis.hash != head_hash
), "Invalid payload tests negative test via sync is not supported yet."

# Most clients require the header to start the sync process, so we create an empty
# block on top of the last block of the test to send it as new payload and trigger the
# sync process.
sync_header, _, _, _, _ = self.generate_block_data(
t8n=t8n,
fork=fork,
block=Block(),
previous_env=env,
previous_alloc=alloc,
eips=eips,
)
sync_payload = FixtureEngineNewPayload.from_fixture_header(
fork=fork,
header=sync_header,
transactions=[],
withdrawals=[],
validation_error=None,
error_code=None,
)

return HiveFixture(
fork=self.network_info(fork, eips),
genesis=genesis,
payloads=fixture_payloads,
fcu_version=fcu_version,
pre_state=pre,
post_state=alloc_to_accounts(alloc),
sync_payload=sync_payload,
name=self.tag,
)

Expand Down
7 changes: 7 additions & 0 deletions src/ethereum_test_tools/spec/blockchain/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,13 @@ class HiveFixture(FixtureCommon):
name="engineFcuVersion",
),
)
sync_payload: Optional[FixtureEngineNewPayload] = field(
default=None,
json_encoder=JSONEncoder.Field(
name="syncPayload",
to_json=True,
),
)
pre_state: Mapping[str, Account] = field(
json_encoder=JSONEncoder.Field(
name="pre",
Expand Down
1 change: 1 addition & 0 deletions whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ eip
eips
EIPs
endianness
EngineAPI
enum
env
eof
Expand Down

0 comments on commit c8e0caa

Please sign in to comment.