diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 0ede655aab8..039d736d135 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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 diff --git a/src/ethereum_test_tools/spec/blockchain/blockchain_test.py b/src/ethereum_test_tools/spec/blockchain/blockchain_test.py index ddda651e27f..2dbeba67416 100644 --- a/src/ethereum_test_tools/spec/blockchain/blockchain_test.py +++ b/src/ethereum_test_tools/spec/blockchain/blockchain_test.py @@ -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 @@ -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( @@ -412,6 +414,7 @@ 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 @@ -419,6 +422,34 @@ def make_hive_fixture( " 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, @@ -426,6 +457,7 @@ def make_hive_fixture( fcu_version=fcu_version, pre_state=pre, post_state=alloc_to_accounts(alloc), + sync_payload=sync_payload, name=self.tag, ) diff --git a/src/ethereum_test_tools/spec/blockchain/types.py b/src/ethereum_test_tools/spec/blockchain/types.py index 958adad6919..27c4042381d 100644 --- a/src/ethereum_test_tools/spec/blockchain/types.py +++ b/src/ethereum_test_tools/spec/blockchain/types.py @@ -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", diff --git a/whitelist.txt b/whitelist.txt index 05108084a4b..50993c40c80 100644 --- a/whitelist.txt +++ b/whitelist.txt @@ -81,6 +81,7 @@ eip eips EIPs endianness +EngineAPI enum env eof