Skip to content

Use TransitionTool.default_tool #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 7 additions & 25 deletions src/ethereum_clis/clis/besu.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@
import tempfile
import textwrap
from pathlib import Path
from typing import ClassVar, Dict, List, Optional
from typing import ClassVar, Dict, Optional

import requests # type: ignore

from ethereum_test_base_types import BlobSchedule
from ethereum_test_exceptions import (
BlockException,
ExceptionBase,
ExceptionMapper,
TransactionException,
)
from ethereum_test_forks import Fork
from ethereum_test_types import Alloc, Environment, Transaction

from ..transition_tool import TransitionTool, dump_files_to_directory, model_dump_config
from ..types import TransitionToolInput, TransitionToolOutput
from ..types import TransitionToolOutput


class BesuTransitionTool(TransitionTool):
Expand Down Expand Up @@ -98,36 +96,20 @@ def shutdown(self):
def evaluate(
self,
*,
alloc: Alloc,
txs: List[Transaction],
env: Environment,
fork: Fork,
chain_id: int,
reward: int,
blob_schedule: BlobSchedule | None = None,
transition_tool_data: TransitionTool.TransitionToolData,
debug_output_path: str = "",
state_test: bool = False,
slow_request: bool = False,
) -> TransitionToolOutput:
"""Execute `evm t8n` with the specified arguments."""
if not self.process:
self.start_server()

fork_name = fork.transition_tool_name(
block_number=env.number,
timestamp=env.timestamp,
)

input_json = TransitionToolInput(
alloc=alloc,
txs=txs,
env=env,
).model_dump(mode="json", **model_dump_config)
input_json = transition_tool_data.to_input().model_dump(mode="json", **model_dump_config)

state_json = {
"fork": fork_name,
"chainid": chain_id,
"reward": reward,
"fork": transition_tool_data.fork_name,
"chainid": transition_tool_data.chain_id,
"reward": transition_tool_data.reward,
}

post_data = {"state": state_json, "input": input_json}
Expand Down
139 changes: 0 additions & 139 deletions src/ethereum_clis/clis/eels_t8n.py

This file was deleted.

16 changes: 9 additions & 7 deletions src/ethereum_clis/tests/test_execution_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,15 @@ def test_evm_t8n(
expected = json.load(exp)

t8n_output = default_t8n.evaluate(
alloc=alloc,
txs=txs,
env=env,
fork=Berlin,
chain_id=1,
reward=0,
blob_schedule=Berlin.blob_schedule(),
transition_tool_data=TransitionTool.TransitionToolData(
alloc=alloc,
txs=txs,
env=env,
fork=Berlin,
chain_id=1,
reward=0,
blob_schedule=Berlin.blob_schedule(),
),
)
assert to_json(t8n_output.alloc) == expected.get("alloc")
if isinstance(default_t8n, ExecutionSpecsTransitionTool):
Expand Down
51 changes: 21 additions & 30 deletions src/ethereum_clis/transition_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,24 @@ class TransitionToolData:
alloc: Alloc
txs: List[Transaction]
env: Environment
fork_name: str
fork: Fork
chain_id: int
reward: int
blob_schedule: BlobSchedule | None
state_test: bool
state_test: bool = False

@property
def fork_name(self) -> str:
"""Return the fork name."""
return self.fork.transition_tool_name(
block_number=self.env.number,
timestamp=self.env.timestamp,
)

def __post_init__(self):
"""Modify the reward if the environment number is 0."""
if self.env.number == 0:
self.reward = -1

def to_input(self) -> TransitionToolInput:
"""Convert the data to a TransactionToolInput object."""
Expand Down Expand Up @@ -493,15 +506,8 @@ def dump_debug_stream(
def evaluate(
self,
*,
alloc: Alloc,
txs: List[Transaction],
env: Environment,
fork: Fork,
chain_id: int,
reward: int,
blob_schedule: BlobSchedule | None,
transition_tool_data: TransitionToolData,
debug_output_path: str = "",
state_test: bool = False,
slow_request: bool = False,
) -> TransitionToolOutput:
"""
Expand All @@ -510,36 +516,21 @@ def evaluate(
If a client's `t8n` tool varies from the default behavior, this method
can be overridden.
"""
fork_name = fork.transition_tool_name(
block_number=env.number,
timestamp=env.timestamp,
)
if env.number == 0:
reward = -1
t8n_data = self.TransitionToolData(
alloc=alloc,
txs=txs,
env=env,
fork_name=fork_name,
chain_id=chain_id,
reward=reward,
blob_schedule=blob_schedule,
state_test=state_test,
)

if self.t8n_use_server:
if not self.process:
self.start_server()
return self._evaluate_server(
t8n_data=t8n_data,
t8n_data=transition_tool_data,
debug_output_path=debug_output_path,
timeout=SLOW_REQUEST_TIMEOUT if slow_request else NORMAL_SERVER_TIMEOUT,
)

if self.t8n_use_stream:
return self._evaluate_stream(t8n_data=t8n_data, debug_output_path=debug_output_path)
return self._evaluate_stream(
t8n_data=transition_tool_data, debug_output_path=debug_output_path
)

return self._evaluate_filesystem(
t8n_data=t8n_data,
t8n_data=transition_tool_data,
debug_output_path=debug_output_path,
)
16 changes: 9 additions & 7 deletions src/ethereum_test_specs/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,15 @@ def generate_block_data(
)

transition_tool_output = t8n.evaluate(
alloc=previous_alloc,
txs=txs,
env=env,
fork=fork,
chain_id=self.chain_id,
reward=fork.get_reward(env.number, env.timestamp),
blob_schedule=fork.blob_schedule(),
transition_tool_data=TransitionTool.TransitionToolData(
alloc=previous_alloc,
txs=txs,
env=env,
fork=fork,
chain_id=self.chain_id,
reward=fork.get_reward(env.number, env.timestamp),
blob_schedule=fork.blob_schedule(),
),
debug_output_path=self.get_next_transition_tool_output_path(),
slow_request=self.is_tx_gas_heavy_test(),
)
Expand Down
18 changes: 10 additions & 8 deletions src/ethereum_test_specs/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,17 @@ def make_state_test_fixture(
raise Exception(f"Empty accounts in pre state: {empty_accounts}")

transition_tool_output = t8n.evaluate(
alloc=pre_alloc,
txs=[tx],
env=env,
fork=fork,
chain_id=self.chain_id,
reward=0, # Reward on state tests is always zero
blob_schedule=fork.blob_schedule(),
transition_tool_data=TransitionTool.TransitionToolData(
alloc=pre_alloc,
txs=[tx],
env=env,
fork=fork,
chain_id=self.chain_id,
reward=0, # Reward on state tests is always zero
blob_schedule=fork.blob_schedule(),
state_test=True,
),
debug_output_path=self.get_next_transition_tool_output_path(),
state_test=True,
slow_request=self.is_tx_gas_heavy_test(),
)

Expand Down
Loading