Skip to content

Commit d2ff08b

Browse files
fix(consume): allow consumption of fixtures with unknown forks (#1318)
Co-authored-by: spencer <[email protected]>
1 parent 35ea11c commit d2ff08b

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

docs/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ Test fixtures for use by clients are available for each release on the [Github r
1313
#### `consume`
1414

1515
- ✨ Add support for Nethermind's `nethtest` command to `consume direct` ([#1250](https://github.com/ethereum/execution-spec-tests/pull/1250)).
16-
- ✨ Allow filtering of test cases by fork via pytest marks (e.g., `-m "Cancun or Prague"`) ([#1304](https://github.com/ethereum/execution-spec-tests/pull/1304)).
16+
- ✨ Allow filtering of test cases by fork via pytest marks (e.g., `-m "Cancun or Prague"`) ([#1304](https://github.com/ethereum/execution-spec-tests/pull/1304), [#1318](https://github.com/ethereum/execution-spec-tests/pull/1318)).
1717
- ✨ Allow filtering of test cases by fixture format via pytest marks (e.g., `-m blockchain_test`) ([#1314](https://github.com/ethereum/execution-spec-tests/pull/1314)).
18+
- ✨ Add top-level entries `forks` and `fixture_formats` to the index file that list all the forks and fixture formats used in the indexed fixtures ([#1318](https://github.com/ethereum/execution-spec-tests/pull/1318)).
1819
- 🐞 Don't parametrize tests for unsupported fixture formats; improve `consume` test collection ([#1315](https://github.com/ethereum/execution-spec-tests/pull/1314)).
1920
- 🐞 Improve index generation of ethereum/tests fixtures: Allow generation at any directory level and include `generatedTestHash` in the index file for the `fixture_hash` ([#1303](https://github.com/ethereum/execution-spec-tests/pull/1303)).
2021

src/cli/gen_index.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ def generate_fixtures_index(
140140
disable=quiet_mode,
141141
) as progress: # type: Progress
142142
task_id = progress.add_task("[cyan]Processing files...", total=total_files, filename="...")
143-
143+
forks = set()
144+
fixture_formats = set()
144145
test_cases: List[TestCaseIndexFile] = []
145146
for file in input_path.rglob("*.json"):
146147
if file.name == "index.json" or ".meta" in file.parts:
@@ -165,6 +166,8 @@ def generate_fixtures_index(
165166
format=fixture.__class__,
166167
)
167168
)
169+
forks.add(fixture.get_fork())
170+
fixture_formats.add(fixture.format_name)
168171

169172
display_filename = file.name
170173
if len(display_filename) > filename_display_width:
@@ -185,6 +188,8 @@ def generate_fixtures_index(
185188
root_hash=root_hash,
186189
created_at=datetime.datetime.now(),
187190
test_count=len(test_cases),
191+
forks=list(forks),
192+
fixture_formats=list(fixture_formats),
188193
)
189194

190195
with open(output_file, "w") as f:

src/ethereum_test_fixtures/consume.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import datetime
44
from abc import ABC, abstractmethod
55
from pathlib import Path
6-
from typing import List, TextIO
6+
from typing import List, Optional, TextIO
77

88
from pydantic import BaseModel, RootModel
99

@@ -80,6 +80,8 @@ class IndexFile(BaseModel):
8080
root_hash: HexNumber | None
8181
created_at: datetime.datetime
8282
test_count: int
83+
forks: Optional[List[str]] = []
84+
fixture_formats: Optional[List[str]] = []
8385
test_cases: List[TestCaseIndexFile]
8486

8587

src/ethereum_test_forks/helpers.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,17 @@ def forks_from(fork: Fork, deployed_only: bool = True) -> List[Fork]:
221221
return forks_from_until(fork, latest_fork)
222222

223223

224-
def get_relative_fork_markers(fork_identifier: Fork | str) -> list[str]:
224+
def get_relative_fork_markers(fork_identifier: Fork | str, strict_mode: bool = True) -> list[str]:
225225
"""
226226
Return a list of marker names for a given fork.
227+
227228
For a base fork (e.g. `Shanghai`), return [ `Shanghai` ].
228229
For a transition fork (e.g. `ShanghaiToCancunAtTime15k` which transitions to `Cancun`),
229230
return [ `ShanghaiToCancunAtTime15k`, `Cancun` ].
231+
232+
If `strict_mode` is set to `True`, raise an `InvalidForkError` if the fork is not found,
233+
otherwise, simply return the provided (str) `fork_identifier` (this is required to run
234+
`consume` with forks that are unknown to EEST).
230235
"""
231236
all_forks = set(get_forks()) | set(get_transition_forks())
232237
if isinstance(fork_identifier, str):
@@ -235,8 +240,9 @@ def get_relative_fork_markers(fork_identifier: Fork | str) -> list[str]:
235240
if candidate.name() == fork_identifier:
236241
fork_class = candidate
237242
break
238-
if fork_class is None:
243+
if strict_mode and fork_class is None:
239244
raise InvalidForkError(f"Unknown fork: {fork_identifier}")
245+
return [fork_identifier]
240246
else:
241247
fork_class = fork_identifier
242248

src/pytest_plugins/consume/consume.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from cli.gen_index import generate_fixtures_index
1818
from ethereum_test_fixtures import BaseFixture
19-
from ethereum_test_fixtures.consume import TestCases
19+
from ethereum_test_fixtures.consume import IndexFile, TestCases
2020
from ethereum_test_forks import get_forks, get_relative_fork_markers, get_transition_forks
2121
from ethereum_test_tools.utility.versioning import get_current_commit_hash_or_tag
2222

@@ -291,17 +291,23 @@ def pytest_configure(config): # noqa: D103
291291
force_flag=False,
292292
disable_infer_format=False,
293293
)
294-
config.test_cases = TestCases.from_index_file(index_file)
295294

296-
all_forks_with_transitions = { # type: ignore
297-
fork for fork in set(get_forks()) | get_transition_forks() if not fork.ignore()
298-
}
295+
index = IndexFile.model_validate_json(index_file.read_text())
296+
config.test_cases = index.test_cases
297+
299298
for fixture_format in BaseFixture.formats.values():
300299
config.addinivalue_line(
301300
"markers",
302301
f"{fixture_format.format_name}: Tests in `{fixture_format.format_name}` format ",
303302
)
304-
for fork in all_forks_with_transitions:
303+
304+
# All forked defined within EEST
305+
all_forks = { # type: ignore
306+
fork for fork in set(get_forks()) | get_transition_forks() if not fork.ignore()
307+
}
308+
# Append all forks within the index file (compatibility with `ethereum/tests`)
309+
all_forks.update(getattr(index, "forks", []))
310+
for fork in all_forks:
305311
config.addinivalue_line("markers", f"{fork}: Tests for the {fork} fork")
306312

307313
if config.option.sim_limit:
@@ -364,7 +370,7 @@ def pytest_generate_tests(metafunc):
364370
for test_case in test_cases:
365371
if test_case.format.format_name not in metafunc.config._supported_fixture_formats:
366372
continue
367-
fork_markers = get_relative_fork_markers(test_case.fork)
373+
fork_markers = get_relative_fork_markers(test_case.fork, strict_mode=False)
368374
param = pytest.param(
369375
test_case,
370376
id=test_case.id,

0 commit comments

Comments
 (0)