Skip to content

Commit

Permalink
feat(consume): enable loading of ethereum/tests/BlockchainTests (et…
Browse files Browse the repository at this point in the history
…hereum#596)

Co-authored-by: spencer <[email protected]>
  • Loading branch information
danceratopz and spencer-tb authored Jun 11, 2024
1 parent 2321199 commit 2df7dea
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Test fixtures for use by clients are available for each release on the [Github r
- ✨ Add "description" and "url" fields containing test case documentation and a source code permalink to fixtures during `fill` and use them in `consume`-generated Hive test reports ([#579](https://github.com/ethereum/execution-spec-tests/pull/579)).
- ✨ Add git workflow evmone coverage script for any new lines mentioned in converted_ethereum_tests.txt ([#503](https://github.com/ethereum/execution-spec-tests/pull/503)).
- ✨ Add a new covariant marker `with_all_contract_creating_tx_types` that allows automatic parametrization of a test with all contract-creating transaction types at the current executing fork ([#602](https://github.com/ethereum/execution-spec-tests/pull/602)).
- ✨ Enable loading of [ethereum/tests/BlockchainTests](https://github.com/ethereum/tests/tree/develop/BlockchainTests) ([#596](https://github.com/ethereum/execution-spec-tests/pull/596)).

### 🔧 EVM Tools

Expand Down
17 changes: 17 additions & 0 deletions src/cli/gen_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@

from .hasher import HashableItem

# TODO: remove when these tests are ported or fixed within ethereum/tests.
fixtures_to_skip = set(
[
# These fixtures have invalid fields that we can't load into our pydantic models (bigint).
"BlockchainTests/GeneralStateTests/stTransactionTest/ValueOverflowParis.json",
"BlockchainTests/InvalidBlocks/bc4895-withdrawals/withdrawalsAmountBounds.json",
"BlockchainTests/InvalidBlocks/bc4895-withdrawals/withdrawalsIndexBounds.json",
"BlockchainTests/InvalidBlocks/bc4895-withdrawals/withdrawalsValidatorIndexBounds.json",
"BlockchainTests/InvalidBlocks/bc4895-withdrawals/withdrawalsAddressBounds.json",
]
)


def count_json_files_exclude_index(start_path: Path) -> int:
"""
Expand All @@ -47,6 +59,8 @@ def infer_fixture_format_from_path(file: Path) -> FixtureFormats:
return FixtureFormats.BLOCKCHAIN_TEST_HIVE
if "blockchain_tests" in file.parts:
return FixtureFormats.BLOCKCHAIN_TEST
if "BlockchainTests" in file.parts: # ethereum/tests
return FixtureFormats.BLOCKCHAIN_TEST
if "state_tests" in file.parts:
return FixtureFormats.STATE_TEST
return FixtureFormats.UNSET_TEST_FORMAT
Expand Down Expand Up @@ -167,6 +181,9 @@ def generate_fixtures_index(
continue
if "blockchain_tests_hive" in file.parts:
continue
if any(fixture in str(file) for fixture in fixtures_to_skip):
rich.print(f"Skipping '{file}'")
continue

try:
fixture_format = None
Expand Down
17 changes: 10 additions & 7 deletions src/cli/hasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,16 @@ def from_json_file(cls, *, file_path: Path, parents: List[str]) -> "HashableItem
raise TypeError(f"Expected dict, got {type(item)} for {key}")
if "_info" not in item:
raise KeyError(f"Expected '_info' in {key}")
if "hash" not in item["_info"]:
raise KeyError(f"Expected 'hash' in {key}")
if not isinstance(item["_info"]["hash"], str):
raise TypeError(
f"Expected hash to be a string in {key}, got {type(item['_info']['hash'])}"
)
item_hash_bytes = bytes.fromhex(item["_info"]["hash"][2:])

# EEST uses 'hash'; ethereum/tests use 'generatedTestHash'
hash_value = item["_info"].get("hash") or item["_info"].get("generatedTestHash")
if hash_value is None:
raise KeyError(f"Expected 'hash' or 'generatedTestHash' in {key}")

if not isinstance(hash_value, str):
raise TypeError(f"Expected hash to be a string in {key}, got {type(hash_value)}")

item_hash_bytes = bytes.fromhex(hash_value[2:])
items[key] = cls(
type=HashableItemType.TEST,
root=item_hash_bytes,
Expand Down
14 changes: 12 additions & 2 deletions src/ethereum_test_tools/spec/blockchain/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
"""

from functools import cached_property
from typing import Annotated, Any, ClassVar, Dict, List, Literal, get_args, get_type_hints
from typing import (
Annotated,
Any,
ClassVar,
Dict,
List,
Literal,
Optional,
get_args,
get_type_hints,
)

from ethereum import rlp as eth_rlp
from ethereum.base_types import Uint
Expand Down Expand Up @@ -636,7 +646,7 @@ class FixtureCommon(BaseFixture):
fork: str = Field(..., alias="network")
genesis: FixtureHeader = Field(..., alias="genesisBlockHeader")
pre: Alloc
post_state: Alloc
post_state: Optional[Alloc] = Field(None)

def get_fork(self) -> str:
"""
Expand Down
1 change: 1 addition & 0 deletions whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ basename
bb
besu
bidict
bigint
big0
big1
blobgasfee
Expand Down

0 comments on commit 2df7dea

Please sign in to comment.