Skip to content

Commit 27b8a9d

Browse files
committed
run tests for eof
1 parent 514a68a commit 27b8a9d

File tree

4 files changed

+170
-76
lines changed

4 files changed

+170
-76
lines changed

tests/helpers/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
# Update the links and commit has in order to consume
22
# newer/other tests
33
TEST_FIXTURES = {
4+
"execution_spec_tests": {
5+
"url": "https://github.com/ethereum/execution-spec-tests/releases/download/v0.2.5/fixtures.tar.gz",
6+
"fixture_path": "tests/fixtures/execution_spec_tests",
7+
},
48
"evm_tools_testdata": {
59
"url": "https://github.com/gurukamath/evm-tools-testdata.git",
610
"commit_hash": "792422d",
711
"fixture_path": "tests/fixtures/evm_tools_testdata",
812
},
913
"ethereum_tests": {
1014
"url": "https://github.com/ethereum/tests.git",
11-
"commit_hash": "afed83b",
15+
"commit_hash": "9201075",
1216
"fixture_path": "tests/fixtures/ethereum_tests",
1317
},
1418
"latest_fork_tests": {
1519
"url": "https://github.com/gurukamath/latest_fork_tests.git",
16-
"commit_hash": "bc74af5",
20+
"commit_hash": "3962b8c",
1721
"fixture_path": "tests/fixtures/latest_fork_tests",
1822
},
1923
}
20-
21-
22-
ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"]
23-
EEST_TESTS_PATH = TEST_FIXTURES["latest_fork_tests"]["fixture_path"]

tests/osaka/test_eof.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import json
2+
import os
3+
from glob import glob
4+
from typing import Dict, Generator, Tuple
5+
6+
import pytest
7+
8+
from ethereum.osaka.vm.eof import ContainerContext
9+
from ethereum.osaka.vm.eof.validation import validate_eof_container
10+
from ethereum.osaka.vm.exceptions import InvalidEof
11+
from ethereum.utils.hexadecimal import hex_to_bytes
12+
13+
TEST_DIRS = (
14+
"tests/fixtures/latest_fork_tests/osaka/eof/eof_tests/eip7692_eof_v1",
15+
"tests/fixtures/ethereum_tests/EOFTests/",
16+
"tests/fixtures/latest_fork_tests/osaka/eof/evmone_tests/eof_tests",
17+
)
18+
19+
20+
def fetch_eof_tests(test_dirs: Tuple[str, ...]) -> Generator:
21+
for test_dir in test_dirs:
22+
all_jsons = [
23+
y
24+
for x in os.walk(test_dir)
25+
for y in glob(os.path.join(x[0], "*.json"))
26+
]
27+
28+
for full_path in all_jsons:
29+
# Read the json file and yield the test cases
30+
with open(full_path, "r") as file:
31+
data = json.load(file)
32+
for test in data.keys():
33+
try:
34+
keys = data[test]["vectors"].keys()
35+
except AttributeError:
36+
continue
37+
for key in keys:
38+
yield {
39+
"test_file": full_path,
40+
"test_name": test,
41+
"test_key": key,
42+
}
43+
44+
45+
# Test case Identifier
46+
def idfn(test_case: Dict) -> str:
47+
if isinstance(test_case, dict):
48+
return (
49+
test_case["test_file"]
50+
+ " - "
51+
+ test_case["test_name"]
52+
+ " - "
53+
+ test_case["test_key"]
54+
)
55+
56+
57+
# Run the tests
58+
@pytest.mark.parametrize(
59+
"test_case",
60+
fetch_eof_tests(TEST_DIRS),
61+
ids=idfn,
62+
)
63+
def test_eof(test_case: Dict) -> None:
64+
test_file = test_case["test_file"]
65+
test_name = test_case["test_name"]
66+
test_key = test_case["test_key"]
67+
68+
with open(test_file, "r") as f:
69+
test_data = json.load(f)
70+
test_vector = test_data[test_name]["vectors"][test_key]
71+
72+
# Extract the test data
73+
code = hex_to_bytes(test_vector["code"])
74+
if test_vector.get("containerKind") == "INITCODE":
75+
context = ContainerContext.INIT
76+
else:
77+
context = ContainerContext.RUNTIME
78+
79+
# TODO: This has to eventually be just Osaka
80+
try:
81+
prague_validation = test_vector["results"]["Osaka"]
82+
except KeyError:
83+
prague_validation = test_vector["results"]["Prague"]
84+
85+
if "exception" in prague_validation and prague_validation["result"]:
86+
raise Exception("Test case has both exception and result")
87+
88+
if "exception" in prague_validation:
89+
with pytest.raises(InvalidEof):
90+
validate_eof_container(code, context)
91+
else:
92+
validate_eof_container(code, context)

tests/osaka/test_evm_tools.py

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,58 @@
11
from functools import partial
2-
from typing import Dict
2+
from typing import Dict, Generator, Tuple
33

44
import pytest
55

6-
from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH
6+
from tests.helpers import TEST_FIXTURES
77
from tests.helpers.load_evm_tools_tests import (
88
fetch_evm_tools_tests,
99
idfn,
1010
load_evm_tools_test,
1111
)
1212

13-
ETHEREUM_STATE_TESTS_DIR = f"{ETHEREUM_TESTS_PATH}/GeneralStateTests/"
14-
EEST_STATE_TESTS_DIR = f"{EEST_TESTS_PATH}/state_tests/"
13+
ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"]
14+
TEST_DIR = f"{ETHEREUM_TESTS_PATH}/GeneralStateTests/"
1515
FORK_NAME = "Osaka"
1616

17+
run_evm_tools_test = partial(
18+
load_evm_tools_test,
19+
fork_name=FORK_NAME,
20+
)
1721

1822
SLOW_TESTS = (
1923
"CALLBlake2f_MaxRounds",
2024
"CALLCODEBlake2f",
2125
"CALLBlake2f",
2226
"loopExp",
2327
"loopMul",
24-
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Prague-state_test-bls_pairing_non-degeneracy-]",
25-
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Prague-state_test-bls_pairing_bilinearity-]",
26-
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Prague-state_test-bls_pairing_e(G1,-G2)=e(-G1,G2)-]",
27-
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Prague-state_test-bls_pairing_e(aG1,bG2)=e(abG1,G2)-]",
28-
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Prague-state_test-bls_pairing_e(aG1,bG2)=e(G1,abG2)-]",
29-
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Prague-state_test-inf_pair-]",
30-
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Prague-state_test-multi_inf_pair-]",
28+
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Osaka-state_test-bls_pairing_non-degeneracy-]",
29+
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Osaka-state_test-bls_pairing_bilinearity-]",
30+
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Osaka-state_test-bls_pairing_e(G1,-G2)=e(-G1,G2)-]",
31+
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Osaka-state_test-bls_pairing_e(aG1,bG2)=e(abG1,G2)-]",
32+
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Osaka-state_test-bls_pairing_e(aG1,bG2)=e(G1,abG2)-]",
33+
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Osaka-state_test-inf_pair-]",
34+
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Osaka-state_test-multi_inf_pair-]",
3135
)
3236

33-
34-
# Define tests
35-
fetch_tests = partial(
36-
fetch_evm_tools_tests,
37-
fork_name=FORK_NAME,
38-
slow_tests=SLOW_TESTS,
39-
)
40-
41-
run_tests = partial(
42-
load_evm_tools_test,
43-
fork_name=FORK_NAME,
37+
test_dirs = (
38+
"tests/fixtures/latest_fork_tests/osaka/eof/state_tests/eip7692_eof_v1",
4439
)
4540

4641

47-
# Run tests from ethereum/tests
48-
@pytest.mark.evm_tools
49-
@pytest.mark.parametrize(
50-
"test_case",
51-
fetch_tests(ETHEREUM_STATE_TESTS_DIR),
52-
ids=idfn,
53-
)
54-
def test_ethereum_tests_evm_tools(test_case: Dict) -> None:
55-
run_tests(test_case)
42+
def fetch_temporary_tests(test_dirs: Tuple[str, ...]) -> Generator:
43+
for test_dir in test_dirs:
44+
yield from fetch_evm_tools_tests(
45+
test_dir,
46+
FORK_NAME,
47+
SLOW_TESTS,
48+
)
5649

5750

58-
# Run EEST test fixtures
5951
@pytest.mark.evm_tools
6052
@pytest.mark.parametrize(
6153
"test_case",
62-
fetch_tests(EEST_STATE_TESTS_DIR),
54+
fetch_temporary_tests(test_dirs),
6355
ids=idfn,
6456
)
65-
def test_eest_evm_tools(test_case: Dict) -> None:
66-
run_tests(test_case)
57+
def test_evm_tools(test_case: Dict) -> None:
58+
run_evm_tools_test(test_case)

tests/osaka/test_state_transition.py

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,41 @@
11
from functools import partial
2-
from typing import Dict
2+
from typing import Dict, Generator, Tuple
33

44
import pytest
55

6-
from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH
6+
from tests.helpers import TEST_FIXTURES
77
from tests.helpers.load_state_tests import (
88
Load,
99
fetch_state_test_files,
1010
idfn,
1111
run_blockchain_st_test,
1212
)
1313

14-
ETHEREUM_BLOCKCHAIN_TESTS_DIR = f"{ETHEREUM_TESTS_PATH}/BlockchainTests/"
15-
EEST_BLOCKCHAIN_TESTS_DIR = f"{EEST_TESTS_PATH}/blockchain_tests/"
16-
NETWORK = "Osaka"
17-
PACKAGE = "osaka"
14+
fetch_osaka_tests = partial(fetch_state_test_files, network="Osaka")
15+
16+
FIXTURES_LOADER = Load("Osaka", "osaka")
17+
18+
run_osaka_blockchain_st_tests = partial(
19+
run_blockchain_st_test, load=FIXTURES_LOADER
20+
)
21+
22+
ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"]
23+
ETHEREUM_SPEC_TESTS_PATH = TEST_FIXTURES["execution_spec_tests"][
24+
"fixture_path"
25+
]
26+
27+
28+
# Run state tests
29+
test_dir = f"{ETHEREUM_TESTS_PATH}/BlockchainTests/"
1830

1931
SLOW_TESTS = (
2032
# GeneralStateTests
2133
"stTimeConsuming/CALLBlake2f_MaxRounds.json",
2234
"stTimeConsuming/static_Call50000_sha256.json",
2335
"vmPerformance/loopExp.json",
2436
"vmPerformance/loopMul.json",
25-
"QuadraticComplexitySolidity_CallDataCopy_d0g1v0_Prague",
26-
"CALLBlake2f_d9g0v0_Prague",
37+
"QuadraticComplexitySolidity_CallDataCopy_d0g1v0_Osaka",
38+
"CALLBlake2f_d9g0v0_Osaka",
2739
"CALLCODEBlake2f_d9g0v0",
2840
# GeneralStateTests
2941
"stRandom/randomStatetest177.json",
@@ -33,14 +45,14 @@
3345
# InvalidBlockTest
3446
"bcUncleHeaderValidity/nonceWrong.json",
3547
"bcUncleHeaderValidity/wrongMixHash.json",
36-
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Prague-blockchain_test-bls_pairing_non-degeneracy-\\]",
37-
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Prague-blockchain_test-bls_pairing_bilinearity-\\]",
38-
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Prague-blockchain_test-bls_pairing_e\\(G1,-G2\\)=e\\(-G1,G2\\)-\\]",
39-
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Prague-blockchain_test-bls_pairing_e\\(aG1,bG2\\)=e\\(abG1,G2\\)-\\]",
40-
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Prague-blockchain_test-bls_pairing_e\\(aG1,bG2\\)=e\\(G1,abG2\\)-\\]",
41-
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Prague-blockchain_test-inf_pair-\\]",
42-
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Prague-blockchain_test-multi_inf_pair-\\]",
43-
"tests/osaka/eip2935_historical_block_hashes_from_state/test_block_hashes\\.py\\:\\:test_block_hashes_history\\[fork_Prague-blockchain_test-full_history_plus_one_check_blockhash_first\\]",
48+
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Osaka-blockchain_test-bls_pairing_non-degeneracy-\\]",
49+
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Osaka-blockchain_test-bls_pairing_bilinearity-\\]",
50+
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Osaka-blockchain_test-bls_pairing_e\\(G1,-G2\\)=e\\(-G1,G2\\)-\\]",
51+
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Osaka-blockchain_test-bls_pairing_e\\(aG1,bG2\\)=e\\(abG1,G2\\)-\\]",
52+
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Osaka-blockchain_test-bls_pairing_e\\(aG1,bG2\\)=e\\(G1,abG2\\)-\\]",
53+
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Osaka-blockchain_test-inf_pair-\\]",
54+
"tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Osaka-blockchain_test-multi_inf_pair-\\]",
55+
"tests/osaka/eip2935_historical_block_hashes_from_state/test_block_hashes\\.py\\:\\:test_block_hashes_history\\[fork_Osaka-blockchain_test-full_history_plus_one_check_blockhash_first\\]",
4456
)
4557

4658
# These are tests that are considered to be incorrect,
@@ -54,7 +66,7 @@
5466
# InvalidBlockTest
5567
"bcForgedTest",
5668
"bcMultiChainTest",
57-
"GasLimitHigherThan2p63m1_Prague",
69+
"GasLimitHigherThan2p63m1_Osaka",
5870
)
5971

6072
# All tests that recursively create a large number of frames (50000)
@@ -70,35 +82,33 @@
7082
"stStaticCall/",
7183
)
7284

73-
# Define Tests
74-
fetch_tests = partial(
75-
fetch_state_test_files,
76-
network=NETWORK,
85+
fetch_state_tests = partial(
86+
fetch_osaka_tests,
7787
ignore_list=IGNORE_TESTS,
7888
slow_list=SLOW_TESTS,
7989
big_memory_list=BIG_MEMORY_TESTS,
8090
)
8191

82-
FIXTURES_LOADER = Load(NETWORK, PACKAGE)
8392

84-
run_tests = partial(run_blockchain_st_test, load=FIXTURES_LOADER)
93+
# Run temporary test fixtures for Osaka
94+
test_dirs = (
95+
"tests/fixtures/latest_fork_tests/osaka/eof/blockchain_tests/eip7692_eof_v1",
96+
)
8597

8698

87-
# Run tests from ethereum/tests
88-
@pytest.mark.parametrize(
89-
"test_case",
90-
fetch_tests(ETHEREUM_BLOCKCHAIN_TESTS_DIR),
91-
ids=idfn,
92-
)
93-
def test_ethereum_tests(test_case: Dict) -> None:
94-
run_tests(test_case)
99+
def fetch_temporary_tests(test_dirs: Tuple[str, ...]) -> Generator:
100+
"""
101+
Fetch the relevant tests for a particular EIP-Implementation
102+
from among the temporary fixtures from ethereum-spec-tests.
103+
"""
104+
for test_dir in test_dirs:
105+
yield from fetch_state_tests(test_dir)
95106

96107

97-
# Run EEST test fixtures
98108
@pytest.mark.parametrize(
99109
"test_case",
100-
fetch_tests(EEST_BLOCKCHAIN_TESTS_DIR),
110+
fetch_temporary_tests(test_dirs),
101111
ids=idfn,
102112
)
103-
def test_eest_tests(test_case: Dict) -> None:
104-
run_tests(test_case)
113+
def test_execution_specs_generated_tests(test_case: Dict) -> None:
114+
run_osaka_blockchain_st_tests(test_case)

0 commit comments

Comments
 (0)