Skip to content

Commit 3dad5f7

Browse files
committed
post review: other fixes
1 parent f4da641 commit 3dad5f7

File tree

6 files changed

+126
-101
lines changed

6 files changed

+126
-101
lines changed

tests/json_infra/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class _FixtureSource(TypedDict):
99
commit_hash: NotRequired[str]
1010

1111

12-
# Update the links and commit has in order to consume
12+
# Update the links and commit hash in order to consume
1313
# newer/other tests
1414
TEST_FIXTURES: Dict[str, _FixtureSource] = {
1515
"evm_tools_testdata": {
@@ -82,9 +82,19 @@ def _build_eest_test_paths(base_path: str) -> tuple:
8282
)
8383

8484

85+
ForkConfig = TypedDict(
86+
"ForkConfig",
87+
{
88+
"eels_fork": str,
89+
"blockchain_test_dirs": list[str],
90+
"state_test_dirs": list[str],
91+
},
92+
)
93+
94+
8595
def _create_fork_config(
8696
eels_fork: str, bc_dirs: list, state_dirs: list
87-
) -> dict:
97+
) -> ForkConfig:
8898
return {
8999
"eels_fork": eels_fork,
90100
"blockchain_test_dirs": bc_dirs,
@@ -112,7 +122,7 @@ def _create_fork_config(
112122
[STATE_ETHEREUM_TESTS, EEST_OSAKA_STATE_TESTS],
113123
)
114124

115-
FORKS = {
125+
FORKS: Dict[str, ForkConfig] = {
116126
**{
117127
json_fork: _create_fork_config(eels_fork, *PRE_CONSTANTINOPLE_DIRS)
118128
for json_fork, eels_fork in [
Lines changed: 58 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1-
from typing import Tuple
1+
import re
2+
from dataclasses import dataclass
3+
from typing import Pattern, Tuple
24

35

4-
def get_exceptional_blockchain_test_patterns(
6+
@dataclass
7+
class TestPatterns:
8+
"""
9+
Identify test patterns which are slow, are to be ignored
10+
or are to be marked as consuming large memory at runtime.
11+
"""
12+
13+
slow: Tuple[Pattern[str], ...]
14+
expected_fail: Tuple[Pattern[str], ...]
15+
big_memory: Tuple[Pattern[str], ...]
16+
17+
18+
def exceptional_blockchain_test_patterns(
519
json_fork: str, eels_fork: str
6-
) -> Tuple[tuple[str, ...], tuple[str, ...], tuple[str, ...]]:
20+
) -> TestPatterns:
721
"""
822
Returns patterns for slow, ignored, and big-memory tests for a given json_fork and eels_fork.
923
@@ -16,21 +30,20 @@ def get_exceptional_blockchain_test_patterns(
1630
1731
Returns
1832
-------
19-
slow_tests :
20-
Patterns to match test files or test ids that should be marked as slow.
21-
ignore_tests :
22-
Patterns to match test files or test ids that should be ignored.
23-
big_memory_tests :
24-
Patterns to match test files or test ids that require large memory.
33+
TestPatterns :
34+
Patterns that are relevant to the current fork.
2535
"""
36+
jf = re.escape(json_fork)
37+
ef = re.escape(eels_fork)
38+
2639
slow_tests = (
2740
# GeneralStateTests
2841
"stTimeConsuming/CALLBlake2f_MaxRounds.json",
2942
"stTimeConsuming/static_Call50000_sha256.json",
3043
"vmPerformance/loopExp.json",
3144
"vmPerformance/loopMul.json",
32-
f"QuadraticComplexitySolidity_CallDataCopy_d0g1v0_{json_fork}",
33-
f"CALLBlake2f_d9g0v0_{json_fork}",
45+
f"QuadraticComplexitySolidity_CallDataCopy_d0g1v0_{jf}",
46+
f"CALLBlake2f_d9g0v0_{jf}",
3447
"CALLCODEBlake2f_d9g0v0",
3548
# GeneralStateTests
3649
"stRandom/randomStatetest177.json",
@@ -40,19 +53,19 @@ def get_exceptional_blockchain_test_patterns(
4053
# InvalidBlockTest
4154
"bcUncleHeaderValidity/nonceWrong.json",
4255
"bcUncleHeaderValidity/wrongMixHash.json",
43-
f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{json_fork}-blockchain_test-bls_pairing_non-degeneracy-\\]",
44-
f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{json_fork}-blockchain_test-bls_pairing_bilinearity-\\]",
45-
f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{json_fork}-blockchain_test-bls_pairing_e\\(G1,-G2\\)=e\\(-G1,G2\\)-\\]",
46-
f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{json_fork}-blockchain_test-bls_pairing_e\\(aG1,bG2\\)=e\\(abG1,G2\\)-\\]",
47-
f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{json_fork}-blockchain_test-bls_pairing_e\\(aG1,bG2\\)=e\\(G1,abG2\\)-\\]",
48-
f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{json_fork}-blockchain_test-inf_pair-\\]",
49-
f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{json_fork}-blockchain_test-multi_inf_pair-\\]",
50-
f"tests/{eels_fork}/eip2935_historical_block_hashes_from_state/test_block_hashes\\.py\\:\\:test_block_hashes_history\\[fork_{json_fork}-blockchain_test-full_history_plus_one_check_blockhash_first\\]",
56+
f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-blockchain_test-bls_pairing_non-degeneracy-\\]",
57+
f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-blockchain_test-bls_pairing_bilinearity-\\]",
58+
f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-blockchain_test-bls_pairing_e(G1,-G2)=e(-G1,G2)-\\]",
59+
f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-blockchain_test-bls_pairing_e(aG1,bG2)=e(abG1,G2)-\\]",
60+
f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-blockchain_test-bls_pairing_e(aG1,bG2)=e(G1,abG2)-\\]",
61+
f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-blockchain_test-inf_pair-\\]",
62+
f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-blockchain_test-multi_inf_pair-\\]",
63+
f"tests/{ef}/eip2935_historical_block_hashes_from_state/test_block_hashes.py::test_block_hashes_history\\[fork_{jf}-blockchain_test-full_history_plus_one_check_blockhash_first\\]",
5164
)
5265

5366
# These are tests that are considered to be incorrect,
5467
# Please provide an explanation when adding entries
55-
ignore_tests = (
68+
expected_fail = (
5669
# ValidBlockTest
5770
"bcForkStressTest/ForkStressTest.json",
5871
"bcGasPricerTest/RPC_API_Test.json",
@@ -61,7 +74,7 @@ def get_exceptional_blockchain_test_patterns(
6174
# InvalidBlockTest
6275
"bcForgedTest",
6376
"bcMultiChainTest",
64-
f"GasLimitHigherThan2p63m1_{json_fork}",
77+
f"GasLimitHigherThan2p63m1_{jf}",
6578
)
6679

6780
# All tests that recursively create a large number of frames (50000)
@@ -77,28 +90,38 @@ def get_exceptional_blockchain_test_patterns(
7790
"stStaticCall/",
7891
)
7992

80-
return slow_tests, ignore_tests, big_memory_tests
93+
return TestPatterns(
94+
slow=tuple(re.compile(p) for p in slow_tests),
95+
expected_fail=tuple(re.compile(p) for p in expected_fail),
96+
big_memory=tuple(re.compile(p) for p in big_memory_tests),
97+
)
8198

8299

83-
def get_exceptional_state_test_patterns(
100+
def exceptional_state_test_patterns(
84101
json_fork: str, eels_fork: str
85-
) -> tuple[str, ...]:
102+
) -> TestPatterns:
103+
jf = re.escape(json_fork)
104+
ef = re.escape(eels_fork)
86105
slow_tests = (
87106
"CALLBlake2f_MaxRounds",
88107
"CALLCODEBlake2f",
89108
"CALLBlake2f",
90109
"loopExp",
91110
"loopMul",
92-
"GeneralStateTests/stTimeConsuming/CALLBlake2f_MaxRounds.json::CALLBlake2f_MaxRounds-fork_[Cancun-Prague]-d0g0v0",
93-
"GeneralStateTests/VMTests/vmPerformance/loopExp.json::loopExp-fork_[Cancun-Prague]-d[0-14]g0v0",
94-
"GeneralStateTests/VMTests/vmPerformance/loopMul.json::loopMul-fork_[Cancun-Prague]-d[0-2]g0v0",
95-
f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{json_fork}-state_test-bls_pairing_non-degeneracy-]",
96-
f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{json_fork}-state_test-bls_pairing_bilinearity-]",
97-
f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{json_fork}-state_test-bls_pairing_e(G1,-G2)=e(-G1,G2)-]",
98-
f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{json_fork}-state_test-bls_pairing_e(aG1,bG2)=e(abG1,G2)-]",
99-
f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{json_fork}-state_test-bls_pairing_e(aG1,bG2)=e(G1,abG2)-]",
100-
f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{json_fork}-state_test-inf_pair-]",
101-
f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{json_fork}-state_test-multi_inf_pair-]",
111+
"GeneralStateTests/stTimeConsuming/CALLBlake2f_MaxRounds.json::CALLBlake2f_MaxRounds-fork_\\[Cancun-Prague\\]-d0g0v0",
112+
"GeneralStateTests/VMTests/vmPerformance/loopExp.json::loopExp-fork_\\[Cancun-Prague\\]-d[0-14]g0v0",
113+
"GeneralStateTests/VMTests/vmPerformance/loopMul.json::loopMul-fork_\\[Cancun-Prague\\]-d[0-2]g0v0",
114+
f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-state_test-bls_pairing_non-degeneracy-\\]",
115+
f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-state_test-bls_pairing_bilinearity-\\]",
116+
f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-state_test-bls_pairing_e(G1,-G2)=e(-G1,G2)-\\]",
117+
f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-state_test-bls_pairing_e(aG1,bG2)=e(abG1,G2)-\\]",
118+
f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-state_test-bls_pairing_e(aG1,bG2)=e(G1,abG2)-\\]",
119+
f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-state_test-inf_pair-\\]",
120+
f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-state_test-multi_inf_pair-\\]",
102121
)
103122

104-
return slow_tests
123+
return TestPatterns(
124+
slow=tuple(re.compile(p) for p in slow_tests),
125+
expected_fail=tuple(),
126+
big_memory=tuple(),
127+
)

tests/json_infra/helpers/load_blockchain_tests.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import importlib
22
import json
33
import os.path
4-
import re
54
from glob import glob
6-
from typing import Any, Dict, Generator, cast
5+
from typing import Any, Dict, Generator
76
from unittest.mock import call, patch
87

98
import pytest
@@ -18,7 +17,7 @@
1817
from ethereum_spec_tools.evm_tools.loaders.fixture_loader import Load
1918

2019
from .. import FORKS
21-
from .exceptional_test_patterns import get_exceptional_blockchain_test_patterns
20+
from .exceptional_test_patterns import exceptional_blockchain_test_patterns
2221

2322

2423
class NoTestsFound(Exception):
@@ -163,17 +162,10 @@ def fetch_blockchain_tests(
163162
json_fork: str,
164163
) -> Generator[Dict | ParameterSet, None, None]:
165164
# Filter FORKS based on fork_option parameter
166-
eels_fork = cast(str, FORKS[json_fork]["eels_fork"])
167-
test_dirs = cast(list[str], FORKS[json_fork]["blockchain_test_dirs"])
165+
eels_fork = FORKS[json_fork]["eels_fork"]
166+
test_dirs = FORKS[json_fork]["blockchain_test_dirs"]
168167

169-
(
170-
slow_list,
171-
ignore_list,
172-
big_memory_list,
173-
) = get_exceptional_blockchain_test_patterns(json_fork, eels_fork)
174-
all_slow = [re.compile(x) for x in slow_list]
175-
all_big_memory = [re.compile(x) for x in big_memory_list]
176-
all_ignore = [re.compile(x) for x in ignore_list]
168+
test_patterns = exceptional_blockchain_test_patterns(json_fork, eels_fork)
177169

178170
# Get all the files to iterate over from both eest_tests_path and ethereum_tests_path
179171
all_jsons = []
@@ -184,7 +176,7 @@ def fetch_blockchain_tests(
184176

185177
files_to_iterate = []
186178
for full_path in all_jsons:
187-
if not any(x.search(full_path) for x in all_ignore):
179+
if not any(x.search(full_path) for x in test_patterns.expected_fail):
188180
# If a file or folder is marked for ignore,
189181
# it can already be dropped at this stage
190182
files_to_iterate.append(full_path)
@@ -203,11 +195,15 @@ def fetch_blockchain_tests(
203195
+ ")"
204196
)
205197
_test_case["eels_fork"] = eels_fork
206-
if any(x.search(_identifier) for x in all_ignore):
198+
if any(
199+
x.search(_identifier) for x in test_patterns.expected_fail
200+
):
207201
continue
208-
elif any(x.search(_identifier) for x in all_slow):
202+
elif any(x.search(_identifier) for x in test_patterns.slow):
209203
yield pytest.param(_test_case, marks=pytest.mark.slow)
210-
elif any(x.search(_identifier) for x in all_big_memory):
204+
elif any(
205+
x.search(_identifier) for x in test_patterns.big_memory
206+
):
211207
yield pytest.param(_test_case, marks=pytest.mark.bigmem)
212208
else:
213209
yield _test_case

tests/json_infra/helpers/load_state_tests.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
from glob import glob
55
from io import StringIO
6-
from typing import Dict, Generator, cast
6+
from typing import Dict, Generator
77

88
import pytest
99

@@ -14,7 +14,7 @@
1414
from ethereum_spec_tools.evm_tools.t8n import T8N
1515

1616
from .. import FORKS
17-
from .exceptional_test_patterns import get_exceptional_state_test_patterns
17+
from .exceptional_test_patterns import exceptional_state_test_patterns
1818

1919
parser = create_parser()
2020

@@ -24,10 +24,10 @@ def fetch_state_tests(json_fork: str) -> Generator:
2424
Fetches all the general state tests from the given directory
2525
"""
2626
# Filter FORKS based on fork_option parameter
27-
eels_fork = cast(str, FORKS[json_fork]["eels_fork"])
28-
test_dirs = cast(list[str], FORKS[json_fork]["state_test_dirs"])
27+
eels_fork = FORKS[json_fork]["eels_fork"]
28+
test_dirs = FORKS[json_fork]["state_test_dirs"]
2929

30-
slow_tests = get_exceptional_state_test_patterns(json_fork, eels_fork)
30+
test_patterns = exceptional_state_test_patterns(json_fork, eels_fork)
3131

3232
# Get all the files to iterate over from both eest_tests_path and ethereum_tests_path
3333
all_jsons = []
@@ -50,7 +50,7 @@ def fetch_state_tests(json_fork: str) -> Generator:
5050
"json_fork": json_fork,
5151
}
5252

53-
if test_case.key in slow_tests:
53+
if any(x.search(test_case.key) for x in test_patterns.slow):
5454
yield pytest.param(test_case_dict, marks=pytest.mark.slow)
5555
else:
5656
yield test_case_dict

tests/json_infra/test_ethash.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@
3939
]
4040

4141

42-
@pytest.mark.parametrize("network", POW_FORKS)
43-
def test_ethtest_fixtures(network: str) -> None:
44-
package = FORKS[network]["package"]
45-
fork_module = importlib.import_module(f"ethereum.{package}.fork")
42+
@pytest.mark.parametrize("json_fork", POW_FORKS)
43+
def test_ethtest_fixtures(json_fork: str) -> None:
44+
eels_fork = FORKS[json_fork]["eels_fork"]
45+
fork_module = importlib.import_module(f"ethereum.{eels_fork}.fork")
4646

47-
ethereum_tests = load_pow_test_fixtures(network)
47+
ethereum_tests = load_pow_test_fixtures(json_fork)
4848
for test in ethereum_tests:
4949
header = test["header"]
5050
assert header.nonce == test["nonce"]
@@ -71,9 +71,9 @@ def test_ethtest_fixtures(network: str) -> None:
7171
assert result == test["result"]
7272

7373

74-
def load_pow_test_fixtures(network: str) -> List[Dict[str, Any]]:
75-
package = FORKS[network]["package"]
76-
Header = importlib.import_module(f"ethereum.{package}.blocks").Header
74+
def load_pow_test_fixtures(json_fork: str) -> List[Dict[str, Any]]:
75+
eels_fork = FORKS[json_fork]["eels_fork"]
76+
Header = importlib.import_module(f"ethereum.{eels_fork}.blocks").Header
7777

7878
with open(
7979
f"{ETHEREUM_TESTS_PATH}/PoWTests/ethash_tests.json"
@@ -97,7 +97,7 @@ def load_pow_test_fixtures(network: str) -> List[Dict[str, Any]]:
9797

9898

9999
@pytest.mark.slow
100-
@pytest.mark.parametrize("network", POW_FORKS)
100+
@pytest.mark.parametrize("json_fork", POW_FORKS)
101101
@pytest.mark.parametrize(
102102
"block_file_name",
103103
[
@@ -107,17 +107,17 @@ def load_pow_test_fixtures(network: str) -> List[Dict[str, Any]]:
107107
],
108108
)
109109
def test_pow_validation_block_headers(
110-
network: str, block_file_name: str
110+
json_fork: str, block_file_name: str
111111
) -> None:
112-
package = cast(str, FORKS[network]["package"])
113-
fork_module = importlib.import_module(f"ethereum.{package}.fork")
112+
eels_fork = FORKS[json_fork]["eels_fork"]
113+
fork_module = importlib.import_module(f"ethereum.{eels_fork}.fork")
114114

115115
block_str_data = cast(
116116
bytes, pkgutil.get_data("ethereum", f"assets/blocks/{block_file_name}")
117117
).decode()
118118
block_json_data = json.loads(block_str_data)
119119

120-
load = Load(network, package)
120+
load = Load(json_fork, eels_fork)
121121
header = load.json_to_header(block_json_data)
122122
fork_module.validate_proof_of_work(header)
123123

0 commit comments

Comments
 (0)