From 1376f8c5c44ff52c201c779f111ecf14294597f2 Mon Sep 17 00:00:00 2001 From: spencer Date: Thu, 8 Aug 2024 19:59:35 +0100 Subject: [PATCH] bug(consume): genesis block hash exception (#734) * fix(consume): genesis block hash exception bug & extra. * docs: update changelog. * chore: tox fix. --- docs/CHANGELOG.md | 1 + .../hive_simulators/engine/test_via_engine.py | 4 +-- .../consume/hive_simulators/exceptions.py | 26 ++++++++++++++----- .../hive_simulators/rlp/test_via_rlp.py | 4 +-- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4cded5de75..da50775a7c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -16,6 +16,7 @@ Test fixtures for use by clients are available for each release on the [Github r - ✨ A metadata folder `.meta/` now stores all fixture metadata files by default ([#721](https://github.com/ethereum/execution-spec-tests/pull/721)). - 🐞 Fixed `fill` command index generation issue due to concurrency ([#725](https://github.com/ethereum/execution-spec-tests/pull/725)). - 🐞 Fixed fixture index generation on EOF tests ([#728](https://github.com/ethereum/execution-spec-tests/pull/728)). +- 🐞 Fixes consume genesis mismatch exception for hive based simulators ([#734](https://github.com/ethereum/execution-spec-tests/pull/734)). ### 🔧 EVM Tools diff --git a/src/pytest_plugins/consume/hive_simulators/engine/test_via_engine.py b/src/pytest_plugins/consume/hive_simulators/engine/test_via_engine.py index c7a271329c..287907309e 100644 --- a/src/pytest_plugins/consume/hive_simulators/engine/test_via_engine.py +++ b/src/pytest_plugins/consume/hive_simulators/engine/test_via_engine.py @@ -4,8 +4,8 @@ Each `engine_newPayloadVX` is verified against the appropriate VALID/INVALID responses. """ + from ethereum_test_fixtures import BlockchainEngineFixture, FixtureFormats -from ethereum_test_fixtures.blockchain import FixtureHeader from ethereum_test_tools.rpc import EngineRPC, EthRPC from ethereum_test_tools.rpc.types import ForkchoiceState, PayloadStatusEnum from pytest_plugins.consume.hive_simulators.exceptions import GenesisBlockMismatchException @@ -45,7 +45,7 @@ def test_via_engine( if genesis_block["hash"] != str(blockchain_fixture.genesis.block_hash): raise GenesisBlockMismatchException( expected_header=blockchain_fixture.genesis, - got_header=FixtureHeader(**genesis_block), + got_genesis_block=genesis_block, ) with timing_data.time("Payloads execution") as total_payload_timing: diff --git a/src/pytest_plugins/consume/hive_simulators/exceptions.py b/src/pytest_plugins/consume/hive_simulators/exceptions.py index e0b4765a3a..bf949d333d 100644 --- a/src/pytest_plugins/consume/hive_simulators/exceptions.py +++ b/src/pytest_plugins/consume/hive_simulators/exceptions.py @@ -3,6 +3,7 @@ """ import pprint +from typing import Dict, List, Tuple from ethereum_test_fixtures.blockchain import FixtureHeader @@ -12,18 +13,26 @@ class GenesisBlockMismatchException(Exception): Definers a mismatch exception between the client and fixture genesis blockhash. """ - def __init__(self, *, expected_header: FixtureHeader, got_header: FixtureHeader): + def __init__(self, *, expected_header: FixtureHeader, got_genesis_block: Dict[str, str]): message = ( "Genesis block hash mismatch.\n\n" f"Expected: {expected_header.block_hash}\n" - f" Got: {got_header.block_hash}." + f" Got: {got_genesis_block['hash']}." + ) + differences, unexpected_fields = self.compare_models( + expected_header, FixtureHeader(**got_genesis_block) ) - differences = self.compare_models(expected_header, got_header) if differences: message += ( "\n\nGenesis block header field differences:\n" f"{pprint.pformat(differences, indent=4)}" ) + elif unexpected_fields: + message += ( + "\n\nUn-expected genesis block header fields from client:\n" + f"{pprint.pformat(unexpected_fields, indent=4)}" + "\nIs the fork configuration correct?" + ) else: message += ( "There were no differences in the expected and received genesis block headers." @@ -31,17 +40,20 @@ def __init__(self, *, expected_header: FixtureHeader, got_header: FixtureHeader) super().__init__(message) @staticmethod - def compare_models(expected: FixtureHeader, got: FixtureHeader) -> dict: + def compare_models(expected: FixtureHeader, got: FixtureHeader) -> Tuple[Dict, List]: """ Compare two FixtureHeader model instances and return their differences. """ differences = {} - for (exp_name, exp_value), (_, got_value) in zip(expected, got): + unexpected_fields = [] + for (exp_name, exp_value), (got_name, got_value) in zip(expected, got): if "rlp" in exp_name or "fork" in exp_name: # ignore rlp as not verbose enough continue - if exp_value is None or got_value is None or exp_value != got_value: + if exp_value != got_value: differences[exp_name] = { "expected ": str(exp_value), "got (via rpc)": str(got_value), } - return differences + if got_value is None: + unexpected_fields.append(got_name) + return differences, unexpected_fields diff --git a/src/pytest_plugins/consume/hive_simulators/rlp/test_via_rlp.py b/src/pytest_plugins/consume/hive_simulators/rlp/test_via_rlp.py index 94959871e9..42155400d9 100644 --- a/src/pytest_plugins/consume/hive_simulators/rlp/test_via_rlp.py +++ b/src/pytest_plugins/consume/hive_simulators/rlp/test_via_rlp.py @@ -4,8 +4,8 @@ Clients consume the genesis and RLP-encoded blocks from input files upon start-up. """ + from ethereum_test_fixtures import BlockchainFixture, FixtureFormats -from ethereum_test_fixtures.blockchain import FixtureHeader from ethereum_test_tools.rpc import EthRPC from pytest_plugins.consume.hive_simulators.exceptions import GenesisBlockMismatchException @@ -28,7 +28,7 @@ def test_via_rlp( if genesis_block["hash"] != str(blockchain_fixture.genesis.block_hash): raise GenesisBlockMismatchException( expected_header=blockchain_fixture.genesis, - got_header=FixtureHeader(**genesis_block), + got_genesis_block=genesis_block, ) with timing_data.time("Get latest block"): block = eth_rpc.get_block_by_number("latest")