Skip to content

Commit

Permalink
fix(forks,fw): Fix transition forks on state tests (#406)
Browse files Browse the repository at this point in the history
* fix(forks,fw): Fix transition forks on state tests

* changelog
  • Loading branch information
marioevz authored Jan 28, 2024
1 parent fb4b16e commit c6ebfc5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ Test fixtures for use by clients are available for each release on the [Github r

**Key:** ✨ = New, 🐞 = Fixed, 🔀 = Changed, 💥 = Breaking change.

## [v2.0.1](https://github.com/ethereum/execution-spec-tests/releases/tag/v2.0.1) - 20XX-XX-XX: Unreleased

### 🧪 Test Cases

### 🛠️ Framework

- 🐞 State tests generated with transition forks no longer use the transition fork name in the fixture output, instead they use the actual enabled fork according to the state test's block number and timestamp ([#406](https://github.com/ethereum/execution-spec-tests/pull/406)).

### 📋 Misc

### 💥 Breaking Changes

## [v2.0.0](https://github.com/ethereum/execution-spec-tests/releases/tag/v2.0.0) - 2024-01-25: 🐍🏖️ Cancun

Release [v2.0.0](https://github.com/ethereum/execution-spec-tests/releases/tag/v2.0.0) contains many important framework changes, including introduction of the `StateTest` format, and some additional Cancun and other test coverage.
Expand Down
8 changes: 8 additions & 0 deletions src/ethereum_test_forks/base_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ def name(cls) -> str:
"""
return cls.__name__

@classmethod
def fork_at(cls, block_number: int = 0, timestamp: int = 0) -> Type["BaseFork"]:
"""
Returns the fork at the given block number and timestamp.
Useful only for transition forks, and it's a no-op for normal forks.
"""
return cls

@classmethod
@abstractmethod
def transition_tool_name(cls, block_number: int = 0, timestamp: int = 0) -> str:
Expand Down
7 changes: 7 additions & 0 deletions src/ethereum_test_forks/tests/test_forks.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ def test_transition_forks():
assert ParisToShanghaiAtTime15k.engine_new_payload_version(0, 14_999) == 1
assert ParisToShanghaiAtTime15k.engine_new_payload_version(0, 15_000) == 2

assert BerlinToLondonAt5.fork_at(4, 0) == Berlin
assert BerlinToLondonAt5.fork_at(5, 0) == London
assert ParisToShanghaiAtTime15k.fork_at(0, 14_999) == Paris
assert ParisToShanghaiAtTime15k.fork_at(0, 15_000) == Shanghai
assert ParisToShanghaiAtTime15k.fork_at() == Paris
assert ParisToShanghaiAtTime15k.fork_at(10_000_000, 14_999) == Paris


def test_forks_from(): # noqa: D103
assert forks_from(Paris) == [Paris, LAST_DEPLOYED]
Expand Down
3 changes: 3 additions & 0 deletions src/ethereum_test_forks/transition_base_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def transition_method(

NewTransitionClass.transitions_to = lambda: to_fork # type: ignore
NewTransitionClass.transitions_from = lambda: from_fork # type: ignore
NewTransitionClass.fork_at = lambda block_number=0, timestamp=0: ( # type: ignore
to_fork if block_number >= at_block and timestamp >= at_timestamp else from_fork
)

return NewTransitionClass

Expand Down
3 changes: 3 additions & 0 deletions src/ethereum_test_tools/spec/state/state_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ def generate(
if self.fixture_format in BlockchainTest.fixture_formats():
return self.generate_blockchain_test().generate(t8n, fork, eips)
elif self.fixture_format == FixtureFormats.STATE_TEST:
# We can't generate a state test fixture that names a transition fork,
# so we get the fork at the block number and timestamp of the state test
fork = fork.fork_at(Number(self.env.number), Number(self.env.timestamp))
return self.make_state_test_fixture(t8n, fork, eips)

raise Exception(f"Unknown fixture format: {self.fixture_format}")
Expand Down

0 comments on commit c6ebfc5

Please sign in to comment.