Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
get_spec_format_for_item,
is_help_or_collectonly_mode,
labeled_format_parameter_set,
option_was_explicitly_set,
)
from ..spec_version_checker.spec_version_checker import EIPSpecTestItem
from .pre_alloc import Alloc
Expand Down Expand Up @@ -200,8 +201,9 @@ def pytest_configure(config: pytest.Config) -> None:
called before the pytest-html plugin's pytest_configure to ensure that
it uses the modified `htmlpath` option.
"""
# Modify the block gas limit if specified.
if config.getoption("transaction_gas_limit"):
# Keep execute-mode overrides working, but avoid rewriting the global
# default when this plugin is merely imported into nested pytest sessions.
if option_was_explicitly_set(config, "--transaction-gas-limit"):
EnvironmentDefaults.gas_limit = config.getoption(
"transaction_gas_limit"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Regression tests for execute plugin configuration."""

from types import SimpleNamespace
from typing import Any

from execution_testing.test_types.block_types import EnvironmentDefaults

from ..execute import pytest_configure


class FakeConfig:
"""Minimal config object for exercising execute plugin setup."""

engine_rpc_supported: bool

def __init__(self, *args: str) -> None:
self.invocation_params = SimpleNamespace(args=args)
self.option = SimpleNamespace(help=True)
self.pluginmanager = SimpleNamespace(has_plugin=lambda _name: False)

def getoption(self, name: str, default: Any = None) -> Any:
"""Return configured option values used by pytest_configure."""
options = {
"transaction_gas_limit": 7,
"disable_html": False,
"htmlpath": None,
"markers": False,
"collectonly": False,
"show_ported_from": False,
"links_as_filled": False,
"help": True,
}
return options.get(name, default)


def test_pytest_configure_ignores_default_transaction_gas_limit() -> None:
"""Default execute options must not rewrite the global block gas limit."""
original_gas_limit = EnvironmentDefaults.gas_limit

config = FakeConfig()
pytest_configure(config) # type: ignore[arg-type]

assert EnvironmentDefaults.gas_limit == original_gas_limit
assert config.engine_rpc_supported is False


def test_pytest_configure_applies_explicit_transaction_gas_limit() -> None:
"""An explicit execute gas-limit override still updates the default."""
original_gas_limit = EnvironmentDefaults.gas_limit

config = FakeConfig("--transaction-gas-limit=7")
pytest_configure(config) # type: ignore[arg-type]

assert EnvironmentDefaults.gas_limit == 7
assert config.engine_rpc_supported is False

EnvironmentDefaults.gas_limit = original_gas_limit
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
get_spec_format_for_item,
is_help_or_collectonly_mode,
labeled_format_parameter_set,
option_was_explicitly_set,
)
from ..spec_version_checker.spec_version_checker import (
get_ref_spec_from_module,
Expand Down Expand Up @@ -827,7 +828,7 @@ def pytest_configure(config: pytest.Config) -> None:
"""
# Register custom markers
# Modify the block gas limit if specified.
if config.getoption("block_gas_limit"):
if option_was_explicitly_set(config, "--block-gas-limit"):
EnvironmentDefaults.gas_limit = config.getoption("block_gas_limit")

# Initialize fixture output configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
import pytest


@pytest.fixture
@pytest.fixture(autouse=True)
def restore_environment_defaults() -> Generator[None, None, None]:
"""
Restore EnvironmentDefaults.gas_limit after tests.
Reset EnvironmentDefaults.gas_limit around each test.

Restore the gas limit after the test run to prevent side effects.
Reset the gas limit to DEFAULT_BLOCK_GAS_LIMIT before and after each test
run to prevent side effects from nested in-process pytest sessions leaking
into later tests on the same worker.
"""
from execution_testing.test_types.block_types import EnvironmentDefaults
from execution_testing.test_types.block_types import (
DEFAULT_BLOCK_GAS_LIMIT,
EnvironmentDefaults,
)

original_gas_limit = EnvironmentDefaults.gas_limit
EnvironmentDefaults.gas_limit = DEFAULT_BLOCK_GAS_LIMIT
yield
EnvironmentDefaults.gas_limit = original_gas_limit
EnvironmentDefaults.gas_limit = DEFAULT_BLOCK_GAS_LIMIT
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,6 @@ def test_max_gas_limit(state_test, pre, block_gas_limit) -> None:
),
],
)
@pytest.mark.usefixtures("restore_environment_defaults")
def test_fill_variables(
testdir: pytest.Testdir,
args: list[str],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@
from execution_testing.specs import BaseTest


def option_was_explicitly_set(config: pytest.Config, option_name: str) -> bool:
"""Return whether a long CLI option was passed explicitly."""
normalized_option = option_name.strip()
if not normalized_option.startswith("--"):
normalized_option = f"--{normalized_option}"

for arg in config.invocation_params.args:
if arg == normalized_option or arg.startswith(f"{normalized_option}="):
return True
return False


def is_help_or_collectonly_mode(config: pytest.Config) -> bool:
"""Check if pytest is running in a help or collectonly mode."""
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,13 @@ class BesuExceptionMapper(ExceptionMapper):
r"exceeds transaction sender account balance 0x[0-9a-f]+"
),
TransactionException.INTRINSIC_GAS_TOO_LOW: (
r"transaction invalid intrinsic gas cost \d+ "
r"transaction invalid intrinsic gas cost \d+"
r"(?: \(regular \d+ \+ state \d+\))? "
r"exceeds gas limit \d+"
),
TransactionException.INTRINSIC_GAS_BELOW_FLOOR_GAS_COST: (
r"transaction invalid intrinsic gas cost \d+ "
r"transaction invalid intrinsic gas cost \d+"
r"(?: \(regular \d+ \+ state \d+\))? "
r"exceeds gas limit \d+"
),
TransactionException.SENDER_NOT_EOA: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@ class ErigonExceptionMapper(ExceptionMapper):
r"invalid block access list"
),
BlockException.INCORRECT_BLOCK_FORMAT: (r"invalid block access list"),
BlockException.BLOCK_ACCESS_LIST_GAS_LIMIT_EXCEEDED: (
r"block access list too large"
),
TransactionException.GAS_LIMIT_EXCEEDS_MAXIMUM: (
r"invalid block, txnIdx=\d+,.*gas limit too high"
r"gas limit too high"
),
BlockException.INCORRECT_BLOB_GAS_USED: (
r"blobGasUsed by execution: \d+, in header: \d+"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ class NethermindExceptionMapper(ExceptionMapper):
"InvalidStateRoot: State root in header does not match"
),
BlockException.GAS_USED_OVERFLOW: ("Block gas limit exceeded"),
BlockException.BLOCK_ACCESS_LIST_GAS_LIMIT_EXCEEDED: (
"BlockAccessListGasLimitExceeded:"
),
}
mapping_regex = {
TransactionException.INSUFFICIENT_ACCOUNT_FUNDS: (
Expand Down Expand Up @@ -431,21 +434,29 @@ class NethermindExceptionMapper(ExceptionMapper):
BlockException.SYSTEM_CONTRACT_CALL_FAILED: (
r"(Withdrawals|Consolidations)Failed: Contract execution failed\."
),
# BAL Exceptions: TODO - review once all clients completed.
BlockException.INVALID_BAL_EXTRA_ACCOUNT: (
r"could not be parsed as a block: "
r"Could not decode block access list."
),
BlockException.INVALID_BAL_HASH: (r"InvalidBlockLevelAccessListRoot:"),
# BAL Exceptions — specific exceptions have unique patterns, but
# INVALID_BLOCK_ACCESS_LIST and INCORRECT_BLOCK_FORMAT intentionally
# overlap because the test framework requires `want in got` matching.
BlockException.INVALID_BAL_HASH: (r"InvalidBlockLevelAccessListHash:"),
BlockException.INVALID_BAL_MISSING_ACCOUNT: (
r"InvalidBlockLevelAccessListRoot:"
r"InvalidBlockLevelAccessList:.*missing account"
),
BlockException.INVALID_BAL_EXTRA_ACCOUNT: (
r"InvalidBlockLevelAccessList:.*surplus changes"
r"|could not be parsed as a block: "
r"Error decoding block access list:"
),
BlockException.INVALID_BLOCK_ACCESS_LIST: (
r"InvalidBlockLevelAccessListRoot:|could not be parsed as a "
r"block: Could not decode block access list."
r"InvalidBlockLevelAccessListHash:"
r"|InvalidBlockLevelAccessList:"
r"|could not be parsed as a block: "
r"Error decoding block access list:"
),
BlockException.INCORRECT_BLOCK_FORMAT: (
r"could not be parsed as a block: "
r"Could not decode block access list."
r"Error decoding block access list:"
),
TransactionException.GAS_ALLOWANCE_EXCEEDED: (
r"TxGasLimitCapExceeded:"
),
}
Loading
Loading