Skip to content

Commit b456efa

Browse files
committed
create EELS TransitionTool subclass
1 parent 510d922 commit b456efa

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

conftest.py

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

whitelist.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,3 +475,6 @@ eoa
475475
blockchain
476476
listdir
477477
precompiles
478+
EELST8N
479+
clis
480+
T8

0 commit comments

Comments
 (0)