-
Notifications
You must be signed in to change notification settings - Fork 450
feat(test-cli): Add support for testing block building via simulator #2679
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
Open
fselmo
wants to merge
5
commits into
ethereum:forks/amsterdam
Choose a base branch
from
fselmo:feat/block-building-tests
base: forks/amsterdam
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aa4fd31
feat(test-cli): Add support for testing block building via simulator
fselmo 679ff43
chore: pretty diff BALs on errors
fselmo 795a4f9
refactor(test): cleanup based on comments on PR #2679
fselmo 7a2db76
chore: cleanup from comments on PR #2679
fselmo ff28369
chore: initial docs for build-block
fselmo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/testing/src/execution_testing/cli/pytest_commands/build_block.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| """CLI entry point for the `build-block` pytest-based command.""" | ||
|
|
||
| from pathlib import Path | ||
| from typing import Any, List | ||
|
|
||
| import click | ||
|
|
||
| from .base import PytestCommand, common_pytest_options | ||
| from .processors import ( | ||
| ConsumeCommandProcessor, | ||
| HelpFlagsProcessor, | ||
| HiveEnvironmentProcessor, | ||
| ) | ||
|
|
||
|
|
||
| def create_build_block_command() -> PytestCommand: | ||
| """Initialize the build-block command with paths and processors.""" | ||
| base_path = Path("cli/pytest_commands/plugins/consume") | ||
| command_logic_test_paths = [ | ||
| base_path / "simulators" / "simulator_logic" / "test_via_build.py" | ||
| ] | ||
| return PytestCommand( | ||
| config_file="pytest-consume.ini", | ||
| argument_processors=[ | ||
| HelpFlagsProcessor("consume"), | ||
| HiveEnvironmentProcessor(command_name="build_block"), | ||
| ConsumeCommandProcessor(is_hive=True), | ||
| ], | ||
| command_logic_test_paths=command_logic_test_paths, | ||
| ) | ||
|
|
||
|
|
||
| @click.command( | ||
| name="build-block", | ||
| context_settings={"ignore_unknown_options": True}, | ||
| ) | ||
| @common_pytest_options | ||
| def build_block(pytest_args: List[str], **kwargs: Any) -> None: | ||
| """Test block building via testing_buildBlockV1.""" | ||
| del kwargs | ||
|
|
||
| cmd = create_build_block_command() | ||
| cmd.execute(list(pytest_args)) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
.../execution_testing/cli/pytest_commands/plugins/consume/simulators/build_block/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Pytest configuration for the build-block simulator.""" |
66 changes: 66 additions & 0 deletions
66
.../execution_testing/cli/pytest_commands/plugins/consume/simulators/build_block/conftest.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| """ | ||
| Pytest fixtures for the `build-block` simulator. | ||
|
|
||
| Configures the hive back-end & EL clients for block building correctness | ||
| testing via the ``testing_buildBlockV1`` endpoint. | ||
| """ | ||
|
|
||
| import io | ||
| from typing import Mapping | ||
|
|
||
| import pytest | ||
| from hive.client import Client | ||
|
|
||
| from execution_testing.fixtures import BlockchainEngineFixture | ||
| from execution_testing.fixtures.blockchain import FixtureHeader | ||
| from execution_testing.rpc import TestingRPC | ||
|
|
||
| pytest_plugins = ( | ||
| "execution_testing.cli.pytest_commands.plugins.pytest_hive.pytest_hive", | ||
| "execution_testing.cli.pytest_commands.plugins.consume.simulators.base", | ||
| "execution_testing.cli.pytest_commands.plugins.consume.simulators.single_test_client", | ||
| "execution_testing.cli.pytest_commands.plugins.consume.simulators.test_case_description", | ||
| "execution_testing.cli.pytest_commands.plugins.consume.simulators.timing_data", | ||
| "execution_testing.cli.pytest_commands.plugins.consume.simulators.exceptions", | ||
| "execution_testing.cli.pytest_commands.plugins.consume.simulators.engine_api", | ||
| ) | ||
|
|
||
|
|
||
| def pytest_configure(config: pytest.Config) -> None: | ||
| """Set the supported fixture formats for the build-block simulator.""" | ||
| config.supported_fixture_formats = [BlockchainEngineFixture] # type: ignore[attr-defined] | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def test_suite_name() -> str: | ||
| """The name of the hive test suite used in this simulator.""" | ||
| return "eels/build-block" | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def test_suite_description() -> str: | ||
| """The description of the hive test suite used in this simulator.""" | ||
| return ( | ||
| "Test block building correctness via the " | ||
| "testing_buildBlockV1 endpoint." | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| def client_files( | ||
| buffered_genesis: io.BufferedReader, | ||
| ) -> Mapping[str, io.BufferedReader]: | ||
| """Define the files that hive will start the client with.""" | ||
| return {"/genesis.json": buffered_genesis} | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| def genesis_header(fixture: BlockchainEngineFixture) -> FixtureHeader: | ||
| """Provide the genesis header from the fixture.""" | ||
| return fixture.genesis | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| def testing_rpc(client: Client) -> TestingRPC: | ||
| """Initialize Testing RPC client for the execution client under test.""" | ||
| return TestingRPC(f"http://{client.ip}:8545") |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This command does use the
testing_buildBlockV1endpoint, but I think it's rather close to aconsumesimulator (it still consumes a fixture) so I wondered if it should be aconsumesub-command?I.e., something like
uv run consume build-block.Then the simulator in hive would be
eels/consume-build-block.Imo, when we add a command to fill tests using the
testing_buildBlockV1in the future, that command should be the newbuildorbuild-blockcommand. Wdyt?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I thought about this a bit but it seems like the opposite of consume imo. It receives a request to build a block and then is validated against what's in the fixture, rather than sending the payloads as they are (consuming) and then validating against some post state after.
I'm not one to argue semantics tbh, all I care is that the functionality is there. I'd love to get ideas from the team and settle on something but the reason I went with a new top-level command is that this feels entirely different to me. I can see the argument since they share a lot of things though. Happy to go either way here.