Skip to content

Commit c73f685

Browse files
committed
feat(cli,specs): Pass blob schedule to t8n
1 parent a35652a commit c73f685

File tree

6 files changed

+70
-25
lines changed

6 files changed

+70
-25
lines changed

src/ethereum_clis/clis/besu.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import requests
1313

14+
from ethereum_test_base_types import BlobSchedule
1415
from ethereum_test_exceptions import (
1516
EOFException,
1617
ExceptionMapper,
@@ -101,8 +102,9 @@ def evaluate(
101102
txs: List[Transaction],
102103
env: Environment,
103104
fork: Fork,
104-
chain_id: int = 1,
105-
reward: int = 0,
105+
chain_id: int,
106+
reward: int,
107+
blob_schedule: BlobSchedule | None = None,
106108
eips: Optional[List[int]] = None,
107109
debug_output_path: str = "",
108110
state_test: bool = False,

src/ethereum_clis/tests/test_execution_specs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ def test_evm_t8n(
170170
txs=txs,
171171
env=env,
172172
fork=Berlin,
173+
chain_id=1,
174+
reward=0,
175+
blob_schedule=Berlin.blob_schedule(),
173176
)
174177
assert to_json(t8n_output.alloc) == expected.get("alloc")
175178
if isinstance(t8n, ExecutionSpecsTransitionTool):

src/ethereum_clis/transition_tool.py

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import textwrap
99
import time
1010
from abc import abstractmethod
11-
from dataclasses import dataclass, field
11+
from dataclasses import dataclass
1212
from pathlib import Path
1313
from typing import Any, Dict, List, Mapping, Optional, Type
1414
from urllib.parse import urlencode
@@ -17,14 +17,21 @@
1717
from requests.exceptions import ConnectionError as RequestsConnectionError
1818
from requests_unixsocket import Session # type: ignore
1919

20+
from ethereum_test_base_types import BlobSchedule
2021
from ethereum_test_exceptions import ExceptionMapper
2122
from ethereum_test_fixtures import FixtureFormat, FixtureVerifier
2223
from ethereum_test_forks import Fork
2324
from ethereum_test_types import Alloc, Environment, Transaction
2425

2526
from .ethereum_cli import EthereumCLI
2627
from .file_utils import dump_files_to_directory, write_json_file
27-
from .types import TransactionReceipt, TransitionToolInput, TransitionToolOutput
28+
from .types import (
29+
TransactionReceipt,
30+
TransitionToolInput,
31+
TransitionToolOutput,
32+
TransitionToolPost,
33+
TransitionToolState,
34+
)
2835

2936
model_dump_config: Mapping = {"by_alias": True, "exclude_none": True}
3037

@@ -130,9 +137,10 @@ class TransitionToolData:
130137
txs: List[Transaction]
131138
env: Environment
132139
fork_name: str
133-
chain_id: int = field(default=1)
134-
reward: int = field(default=0)
135-
state_test: bool = field(default=False)
140+
chain_id: int
141+
reward: int
142+
blob_schedule: BlobSchedule | None
143+
state_test: bool
136144

137145
def to_input(self) -> TransitionToolInput:
138146
"""Convert the data to a TransactionToolInput object."""
@@ -142,6 +150,18 @@ def to_input(self) -> TransitionToolInput:
142150
env=self.env,
143151
)
144152

153+
def get_post(self) -> TransitionToolPost:
154+
"""Convert the data to a TransitionToolState object."""
155+
return TransitionToolPost(
156+
state=TransitionToolState(
157+
fork=self.fork_name,
158+
chain_id=self.chain_id,
159+
reward=self.reward,
160+
blob_schedule=self.blob_schedule,
161+
),
162+
input=self.to_input(),
163+
)
164+
145165
def _evaluate_filesystem(
146166
self,
147167
*,
@@ -298,37 +318,29 @@ def _evaluate_server(
298318
timeout: int,
299319
) -> TransitionToolOutput:
300320
"""Execute the transition tool sending inputs and outputs via a server."""
301-
input_contents = t8n_data.to_input()
302-
input_json = input_contents.model_dump(mode="json", **model_dump_config)
303-
post_data = {
304-
"state": {
305-
"fork": t8n_data.fork_name,
306-
"chainid": t8n_data.chain_id,
307-
"reward": t8n_data.reward,
308-
},
309-
"input": input_json,
310-
}
321+
post_data = t8n_data.get_post()
322+
post_json = post_data.model_dump(mode="json", **model_dump_config)
311323

312324
if debug_output_path:
313325
request_info = (
314326
f"Server URL: {self.server_url}\n\n"
315-
f"Request Data:\n{json.dumps(post_data, indent=2)}\n"
327+
f"Request Data:\n{json.dumps(post_json, indent=2)}\n"
316328
)
317329
dump_files_to_directory(
318330
debug_output_path,
319331
{
320-
"input/alloc.json": input_contents.alloc,
321-
"input/env.json": input_contents.env,
332+
"input/alloc.json": post_data.input.alloc,
333+
"input/env.json": post_data.input.env,
322334
"input/txs.json": [
323335
tx.model_dump(mode="json", **model_dump_config)
324-
for tx in input_contents.txs
336+
for tx in post_data.input.txs
325337
],
326338
"request_info.txt": request_info,
327339
},
328340
)
329341

330342
response = self._server_post(
331-
data=post_data, url_args=self._generate_post_args(t8n_data), timeout=timeout
343+
data=post_json, url_args=self._generate_post_args(t8n_data), timeout=timeout
332344
)
333345
output: TransitionToolOutput = TransitionToolOutput.model_validate(response.json())
334346

@@ -465,8 +477,9 @@ def evaluate(
465477
txs: List[Transaction],
466478
env: Environment,
467479
fork: Fork,
468-
chain_id: int = 1,
469-
reward: int = 0,
480+
chain_id: int,
481+
reward: int,
482+
blob_schedule: BlobSchedule | None,
470483
eips: Optional[List[int]] = None,
471484
debug_output_path: str = "",
472485
state_test: bool = False,
@@ -493,6 +506,7 @@ def evaluate(
493506
fork_name=fork_name,
494507
chain_id=chain_id,
495508
reward=reward,
509+
blob_schedule=blob_schedule,
496510
state_test=state_test,
497511
)
498512

src/ethereum_clis/types.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44

55
from pydantic import Field
66

7-
from ethereum_test_base_types import Address, Bloom, Bytes, CamelModel, Hash, HexNumber
7+
from ethereum_test_base_types import (
8+
Address,
9+
BlobSchedule,
10+
Bloom,
11+
Bytes,
12+
CamelModel,
13+
Hash,
14+
HexNumber,
15+
)
816
from ethereum_test_types import Alloc, Environment, Transaction
917

1018

@@ -93,3 +101,19 @@ class TransitionToolOutput(CamelModel):
93101
alloc: Alloc
94102
result: Result
95103
body: Bytes | None = None
104+
105+
106+
class TransitionToolState(CamelModel):
107+
"""Transition tool state."""
108+
109+
fork: str
110+
chain_id: int = Field(..., alias="chainid")
111+
reward: int
112+
blob_schedule: BlobSchedule | None
113+
114+
115+
class TransitionToolPost(CamelModel):
116+
"""Transition tool post."""
117+
118+
state: TransitionToolState
119+
input: TransitionToolInput

src/ethereum_test_specs/blockchain.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ def generate_block_data(
386386
fork=fork,
387387
chain_id=self.chain_id,
388388
reward=fork.get_reward(env.number, env.timestamp),
389+
blob_schedule=fork.blob_schedule(),
389390
eips=eips,
390391
debug_output_path=self.get_next_transition_tool_output_path(),
391392
slow_request=slow,

src/ethereum_test_specs/state.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def make_state_test_fixture(
135135
fork=fork,
136136
chain_id=self.chain_id,
137137
reward=0, # Reward on state tests is always zero
138+
blob_schedule=fork.blob_schedule(),
138139
eips=eips,
139140
debug_output_path=self.get_next_transition_tool_output_path(),
140141
state_test=True,

0 commit comments

Comments
 (0)