Skip to content

Commit 951e054

Browse files
authored
feat(weld): add eest tests as a submodule
* update dependencies * add fill to the entry points * add eest tests * run eest tests in py3 * create EELS TransitionTool subclass * post review fix and latest eest * remove pytest-eest.ini * minor fix: fix tox config * minor fix: add vulture exception * run eest tests in pypy * update optimized tox command
1 parent 20cdaf9 commit 951e054

File tree

10 files changed

+199
-12
lines changed

10 files changed

+199
-12
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
4646
- name: Run Tox (CPython)
4747
if: "${{ !startsWith(matrix.py, 'pypy') }}"
48-
run: tox -e static,optimized,py3
48+
run: tox -e static,py3_eest,optimized,py3
4949

5050
- name: Run Tox (PyPy)
5151
if: "${{ startsWith(matrix.py, 'pypy') }}"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,5 @@ pip-delete-this-directory.txt
5858
tests/execution-spec-generated-tests
5959
tests/fixtures
6060
tests/t8n_testdata
61+
62+
fixtures

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "eest_tests/execution-spec-tests"]
2+
path = eest_tests/execution-spec-tests
3+
url = https://github.com/ethereum/execution-spec-tests.git

eest_tests/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import pytest
2+
from ethereum_spec_tools.evm_tools.t8n.transition_tool import EELST8N
3+
from ethereum_clis import TransitionTool
4+
5+
6+
@pytest.hookimpl(tryfirst=True)
7+
def pytest_configure(config):
8+
TransitionTool.set_default_tool(EELST8N)

eest_tests/execution-spec-tests

Submodule execution-spec-tests added at 6cf5107

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ dependencies = [
2626
"ethereum-types>=0.2.1,<0.3",
2727
"ethereum-rlp>=0.1.4,<0.2",
2828
"cryptography>=45.0.1,<46",
29+
"ethereum-execution-spec-tests @ git+https://github.com/ethereum/execution-spec-tests@6cf5107cee0eae1c2d4dd6a5ef5bc729aea6c379",
30+
"ethereum-spec-evm-resolver @ git+https://github.com/petertdavies/ethereum-spec-evm-resolver",
2931
]
3032

3133
[tool.setuptools]
@@ -152,11 +154,11 @@ packages = [
152154

153155
[project.optional-dependencies]
154156
test = [
155-
"pytest>=7.4.0,<8",
157+
"pytest>=8,<9",
156158
"pytest-cov>=4.1.0,<5",
157159
"pytest-xdist>=3.3.1,<4",
158160
"GitPython>=3.1.0,<3.2",
159-
"filelock>=3.12.3,<3.13",
161+
"filelock>=3.15.1,<4",
160162
"requests",
161163
"requests-cache>=1.2.1,<2",
162164
]
@@ -195,6 +197,7 @@ ethereum-spec-sync = "ethereum_spec_tools.sync:main"
195197
ethereum-spec-new-fork = "ethereum_spec_tools.new_fork:main"
196198
ethereum-spec-patch = "ethereum_spec_tools.patch_tool:main"
197199
ethereum-spec-evm = "ethereum_spec_tools.evm_tools:main"
200+
ethereum-spec-fill = "cli.pytest_commands.fill:fill"
198201

199202
[project.entry-points."docc.plugins"]
200203
"ethereum_spec_tools.docc.discover" = "ethereum_spec_tools.docc:EthereumDiscover"
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
"""
2+
Implementation of the EELS T8N for execution-spec-tests.
3+
"""
4+
5+
import json
6+
import tempfile
7+
from io import StringIO
8+
from typing import Any, Dict, Optional
9+
10+
from ethereum_clis.clis.execution_specs import ExecutionSpecsExceptionMapper
11+
from ethereum_clis.file_utils import dump_files_to_directory
12+
from ethereum_clis.transition_tool import TransitionTool, model_dump_config
13+
from ethereum_clis.types import TransitionToolOutput
14+
from ethereum_test_forks import Fork
15+
16+
import ethereum
17+
18+
from .. import create_parser
19+
from ..utils import get_supported_forks
20+
from . import T8N
21+
22+
23+
class EELST8N(TransitionTool):
24+
"""Implementation of the EELS T8N for execution-spec-tests."""
25+
26+
def __init__(
27+
self,
28+
*,
29+
trace: bool = False,
30+
):
31+
"""Initialize the EELS Transition Tool interface."""
32+
self.exception_mapper = ExecutionSpecsExceptionMapper()
33+
self.trace = trace
34+
self._info_metadata: Optional[Dict[str, Any]] = {}
35+
36+
def version(self) -> str:
37+
"""Version of the t8n tool."""
38+
return ethereum.__version__
39+
40+
def is_fork_supported(self, fork: Fork) -> bool:
41+
"""Return True if the fork is supported by the tool."""
42+
return fork.transition_tool_name() in get_supported_forks()
43+
44+
def evaluate(
45+
self,
46+
*,
47+
transition_tool_data: TransitionTool.TransitionToolData,
48+
debug_output_path: str = "",
49+
slow_request: bool = False, # noqa: U100, F841
50+
) -> TransitionToolOutput:
51+
"""
52+
Evaluate using the EELS T8N entry point.
53+
"""
54+
request_data = transition_tool_data.get_request_data()
55+
request_data_json = request_data.model_dump(
56+
mode="json", **model_dump_config
57+
)
58+
59+
t8n_args = [
60+
"t8n",
61+
"--input.alloc=stdin",
62+
"--input.env=stdin",
63+
"--input.txs=stdin",
64+
"--output.result=stdout",
65+
"--output.body=stdout",
66+
"--output.alloc=stdout",
67+
f"--state.fork={request_data_json['state']['fork']}",
68+
f"--state.chainid={request_data_json['state']['chainid']}",
69+
f"--state.reward={request_data_json['state']['reward']}",
70+
]
71+
72+
if transition_tool_data.state_test:
73+
t8n_args.append("--state-test")
74+
75+
temp_dir = tempfile.TemporaryDirectory()
76+
if self.trace:
77+
t8n_args.extend(
78+
[
79+
"--trace",
80+
"--trace.memory",
81+
"--trace.returndata",
82+
f"--output.basedir={temp_dir.name}",
83+
]
84+
)
85+
86+
parser = create_parser()
87+
t8n_options = parser.parse_args(t8n_args)
88+
89+
out_stream = StringIO()
90+
91+
in_stream = StringIO(json.dumps(request_data_json["input"]))
92+
93+
t8n = T8N(t8n_options, out_stream, in_stream)
94+
t8n.run()
95+
96+
output_dict = json.loads(out_stream.getvalue())
97+
output: TransitionToolOutput = TransitionToolOutput.model_validate(
98+
output_dict, context={"exception_mapper": self.exception_mapper}
99+
)
100+
101+
if debug_output_path:
102+
dump_files_to_directory(
103+
debug_output_path,
104+
{
105+
"input/alloc.json": request_data.input.alloc,
106+
"input/env.json": request_data.input.env,
107+
"input/txs.json": [
108+
tx.model_dump(mode="json", **model_dump_config)
109+
for tx in request_data.input.txs
110+
],
111+
},
112+
)
113+
114+
dump_files_to_directory(
115+
debug_output_path,
116+
{
117+
"output/alloc.json": output.alloc,
118+
"output/result.json": output.result,
119+
},
120+
)
121+
122+
if self.trace:
123+
self.collect_traces(
124+
output.result.receipts, temp_dir, debug_output_path
125+
)
126+
temp_dir.cleanup()
127+
128+
return output

tox.ini

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
min_version = 2.0
3-
envlist = py3,pypy3,static
3+
envlist = py3,pypy3,py3_eest,static
44

55
[testenv:static]
66
extras =
@@ -30,22 +30,52 @@ commands =
3030
--no-cov-on-fail \
3131
--cov-branch \
3232
--ignore-glob='tests/fixtures/*' \
33-
--basetemp="{temp_dir}/pytest"
33+
--basetemp="{temp_dir}/pytest" \
34+
tests
35+
36+
[testenv:py3_eest]
37+
extras =
38+
test
39+
commands =
40+
fill \
41+
-m "not slow and not zkevm and not benchmark" \
42+
-n auto --maxprocesses 6 \
43+
--basetemp="{temp_dir}/pytest" \
44+
--clean \
45+
eest_tests/execution-spec-tests/tests
46+
fill \
47+
-m "not slow and not zkevm and not benchmark" \
48+
-n auto --maxprocesses 6 \
49+
--basetemp="{temp_dir}/pytest" \
50+
--clean \
51+
--fork Osaka \
52+
eest_tests/execution-spec-tests/tests/osaka
3453

3554
[testenv:pypy3]
3655
extras =
3756
test
3857
passenv =
3958
PYPY_GC_MAX
4059
commands =
41-
pytest \
60+
fill \
4261
--tb=no \
4362
--show-capture=no \
4463
--disable-warnings \
45-
-m "not slow" \
46-
-n auto --maxprocesses 5 \
47-
--ignore-glob='tests/fixtures/*' \
48-
--basetemp="{temp_dir}/pytest"
64+
-m "not slow and not zkevm and not benchmark" \
65+
-n auto --maxprocesses 3 \
66+
--basetemp="{temp_dir}/pytest" \
67+
--clean \
68+
eest_tests/execution-spec-tests/tests
69+
fill \
70+
--tb=no \
71+
--show-capture=no \
72+
--disable-warnings \
73+
-m "not slow and not zkevm and not benchmark" \
74+
-n auto --maxprocesses 3 \
75+
--basetemp="{temp_dir}/pytest" \
76+
--clean \
77+
--fork Osaka \
78+
eest_tests/execution-spec-tests/tests/osaka
4979

5080
[testenv:optimized]
5181
extras =
@@ -60,7 +90,8 @@ commands =
6090
--ignore-glob='tests/fixtures/*' \
6191
--ignore-glob='tests/test_t8n.py' \
6292
--basetemp="{temp_dir}/pytest" \
63-
--optimized
93+
--optimized \
94+
tests
6495

6596
[testenv:doc]
6697
basepython = python3

vulture_whitelist.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
)
1111
from ethereum_spec_tools.evm_tools.t8n.env import Ommer
1212
from ethereum_spec_tools.evm_tools.t8n.evm_trace import Trace, FinalTrace
13+
from ethereum_spec_tools.evm_tools.t8n.transition_tool import EELST8N
1314
from ethereum_spec_tools.lint.lints.glacier_forks_hygiene import (
1415
GlacierForksHygiene,
1516
)
@@ -54,6 +55,13 @@
5455
_EvmToolHandler.do_POST
5556
_EvmToolHandler.log_request
5657

58+
# src/ethereum_spec_tools/evm_tools/transition_tool.py
59+
EELST8N
60+
EELST8N._info_metadata
61+
EELST8N.version
62+
EELST8N.is_fork_supported
63+
EELST8N.evaluate
64+
5765
# src/ethereum_spec_tools/loaders/fixture_loader.py
5866
Load._network
5967

whitelist.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,4 +494,7 @@ SECP256R1P
494494
secp256r1
495495
sig
496496

497-
CLZ
497+
CLZ
498+
EELST8N
499+
clis
500+
T8

0 commit comments

Comments
 (0)