Skip to content

Commit

Permalink
src/tools: Initial refactor using make_fixture and make_fixture_hive.
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-tb committed Sep 27, 2023
1 parent a11b7b1 commit a33ef95
Show file tree
Hide file tree
Showing 13 changed files with 338 additions and 325 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Test fixtures for use by clients are available for each release on the [Github r
### 🔧 Tools

- 🔀 Tools: Updated invalid blocks in fixtures to include non-RLP format ([#322](https://github.com/ethereum/execution-spec-tests/pull/322)).
- 🔀 Spec: Refactor state and blockchain spec ([#307](https://github.com/ethereum/execution-spec-tests/pull/307)).

### 📋 Misc

Expand Down
15 changes: 5 additions & 10 deletions src/ethereum_test_tools/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2576,14 +2576,14 @@ class FixtureEngineNewPayload:
cast_type=Hash,
),
)
version: int = field(
json_encoder=JSONEncoder.Field(),
)
valid: bool = field(
json_encoder=JSONEncoder.Field(
skip_string_convert=True,
),
)
version: int = field(
json_encoder=JSONEncoder.Field(),
)
error_code: Optional[EngineAPIError] = field(
default=None,
json_encoder=JSONEncoder.Field(
Expand Down Expand Up @@ -2731,12 +2731,6 @@ class BaseFixture:
name="network",
),
)
name: str = field(
default="",
json_encoder=JSONEncoder.Field(
skip=True,
),
)
_json: Dict[str, Any] | None = field(
default=None,
json_encoder=JSONEncoder.Field(
Expand Down Expand Up @@ -2795,7 +2789,7 @@ class Fixture(BaseFixture):
to_json=True,
),
)
head: Hash = field(
last_block_hash: Hash = field(
json_encoder=JSONEncoder.Field(
name="lastblockhash",
),
Expand All @@ -2816,6 +2810,7 @@ class Fixture(BaseFixture):
),
)
seal_engine: str = field(
default="NoProof",
json_encoder=JSONEncoder.Field(
name="sealEngine",
),
Expand Down
40 changes: 3 additions & 37 deletions src/ethereum_test_tools/filling/fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ethereum_test_forks import Fork
from evm_transition_tool import TransitionTool

from ..common import Fixture, HiveFixture, alloc_to_accounts
from ..common import Fixture, HiveFixture
from ..reference_spec.reference_spec import ReferenceSpec
from ..spec import BaseTest

Expand All @@ -15,56 +15,22 @@ def fill_test(
t8n: TransitionTool,
test_spec: BaseTest,
fork: Fork,
engine: str,
spec: ReferenceSpec | None,
eips: Optional[List[int]] = None,
) -> Optional[Union[Fixture, HiveFixture]]:
"""
Fills fixtures for the specified fork.
"""
t8n.reset_traces()

pre, genesis_rlp, genesis = test_spec.make_genesis(t8n, fork)

(blocks, payloads, head, alloc, fcu_version) = test_spec.make_blocks(
t8n,
genesis,
pre,
fork,
eips=eips,
)

network_info = (
"+".join([fork.name()] + [str(eip) for eip in eips]) if eips is not None else fork.name()
)

fixture: Union[Fixture, HiveFixture]
if test_spec.base_test_config.enable_hive:
if fork.engine_new_payload_version() is not None:
fixture = HiveFixture(
payloads=payloads,
fcu_version=fcu_version,
genesis=genesis,
fork=network_info,
pre_state=pre,
post_state=alloc_to_accounts(alloc),
name=test_spec.tag,
)
fixture = test_spec.make_hive_fixture(t8n, fork, eips)
else: # pre Merge tests are not supported in Hive
# TODO: remove this logic. if hive enabled set --from to Merge
return None
else:
fixture = Fixture(
blocks=blocks,
genesis=genesis,
genesis_rlp=genesis_rlp,
head=head,
fork=network_info,
pre_state=pre,
post_state=alloc_to_accounts(alloc),
seal_engine=engine,
name=test_spec.tag,
)
fixture = test_spec.make_fixture(t8n, fork, eips)
fixture.fill_info(t8n, spec)

return fixture
31 changes: 9 additions & 22 deletions src/ethereum_test_tools/spec/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,17 @@
from dataclasses import dataclass, field
from itertools import count
from os import path
from typing import Any, Callable, Dict, Generator, Iterator, List, Mapping, Optional, Tuple
from typing import Any, Callable, Dict, Generator, Iterator, List, Mapping, Optional

from ethereum_test_forks import Fork
from evm_transition_tool import TransitionTool

from ..common import (
Account,
Address,
Alloc,
Bytes,
Environment,
FixtureBlock,
FixtureEngineNewPayload,
FixtureHeader,
Hash,
InvalidFixtureBlock,
Fixture,
HiveFixture,
Transaction,
withdrawals_root,
)
Expand Down Expand Up @@ -110,32 +105,24 @@ class BaseTest:
t8n_call_counter: Iterator[int] = field(init=False, default_factory=count)

@abstractmethod
def make_genesis(
def make_fixture(
self,
t8n: TransitionTool,
fork: Fork,
) -> Tuple[Alloc, Bytes, FixtureHeader]:
eips: Optional[List[int]] = None,
) -> Fixture:
"""
Create a genesis block from the test definition.
Generate blockchain that must be executed sequentially during test.
"""
pass

@abstractmethod
def make_blocks(
def make_hive_fixture(
self,
t8n: TransitionTool,
genesis: FixtureHeader,
pre: Alloc,
fork: Fork,
chain_id: int = 1,
eips: Optional[List[int]] = None,
) -> Tuple[
Optional[List[FixtureBlock | InvalidFixtureBlock]],
Optional[List[Optional[FixtureEngineNewPayload]]],
Hash,
Dict[str, Any],
Optional[int],
]:
) -> HiveFixture:
"""
Generate the blockchain that must be executed sequentially during test.
"""
Expand Down
Loading

0 comments on commit a33ef95

Please sign in to comment.