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 @@ -851,13 +851,10 @@ def pytest_collection_modifyitems(
if isinstance(item, EIPSpecTestItem):
continue
params: Dict[str, Any] = item.callspec.params # type: ignore
if (
"parametrized_fork" not in params
or params["parametrized_fork"] is None
):
if "fork" not in params or params["fork"] is None:
items_for_removal.append(i)
continue
fork: Fork | TransitionFork = params["parametrized_fork"]
fork: Fork | TransitionFork = params["fork"]
spec_type, execute_format = get_spec_format_for_item(params)
assert issubclass(execute_format, BaseExecute)
markers = list(item.iter_markers())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1922,14 +1922,10 @@ def pytest_collection_modifyitems(
params = item.callspec.params
elif hasattr(item, "params"):
params = item.params
if (
not params
or "parametrized_fork" not in params
or params["parametrized_fork"] is None
):
if not params or "fork" not in params or params["fork"] is None:
items_for_removal.append(i)
continue
fork: Fork | TransitionFork = params["parametrized_fork"]
fork: Fork | TransitionFork = params["fork"]
spec_type, fixture_format = get_spec_format_for_item(params)
if isinstance(fixture_format, NotSetType):
items_for_removal.append(i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def create_function_page_props(
)
for value in values
]
fork = item.callspec.params.get("parametrized_fork").name() # type: ignore
fork = item.callspec.params.get("fork").name() # type: ignore
test_type = get_test_function_test_type(item)
test_type_value = item.callspec.params.get(test_type)
fixture_type = test_type_value.format_name # type: ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def collect(self: "FillerFile") -> Generator["FillerTestItem", None, None]:
ps_id = fixture_format_parameter_set.id
test_id = f"fork_{fork.name()}-{ps_id}"
if "fork" in func_parameters:
params["parametrized_fork"] = fork
params["fork"] = fork
if "pre" in func_parameters:
fixturenames.append("pre")
if "request" in func_parameters:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def __init__(
marks = []
self.fork_covariant_parameters = [
ForkCovariantParameter(
names=["parametrized_fork"],
names=["fork"],
values=[
pytest.param(
fork,
Expand Down Expand Up @@ -671,7 +671,7 @@ def pytest_report_header(config: pytest.Config, start_path: Any) -> List[str]:


@pytest.fixture(autouse=True)
def parametrized_fork(request: pytest.FixtureRequest) -> None:
def fork(request: pytest.FixtureRequest) -> None:
"""Parametrize test cases by fork."""
pass

Expand Down Expand Up @@ -1234,9 +1234,7 @@ def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
],
)
]
metafunc.parametrize(
"parametrized_fork", pytest_params, scope="function"
)
metafunc.parametrize("fork", pytest_params, scope="function")
return

# Get the intersection between the test's validity marker and the current
Expand All @@ -1245,7 +1243,7 @@ def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
test_fork_set & metafunc.config.selected_fork_set # type: ignore
)

if "parametrized_fork" not in metafunc.fixturenames:
if "fork" not in metafunc.fixturenames:
return

unsupported_forks: Set[Fork | TransitionFork] = (
Expand All @@ -1268,9 +1266,7 @@ def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
],
)
]
metafunc.parametrize(
"parametrized_fork", pytest_params, scope="function"
)
metafunc.parametrize("fork", pytest_params, scope="function")
else:
pytest_params = []
for fork in sorted(intersection_set):
Expand Down Expand Up @@ -1574,7 +1570,7 @@ def pytest_collection_modifyitems(
continue

# --- validity markers ---
fork = params.get("parametrized_fork")
fork = params.get("fork")
if fork is None:
continue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
[
pytest.param(
[ForkParametrizer(fork=Frontier)],
["parametrized_fork"],
["fork"],
[pytest.param(Frontier)],
id="only_fork",
),
Expand All @@ -34,7 +34,7 @@
],
)
],
["parametrized_fork", "some_value"],
["fork", "some_value"],
[pytest.param(Frontier, 1)],
id="fork_with_single_covariant_parameter",
),
Expand All @@ -50,7 +50,7 @@
],
)
],
["parametrized_fork", "some_value"],
["fork", "some_value"],
[pytest.param(Frontier, 1), pytest.param(Frontier, 2)],
id="fork_with_single_covariant_parameter_multiple_values",
),
Expand All @@ -69,7 +69,7 @@
],
)
],
["parametrized_fork", "some_value"],
["fork", "some_value"],
[
pytest.param(Frontier, 1, marks=[pytest.mark.some_mark]),
pytest.param(Frontier, 2),
Expand All @@ -90,7 +90,7 @@
],
)
],
["parametrized_fork", "some_value", "another_value"],
["fork", "some_value", "another_value"],
[pytest.param(Frontier, 1, 2)],
id="fork_with_multiple_covariant_parameters",
),
Expand All @@ -109,7 +109,7 @@
],
)
],
["parametrized_fork", "some_value", "another_value"],
["fork", "some_value", "another_value"],
[pytest.param(Frontier, 1, 2), pytest.param(Frontier, 1, 3)],
id="fork_with_multiple_covariant_parameters_multiple_values",
),
Expand All @@ -128,7 +128,7 @@
],
)
],
["parametrized_fork", "some_value", "another_value"],
["fork", "some_value", "another_value"],
[pytest.param(Frontier, 1, "a"), pytest.param(Frontier, 2, "b")],
id="fork_with_single_multi_value_covariant_parameter_multiple_values",
),
Expand All @@ -155,7 +155,7 @@
)
],
[
"parametrized_fork",
"fork",
"some_value",
"another_value",
"yet_another_value",
Expand Down Expand Up @@ -191,12 +191,7 @@
],
)
],
[
"parametrized_fork",
"shared_value",
"different_value_1",
"different_value_2",
],
["fork", "shared_value", "different_value_1", "different_value_2"],
[
pytest.param(Frontier, 1, "a", "x"),
pytest.param(Frontier, 2, "b", "y"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,26 +553,16 @@ def _is_benchmark_test(request: pytest.FixtureRequest) -> bool:


@pytest.fixture
def env_gas_limit(request: pytest.FixtureRequest) -> int:
def genesis_environment(request: pytest.FixtureRequest) -> Environment:
"""Return an Environment with appropriate gas limit."""
if _is_benchmark_test(request):
return BENCHMARKING_MAX_GAS
return EnvironmentDefaults.gas_limit


@pytest.fixture
def genesis_environment(
request: pytest.FixtureRequest, env_gas_limit: int
) -> Environment:
"""Return an Environment with appropriate gas limit."""
if _is_benchmark_test(request):
return Environment(gas_limit=env_gas_limit)
return Environment(gas_limit=BENCHMARKING_MAX_GAS)
return Environment()


@pytest.fixture
def env(request: pytest.FixtureRequest, env_gas_limit: int) -> Environment:
def env(request: pytest.FixtureRequest) -> Environment:
"""Return an Environment with appropriate gas limit."""
if _is_benchmark_test(request):
return Environment(gas_limit=env_gas_limit)
return Environment(gas_limit=BENCHMARKING_MAX_GAS)
return Environment()
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
Shared pytest fixtures and hooks for EEST generation modes (fill and execute).
"""

from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING, Dict, List, Tuple
from typing import Dict, List, Tuple

import pytest
from pytest import StashKey
Expand All @@ -17,20 +15,11 @@
LabeledExecuteFormat,
)
from execution_testing.fixtures import BaseFixture, LabeledFixtureFormat

if TYPE_CHECKING:
from execution_testing.forks import Fork, TransitionFork
import sys

from execution_testing.logging import get_logger
from execution_testing.rpc import EthRPC
from execution_testing.specs import BaseTest
from execution_testing.specs.base import OpMode
from execution_testing.test_types import (
EOA,
Alloc,
ChainConfig,
)
from execution_testing.test_types import EOA, Alloc, ChainConfig

from ..shared.address_stubs import AddressStubs, StubEOA
from ..shared.helpers import get_rpc_endpoint
Expand Down Expand Up @@ -321,58 +310,9 @@ def pytest_make_parametrize_id(
readable test ids for the generated tests.
"""
del config
if argname == "parametrized_fork":
return f"fork_{val}"
return f"{argname}_{val}"


@pytest.fixture(scope="function")
def fork(
parametrized_fork: Fork | TransitionFork,
monkeypatch: pytest.MonkeyPatch,
env_gas_limit: int,
) -> Fork | TransitionFork:
"""
Return a per-test fork variant whose ``_env_gas_limit`` tracks the
``Environment.gas_limit`` used by the test.
"""
fork_variant = parametrized_fork.with_env_gas_limit(env_gas_limit)

# Now we monkey-patch the `Environment` class with one that is aware of
# the fork that the test is using, and will update its `_env_gas_limit`
# automatically.
# TODO: This should not be necessary, we should treat the `env` object the
# same way we do `pre` and force it to be a singleton in the test's
# context.
from execution_testing.test_types.block_types import (
Environment as OriginalEnvironment,
)

class _ForkAwareEnvironment(OriginalEnvironment):
"""Transparently syncs ``gas_limit`` back to the fork variant."""

def model_post_init(self, __context: object) -> None:
super().model_post_init(__context)
fork_variant._env_gas_limit = int(self.gas_limit)

def __setattr__(self, name: str, value: object) -> None:
super().__setattr__(name, value)
if name == "gas_limit":
fork_variant._env_gas_limit = int(self.gas_limit)

# Replace Environment in every module that imported the original class
# so that both `Environment(...)` in test code and in conftest fixtures
# create _ForkAwareEnvironment instances.
for mod in list(sys.modules.values()):
try:
if getattr(mod, "Environment", None) is OriginalEnvironment:
monkeypatch.setattr(mod, "Environment", _ForkAwareEnvironment)
except Exception:
continue

return fork_variant


SPEC_TYPES_PARAMETERS: List[str] = list(BaseTest.spec_types.keys())


Expand Down
Loading
Loading