From c6ebfc5035ed77b6799aafda0008f67c72f15078 Mon Sep 17 00:00:00 2001 From: Mario Vega Date: Sun, 28 Jan 2024 08:44:05 -0600 Subject: [PATCH] fix(forks,fw): Fix transition forks on state tests (#406) * fix(forks,fw): Fix transition forks on state tests * changelog --- docs/CHANGELOG.md | 12 ++++++++++++ src/ethereum_test_forks/base_fork.py | 8 ++++++++ src/ethereum_test_forks/tests/test_forks.py | 7 +++++++ src/ethereum_test_forks/transition_base_fork.py | 3 +++ src/ethereum_test_tools/spec/state/state_test.py | 3 +++ 5 files changed, 33 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index c4970827ed..1e4fa4e837 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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. diff --git a/src/ethereum_test_forks/base_fork.py b/src/ethereum_test_forks/base_fork.py index 45b918ad83..b663b9dcee 100644 --- a/src/ethereum_test_forks/base_fork.py +++ b/src/ethereum_test_forks/base_fork.py @@ -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: diff --git a/src/ethereum_test_forks/tests/test_forks.py b/src/ethereum_test_forks/tests/test_forks.py index 31638264e4..c9478381b2 100644 --- a/src/ethereum_test_forks/tests/test_forks.py +++ b/src/ethereum_test_forks/tests/test_forks.py @@ -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] diff --git a/src/ethereum_test_forks/transition_base_fork.py b/src/ethereum_test_forks/transition_base_fork.py index eb16454069..bd7af793ab 100644 --- a/src/ethereum_test_forks/transition_base_fork.py +++ b/src/ethereum_test_forks/transition_base_fork.py @@ -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 diff --git a/src/ethereum_test_tools/spec/state/state_test.py b/src/ethereum_test_tools/spec/state/state_test.py index 4308bdf686..f08814fff5 100644 --- a/src/ethereum_test_tools/spec/state/state_test.py +++ b/src/ethereum_test_tools/spec/state/state_test.py @@ -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}")