Skip to content
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

feat(clis/transition_tool): Pass state_test to transition tool if supported #943

Merged
merged 4 commits into from
Nov 7, 2024
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
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Test fixtures for use by clients are available for each release on the [Github r

- ✨ Fill test fixtures using EELS by default. EEST now uses the [`ethereum-specs-evm-resolver`](https://github.com/petertdavies/ethereum-spec-evm-resolver) with the EELS daemon ([#792](https://github.com/ethereum/execution-spec-tests/pull/792)).
- 🔀 Move the `evm_transition_tool` package to `ethereum_clis` and derive the transition tool CL interfaces from a shared `EthereumCLI` class that can be reused for other sub-commands ([#894](https://github.com/ethereum/execution-spec-tests/pull/894)).
- ✨ Pass `state_test` property to T8N tools that support it (Only EELS at the time of merge) ([#943](https://github.com/ethereum/execution-spec-tests/pull/943)).

### 📋 Misc

Expand Down
1 change: 1 addition & 0 deletions src/ethereum_clis/clis/besu.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def evaluate(
reward: int = 0,
eips: Optional[List[int]] = None,
debug_output_path: str = "",
state_test: bool = False,
) -> TransitionToolOutput:
"""
Executes `evm t8n` with the specified arguments.
Expand Down
12 changes: 11 additions & 1 deletion src/ethereum_clis/clis/execution_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pathlib import Path
from re import compile
from tempfile import TemporaryDirectory
from typing import Optional
from typing import Dict, List, Optional

from ethereum_test_exceptions import (
EOFException,
Expand Down Expand Up @@ -111,6 +111,16 @@ def is_fork_supported(self, fork: Fork) -> bool:
"""
return (fork.transition_tool_name() + "\n") in self.help_string

def _generate_post_args(
self, t8n_data: TransitionTool.TransitionToolData
) -> Dict[str, List[str] | str]:
"""
Generate the arguments for the POST request to the t8n-server.

EELS T8N expects `--state-test` when running a state test.
"""
return {"arg": "--state-test"} if t8n_data.state_test else {}


class ExecutionSpecsExceptionMapper(ExceptionMapper):
"""
Expand Down
25 changes: 22 additions & 3 deletions src/ethereum_clis/transition_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any, Dict, List, Mapping, Optional, Type
from urllib.parse import urlencode

from requests import Response
from requests.exceptions import ConnectionError
Expand Down Expand Up @@ -147,6 +148,7 @@ class TransitionToolData:
fork_name: str
chain_id: int = field(default=1)
reward: int = field(default=0)
state_test: bool = field(default=False)

def to_input(self) -> TransitionToolInput:
"""
Expand Down Expand Up @@ -271,14 +273,23 @@ def _evaluate_filesystem(

return output

def _server_post(self, data: Dict[str, Any], retries: int = 10) -> Response:
def _server_post(
self,
data: Dict[str, Any],
url_args: Dict[str, List[str] | str] = {},
retries: int = 5,
) -> Response:
"""
Send a POST request to the t8n-server and return the response.
"""
post_delay = 0.1
while True:
try:
response = Session().post(self.server_url, json=data, timeout=20)
response = Session().post(
f"{self.server_url}?{urlencode(url_args, doseq=True)}",
json=data,
timeout=20,
)
break
except ConnectionError as e:
retries -= 1
Expand All @@ -294,6 +305,12 @@ def _server_post(self, data: Dict[str, Any], retries: int = 10) -> Response:
)
return response

def _generate_post_args(self, t8n_data: TransitionToolData) -> Dict[str, List[str] | str]:
"""
Generate the arguments for the POST request to the t8n-server.
"""
return {}

def _evaluate_server(
self,
*,
Expand Down Expand Up @@ -332,7 +349,7 @@ def _evaluate_server(
},
)

response = self._server_post(post_data)
response = self._server_post(data=post_data, url_args=self._generate_post_args(t8n_data))
output: TransitionToolOutput = TransitionToolOutput.model_validate(response.json())

if debug_output_path:
Expand Down Expand Up @@ -478,6 +495,7 @@ def evaluate(
reward: int = 0,
eips: Optional[List[int]] = None,
debug_output_path: str = "",
state_test: bool = False,
) -> TransitionToolOutput:
"""
Executes the relevant evaluate method as required by the `t8n` tool.
Expand All @@ -500,6 +518,7 @@ def evaluate(
fork_name=fork_name,
chain_id=chain_id,
reward=reward,
state_test=state_test,
)

if self.t8n_use_server:
Expand Down
4 changes: 3 additions & 1 deletion src/ethereum_test_specs/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any, Callable, ClassVar, Dict, Generator, List, Optional, Type

import pytest
from pydantic import Field

from ethereum_clis import TransitionTool
from ethereum_test_exceptions import EngineAPIError
Expand Down Expand Up @@ -39,7 +40,7 @@ class StateTest(BaseTest):
Filler type that tests transactions over the period of a single block.
"""

env: Environment
env: Environment = Field(default_factory=Environment)
pre: Alloc
post: Alloc
tx: Transaction
Expand Down Expand Up @@ -149,6 +150,7 @@ def make_state_test_fixture(
reward=0, # Reward on state tests is always zero
eips=eips,
debug_output_path=self.get_next_transition_tool_output_path(),
state_test=True,
)

try:
Expand Down
1 change: 1 addition & 0 deletions whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ discordapp
dockerdocs
docstring
docstrings
doseq
dunder
dup
EEST
Expand Down