Skip to content

Commit fc25f0c

Browse files
chore(fill): fix transition fork state test node ids (#1313)
* chore(fill): fix transition fork state test node ids. * chore(docs): update changelog. * Update src/ethereum_test_forks/helpers.py Co-authored-by: danceratopz <[email protected]> * Update src/ethereum_test_forks/helpers.py Co-authored-by: danceratopz <[email protected]> * chore(fill): add review comments. --------- Co-authored-by: danceratopz <[email protected]>
1 parent 0bceb2d commit fc25f0c

File tree

5 files changed

+43
-8
lines changed

5 files changed

+43
-8
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Test fixtures for use by clients are available for each release on the [Github r
2121
#### `fill`
2222

2323
- 🐞 Fix `--fork/from/until` for transition forks when using `fill` [#1311](https://github.com/ethereum/execution-spec-tests/pull/1311).
24+
- 🐞 Fix the node id for state tests marked by transition forks ([#1313](https://github.com/ethereum/execution-spec-tests/pull/1313)).
2425

2526
### 📋 Misc
2627

src/ethereum_test_forks/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
get_from_until_fork_set,
4242
get_last_descendants,
4343
get_relative_fork_markers,
44+
get_transition_fork_predecessor,
45+
get_transition_fork_successor,
4446
get_transition_forks,
4547
transition_fork_from_to,
4648
transition_fork_to,
@@ -76,6 +78,8 @@
7678
"get_closest_fork_with_solc_support",
7779
"get_deployed_forks",
7880
"get_development_forks",
81+
"get_transition_fork_predecessor",
82+
"get_transition_fork_successor",
7983
"get_forks_with_no_descendants",
8084
"get_forks_with_no_parents",
8185
"get_forks_with_solc_support",

src/ethereum_test_forks/helpers.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111

1212
class InvalidForkError(Exception):
13-
"""
14-
Invalid fork error raised when the fork specified by command-line option
15-
--latest-fork is not found.
16-
"""
13+
"""Invalid fork error raised when the fork specified is not found or incompatible."""
1714

1815
def __init__(self, message):
1916
"""Initialize the InvalidForkError exception."""
@@ -56,7 +53,7 @@ def get_parent_fork(fork: Fork) -> Fork:
5653
"""Return parent fork of the specified fork."""
5754
parent_fork = fork.__base__
5855
if not parent_fork:
59-
raise Exception(f"Parent fork of {fork} not found.")
56+
raise InvalidForkError(f"Parent fork of {fork} not found.")
6057
return parent_fork
6158

6259

@@ -98,6 +95,20 @@ def get_transition_forks() -> Set[Fork]:
9895
return transition_forks
9996

10097

98+
def get_transition_fork_predecessor(transition_fork: Fork) -> Fork:
99+
"""Return the fork from which the transition fork transitions."""
100+
if not issubclass(transition_fork, TransitionBaseClass):
101+
raise InvalidForkError(f"{transition_fork} is not a transition fork.")
102+
return transition_fork.transitions_from()
103+
104+
105+
def get_transition_fork_successor(transition_fork: Fork) -> Fork:
106+
"""Return the fork to which the transition fork transitions."""
107+
if not issubclass(transition_fork, TransitionBaseClass):
108+
raise InvalidForkError(f"{transition_fork} is not a transition fork.")
109+
return transition_fork.transitions_to()
110+
111+
101112
def get_from_until_fork_set(
102113
forks: Set[Fork], forks_from: Set[Fork], forks_until: Set[Fork]
103114
) -> Set[Fork]:
@@ -225,7 +236,7 @@ def get_relative_fork_markers(fork_identifier: Fork | str) -> list[str]:
225236
fork_class = candidate
226237
break
227238
if fork_class is None:
228-
raise Exception(f"Unknown fork: {fork_identifier}")
239+
raise InvalidForkError(f"Unknown fork: {fork_identifier}")
229240
else:
230241
fork_class = fork_identifier
231242

src/ethereum_test_forks/transition_base_fork.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class NewTransitionClass(
4949
def transitions_to(cls) -> Fork:
5050
return to_fork
5151

52+
@classmethod
53+
def transitions_from(cls) -> Fork:
54+
return from_fork
55+
5256
NewTransitionClass.name = lambda: transition_name # type: ignore
5357

5458
def make_transition_method(

src/pytest_plugins/filler/filler.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from ethereum_clis.clis.geth import FixtureConsumerTool
2626
from ethereum_test_base_types import Alloc, ReferenceSpec
2727
from ethereum_test_fixtures import BaseFixture, FixtureCollector, FixtureConsumer, TestInfo
28-
from ethereum_test_forks import Fork
28+
from ethereum_test_forks import Fork, get_transition_fork_predecessor, get_transition_forks
2929
from ethereum_test_specs import SPEC_TYPES, BaseTest
3030
from ethereum_test_tools.utility.versioning import (
3131
generate_github_url,
@@ -753,7 +753,9 @@ def pytest_collection_modifyitems(config: pytest.Config, items: List[pytest.Item
753753
Remove pre-Paris tests parametrized to generate hive type fixtures; these
754754
can't be used in the Hive Pyspec Simulator.
755755
756-
This can't be handled in this plugins pytest_generate_tests() as the fork
756+
Replaces the test ID for state tests that use a transition fork with the base fork.
757+
758+
These can't be handled in this plugins pytest_generate_tests() as the fork
757759
parametrization occurs in the forks plugin.
758760
"""
759761
for item in items[:]: # use a copy of the list, as we'll be modifying it
@@ -780,6 +782,19 @@ def pytest_collection_modifyitems(config: pytest.Config, items: List[pytest.Item
780782
if "yul" in item.fixturenames: # type: ignore
781783
item.add_marker(pytest.mark.yul_test)
782784

785+
# Update test ID for state tests that use a transition fork
786+
if fork in get_transition_forks():
787+
has_state_test = any(marker.name == "state_test" for marker in markers)
788+
has_valid_transition = any(
789+
marker.name == "valid_at_transition_to" for marker in markers
790+
)
791+
if has_state_test and has_valid_transition:
792+
base_fork = get_transition_fork_predecessor(fork)
793+
item._nodeid = item._nodeid.replace(
794+
f"fork_{fork.name()}",
795+
f"fork_{base_fork.name()}",
796+
)
797+
783798

784799
def pytest_sessionfinish(session: pytest.Session, exitstatus: int):
785800
"""

0 commit comments

Comments
 (0)