Skip to content

Commit edf2e33

Browse files
committed
feat(consume): add initial implementation of consume enginex
1 parent 9f91081 commit edf2e33

File tree

11 files changed

+689
-37
lines changed

11 files changed

+689
-37
lines changed

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ classifiers = [
2020
]
2121
dependencies = [
2222
"click>=8.1.0,<9",
23-
"hive.py @ git+https://github.com/marioevz/hive.py",
23+
"ethereum-execution==1.17.0rc6.dev1",
24+
"hive-py",
2425
"ethereum-spec-evm-resolver",
2526
"gitpython>=3.1.31,<4",
2627
"PyJWT>=2.3.0,<3",
@@ -148,3 +149,4 @@ ignore-words-list = "ingenuous"
148149

149150
[tool.uv.sources]
150151
ethereum-spec-evm-resolver = { git = "https://github.com/spencer-tb/ethereum-spec-evm-resolver", rev = "ee273e7344e24a739ebfbf0ea1f758530c4d032b" }
152+
hive-py = { git = "https://github.com/marioevz/hive.py", rev = "582703e2f94b4d5e61ae495d90d684852c87a580" }

src/cli/pytest_commands/consume.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,18 @@ def create_executions(self, pytest_args: List[str]) -> List[PytestExecution]:
4949
]
5050

5151

52-
def get_command_paths(command_name: str, is_hive: bool) -> List[Path]:
52+
def get_command_paths(command_name: str) -> List[Path]:
5353
"""Determine the command paths based on the command name and hive flag."""
5454
base_path = Path("src/pytest_plugins/consume")
5555
if command_name == "hive":
5656
commands = ["rlp", "engine"]
5757
command_paths = [
5858
base_path / "simulators" / "hive_tests" / f"test_via_{cmd}.py" for cmd in commands
5959
]
60-
elif command_name in ["engine", "rlp"]:
61-
command_paths = [base_path / "simulators" / "hive_tests" / f"test_via_{command_name}.py"]
60+
elif command_name in ["engine", "engine-reorg", "engine_reorg"]:
61+
command_paths = [base_path / "simulators" / "hive_tests" / "test_via_engine.py"]
62+
elif command_name == "rlp":
63+
command_paths = [base_path / "simulators" / "hive_tests" / "test_via_rlp.py"]
6264
elif command_name == "direct":
6365
command_paths = [base_path / "direct" / "test_via_direct.py"]
6466
else:
@@ -78,7 +80,7 @@ def consume_command(is_hive: bool = False) -> Callable[[Callable[..., Any]], cli
7880
def decorator(func: Callable[..., Any]) -> click.Command:
7981
command_name = func.__name__
8082
command_help = func.__doc__
81-
command_paths = get_command_paths(command_name, is_hive)
83+
command_paths = get_command_paths(command_name)
8284

8385
@consume.command(
8486
name=command_name,
@@ -114,17 +116,33 @@ def engine() -> None:
114116
pass
115117

116118

119+
@consume.command(
120+
name="engine-reorg",
121+
help="Client consumes via the Engine API with reorg fixtures.",
122+
context_settings={"ignore_unknown_options": True},
123+
)
124+
@common_pytest_options
125+
def engine_reorg(
126+
pytest_args: List[str], help_flag: bool = False, pytest_help_flag: bool = False
127+
) -> None:
128+
"""Client consumes via the Engine API with reorg fixtures."""
129+
command_name = "engine_reorg" # Use underscore for internal logic
130+
command_paths = get_command_paths(command_name)
131+
consume_cmd = ConsumeCommand(command_paths, is_hive=True, command_name=command_name)
132+
consume_cmd.execute(list(pytest_args))
133+
134+
117135
@consume_command(is_hive=True)
118136
def hive() -> None:
119-
"""Client consumes via all available hive methods (rlp, engine)."""
137+
"""Client consumes via rlp & engine hive methods."""
120138
pass
121139

122140

123141
@consume.command(
124142
context_settings={"ignore_unknown_options": True},
125143
)
126144
@common_pytest_options
127-
def cache(pytest_args: List[str], **kwargs) -> None:
145+
def cache(pytest_args: List[str], help_flag: bool = False, pytest_help_flag: bool = False) -> None:
128146
"""Consume command to cache test fixtures."""
129-
cache_cmd = ConsumeCommand([], is_hive=False)
147+
cache_cmd = ConsumeCommand([], is_hive=False, command_name="cache")
130148
cache_cmd.execute(list(pytest_args))

src/cli/pytest_commands/processors.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ def process_args(self, args: List[str]) -> List[str]:
107107

108108
if self.command_name == "engine":
109109
modified_args.extend(["-p", "pytest_plugins.consume.simulators.engine.conftest"])
110+
elif self.command_name == "engine_reorg":
111+
modified_args.extend(["-p", "pytest_plugins.consume.simulators.engine_reorg.conftest"])
110112
elif self.command_name == "rlp":
111113
modified_args.extend(["-p", "pytest_plugins.consume.simulators.rlp.conftest"])
112114
else:

src/pytest_plugins/consume/consume.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,8 @@ def pytest_generate_tests(metafunc):
425425
test_case,
426426
id=test_case.id,
427427
marks=[getattr(pytest.mark, m) for m in fork_markers]
428-
+ [getattr(pytest.mark, test_case.format.format_name)],
428+
+ [getattr(pytest.mark, test_case.format.format_name)]
429+
+ [pytest.mark.xdist_group(name=test_case.pre_hash)],
429430
)
430431
param_list.append(param)
431432

src/pytest_plugins/consume/simulators/engine/conftest.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
"""
2-
Pytest fixtures for the `consume engine` simulator.
3-
4-
Configures the hive back-end & EL clients for each individual test execution.
5-
"""
1+
"""Pytest plugin for the `consume engine` simulator."""
62

73
import io
84
from typing import Mapping
@@ -28,6 +24,18 @@ def pytest_configure(config):
2824
config._supported_fixture_formats = [BlockchainEngineFixture.format_name]
2925

3026

27+
@pytest.fixture(scope="module")
28+
def test_suite_name() -> str:
29+
"""The name of the hive test suite used in this simulator."""
30+
return "eest/consume-engine"
31+
32+
33+
@pytest.fixture(scope="module")
34+
def test_suite_description() -> str:
35+
"""The description of the hive test suite used in this simulator."""
36+
return "Execute blockchain tests against clients using the Engine API."
37+
38+
3139
@pytest.fixture(scope="function")
3240
def engine_rpc(client: Client, client_exception_mapper: ExceptionMapper | None) -> EngineRPC:
3341
"""Initialize engine RPC client for the execution client under test."""
@@ -41,18 +49,6 @@ def engine_rpc(client: Client, client_exception_mapper: ExceptionMapper | None)
4149
return EngineRPC(f"http://{client.ip}:8551")
4250

4351

44-
@pytest.fixture(scope="module")
45-
def test_suite_name() -> str:
46-
"""The name of the hive test suite used in this simulator."""
47-
return "eest/consume-engine"
48-
49-
50-
@pytest.fixture(scope="module")
51-
def test_suite_description() -> str:
52-
"""The description of the hive test suite used in this simulator."""
53-
return "Execute blockchain tests against clients using the Engine API."
54-
55-
5652
@pytest.fixture(scope="function")
5753
def client_files(buffered_genesis: io.BufferedReader) -> Mapping[str, io.BufferedReader]:
5854
"""Define the files that hive will start the client with."""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Consume Engine test functions."""
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""
2+
Pytest fixtures for the `consume engine-reorg` simulator.
3+
4+
Configures the hive back-end & EL clients for test execution with BlockchainEngineReorgFixtures.
5+
"""
6+
7+
import pytest
8+
from hive.client import Client
9+
10+
from ethereum_test_exceptions import ExceptionMapper
11+
from ethereum_test_fixtures import BlockchainEngineReorgFixture
12+
from ethereum_test_rpc import EngineRPC
13+
14+
pytest_plugins = (
15+
"pytest_plugins.consume.simulators.base",
16+
"pytest_plugins.consume.simulators.multi_test_client",
17+
"pytest_plugins.consume.simulators.test_case_description",
18+
"pytest_plugins.consume.simulators.timing_data",
19+
"pytest_plugins.consume.simulators.exceptions",
20+
)
21+
22+
23+
def pytest_configure(config):
24+
"""Set the supported fixture formats for the engine simulator."""
25+
config._supported_fixture_formats = [BlockchainEngineReorgFixture.format_name]
26+
27+
28+
@pytest.fixture(scope="module")
29+
def test_suite_name() -> str:
30+
"""The name of the hive test suite used in this simulator."""
31+
return "eest/consume-engine-reorg"
32+
33+
34+
@pytest.fixture(scope="module")
35+
def test_suite_description() -> str:
36+
"""The description of the hive test suite used in this simulator."""
37+
return (
38+
"Execute blockchain tests against clients using the Engine API and shared clients "
39+
"using engine reorg fixtures."
40+
)
41+
42+
43+
@pytest.fixture(scope="function")
44+
def engine_rpc(client: Client, client_exception_mapper: ExceptionMapper | None) -> EngineRPC:
45+
"""Initialize engine RPC client for the execution client under test."""
46+
if client_exception_mapper:
47+
return EngineRPC(
48+
f"http://{client.ip}:8551",
49+
response_validation_context={
50+
"exception_mapper": client_exception_mapper,
51+
},
52+
)
53+
return EngineRPC(f"http://{client.ip}:8551")

0 commit comments

Comments
 (0)