Skip to content

Commit dcc1029

Browse files
committed
enhance(tests): subclass Hardfork
1 parent da8552f commit dcc1029

File tree

8 files changed

+47
-32
lines changed

8 files changed

+47
-32
lines changed

src/ethereum_spec_tools/forks.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -257,20 +257,6 @@ def title_case_name(self) -> str:
257257
"""
258258
return self.short_name.replace("_", " ").title()
259259

260-
@property
261-
def json_test_name(self) -> str:
262-
"""
263-
Name of the hard fork in the test json fixtures.
264-
"""
265-
if self.title_case_name == "Tangerine Whistle":
266-
return "EIP150"
267-
elif self.title_case_name == "Spurious Dragon":
268-
return "EIP158"
269-
elif self.title_case_name == "Constantinople":
270-
return "ConstantinopleFix"
271-
else:
272-
return self.title_case_name
273-
274260
def __repr__(self) -> str:
275261
"""
276262
Return repr(self).

tests/json_infra/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from typing_extensions import NotRequired
66

7-
from ethereum_spec_tools.forks import Hardfork
7+
from .hardfork import TestHardfork
88

99

1010
class _FixtureSource(TypedDict):
@@ -33,6 +33,6 @@ class _FixtureSource(TypedDict):
3333
}
3434

3535

36-
FORKS: Dict[str, str] = {
37-
fork.json_test_name: fork.short_name for fork in Hardfork.discover()
36+
FORKS: Dict[str, TestHardfork] = {
37+
fork.json_test_name: fork for fork in TestHardfork.discover()
3838
}

tests/json_infra/conftest.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
from requests_cache import CachedSession
2424
from requests_cache.backends.sqlite import SQLiteCache
2525

26-
from ethereum_spec_tools.forks import Hardfork
27-
28-
from . import TEST_FIXTURES
26+
from . import FORKS, TEST_FIXTURES
2927
from .helpers import FixturesFile, FixtureTestItem
3028
from .helpers.select_tests import extract_affected_forks
3129
from .stash_keys import desired_forks_key, fixture_lock
@@ -131,7 +129,7 @@ def pytest_configure(config: Config) -> None:
131129
file_list = config.getoption("file_list", None)
132130

133131
desired_forks = []
134-
all_forks = [fork.json_test_name for fork in Hardfork.discover()]
132+
all_forks = list(FORKS.keys())
135133
if desired_fork:
136134
if desired_fork not in all_forks:
137135
raise ValueError(f"Unknown fork: {desired_fork}")
@@ -168,7 +166,7 @@ def pytest_configure(config: Config) -> None:
168166
if not any(desired_forks):
169167
print("No fork specific tests will be run!!!")
170168
else:
171-
fork_list_str = " ".join(desired_forks)
169+
fork_list_str = ", ".join(desired_forks)
172170
print(f"Running tests for the following forks: {fork_list_str}")
173171

174172
config.stash[desired_forks_key] = desired_forks

tests/json_infra/hardfork.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
Test-specific Hardfork subclass.
3+
4+
Extends the base Hardfork class with test infrastructure properties.
5+
"""
6+
7+
from ethereum_spec_tools.forks import Hardfork
8+
9+
10+
class TestHardfork(Hardfork):
11+
"""
12+
Hardfork subclass with test-specific properties.
13+
14+
This class extends the base Hardfork class with properties needed
15+
for test infrastructure, keeping test-specific concerns separated
16+
from the core fork metadata.
17+
"""
18+
19+
@property
20+
def json_test_name(self) -> str:
21+
"""
22+
Name of the hard fork in the test json fixtures.
23+
"""
24+
if self.title_case_name == "Tangerine Whistle":
25+
return "EIP150"
26+
elif self.title_case_name == "Spurious Dragon":
27+
return "EIP158"
28+
elif self.title_case_name == "Constantinople":
29+
return "ConstantinopleFix"
30+
else:
31+
return self.title_case_name

tests/json_infra/helpers/load_blockchain_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(
7575
self.fork_name = self.test_dict["network"]
7676
self.add_marker(pytest.mark.fork(self.fork_name))
7777
self.add_marker("json_blockchain_tests")
78-
self.eels_fork = FORKS[self.fork_name]
78+
self.eels_fork = FORKS[self.fork_name].short_name
7979
test_patterns = exceptional_blockchain_test_patterns(
8080
self.fork_name, self.eels_fork
8181
)

tests/json_infra/helpers/load_state_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __init__(
4747
self.add_marker(pytest.mark.fork(self.fork_name))
4848
self.add_marker("evm_tools")
4949
self.add_marker("json_state_tests")
50-
eels_fork = FORKS[fork_name]
50+
eels_fork = FORKS[fork_name].short_name
5151
test_patterns = exceptional_state_test_patterns(fork_name, eels_fork)
5252
if any(x.search(key) for x in test_patterns.slow):
5353
self.add_marker("slow")

tests/json_infra/test_ethash.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
@pytest.mark.parametrize("json_fork", POW_FORKS)
4545
def test_ethtest_fixtures(json_fork: str) -> None:
4646
"""Tests ethash proof-of-work validation against ethereum test fixtures."""
47-
eels_fork = FORKS[json_fork]
47+
eels_fork = FORKS[json_fork].short_name
4848
fork_module = importlib.import_module(f"ethereum.forks.{eels_fork}.fork")
4949

5050
ethereum_tests = load_pow_test_fixtures(json_fork)
@@ -79,7 +79,7 @@ def load_pow_test_fixtures(json_fork: str) -> List[Dict[str, Any]]:
7979
Loads proof-of-work test fixtures for a specific fork
8080
from JSON files.
8181
"""
82-
eels_fork = FORKS[json_fork]
82+
eels_fork = FORKS[json_fork].short_name
8383
header = importlib.import_module(
8484
f"ethereum.forks.{eels_fork}.blocks"
8585
).Header
@@ -122,7 +122,7 @@ def test_pow_validation_block_headers(
122122
Tests proof-of-work validation on real block headers for
123123
specific forks.
124124
"""
125-
eels_fork = FORKS[json_fork]
125+
eels_fork = FORKS[json_fork].short_name
126126
fork_module = importlib.import_module(f"ethereum.forks.{eels_fork}.fork")
127127

128128
block_str_data = cast(

tests/json_infra/test_trie.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_trie_secure_hex(fork: str) -> None:
3131
"""Tests secure trie implementation with hex-encoded test data."""
3232
tests = load_tests("hex_encoded_securetrie_test.json")
3333

34-
eels_fork = FORKS[fork]
34+
eels_fork = FORKS[fork].short_name
3535
trie_module = importlib.import_module(f"ethereum.forks.{eels_fork}.trie")
3636

3737
for name, test in tests.items():
@@ -48,7 +48,7 @@ def test_trie_secure(fork: str) -> None:
4848
"""Tests secure trie implementation with standard test data."""
4949
tests = load_tests("trietest_secureTrie.json")
5050

51-
eels_fork = FORKS[fork]
51+
eels_fork = FORKS[fork].short_name
5252
trie_module = importlib.import_module(f"ethereum.forks.{eels_fork}.trie")
5353

5454
for name, test in tests.items():
@@ -65,7 +65,7 @@ def test_trie_secure_any_order(fork: str) -> None:
6565
"""Tests secure trie implementation with any-order test data."""
6666
tests = load_tests("trieanyorder_secureTrie.json")
6767

68-
eels_fork = FORKS[fork]
68+
eels_fork = FORKS[fork].short_name
6969
trie_module = importlib.import_module(f"ethereum.forks.{eels_fork}.trie")
7070

7171
for name, test in tests.items():
@@ -82,7 +82,7 @@ def test_trie(fork: str) -> None:
8282
"""Tests non-secure trie implementation with standard test data."""
8383
tests = load_tests("trietest.json")
8484

85-
eels_fork = FORKS[fork]
85+
eels_fork = FORKS[fork].short_name
8686
trie_module = importlib.import_module(f"ethereum.forks.{eels_fork}.trie")
8787

8888
for name, test in tests.items():
@@ -99,7 +99,7 @@ def test_trie_any_order(fork: str) -> None:
9999
"""Tests non-secure trie implementation with any-order test data."""
100100
tests = load_tests("trieanyorder.json")
101101

102-
eels_fork = FORKS[fork]
102+
eels_fork = FORKS[fork].short_name
103103
trie_module = importlib.import_module(f"ethereum.forks.{eels_fork}.trie")
104104

105105
for name, test in tests.items():

0 commit comments

Comments
 (0)