Skip to content

Commit

Permalink
chore(forks,pytest): Add BaseFork.ignore method (#428)
Browse files Browse the repository at this point in the history
* feat(forks): Add `ignore` property to forks

* feat(pytest): use forks `ignore` property to skip forks

* fix(forks): add ignore to transition forks

* chore(fw): clean-up outdated comment in test

---------

Co-authored-by: danceratopz <[email protected]>
  • Loading branch information
marioevz and danceratopz authored Feb 9, 2024
1 parent a614b87 commit 7c03cb5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
10 changes: 10 additions & 0 deletions src/ethereum_test_forks/base_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,23 @@ class BaseFork(ABC, metaclass=BaseForkMeta):
_transition_tool_name: ClassVar[Optional[str]] = None
_blockchain_test_network_name: ClassVar[Optional[str]] = None
_solc_name: ClassVar[Optional[str]] = None
_ignore: ClassVar[bool] = False

def __init_subclass__(
cls,
*,
transition_tool_name: Optional[str] = None,
blockchain_test_network_name: Optional[str] = None,
solc_name: Optional[str] = None,
ignore: bool = False,
) -> None:
"""
Initializes the new fork with values that don't carry over to subclass forks.
"""
cls._transition_tool_name = transition_tool_name
cls._blockchain_test_network_name = blockchain_test_network_name
cls._solc_name = solc_name
cls._ignore = ignore

# Header information abstract methods
@classmethod
Expand Down Expand Up @@ -287,6 +290,13 @@ def is_deployed(cls) -> bool:
"""
return True

@classmethod
def ignore(cls) -> bool:
"""
Returns whether the fork should be ignored during test generation.
"""
return cls._ignore


# Fork Type
Fork = Type[BaseFork]
6 changes: 3 additions & 3 deletions src/ethereum_test_forks/forks/forks.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def precompiles(cls, block_number: int = 0, timestamp: int = 0) -> List[int]:


# Glacier forks skipped, unless explicitly specified
class MuirGlacier(Istanbul, solc_name="istanbul"):
class MuirGlacier(Istanbul, solc_name="istanbul", ignore=True):
"""
Muir Glacier fork
"""
Expand Down Expand Up @@ -273,15 +273,15 @@ def tx_types(cls, block_number: int = 0, timestamp: int = 0) -> List[int]:


# Glacier forks skipped, unless explicitly specified
class ArrowGlacier(London, solc_name="london"):
class ArrowGlacier(London, solc_name="london", ignore=True):
"""
Arrow Glacier fork
"""

pass


class GrayGlacier(ArrowGlacier, solc_name="london"):
class GrayGlacier(ArrowGlacier, solc_name="london", ignore=True):
"""
Gray Glacier fork
"""
Expand Down
2 changes: 2 additions & 0 deletions src/ethereum_test_forks/transition_base_fork.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Base objects used to define transition forks.
"""

from inspect import signature
from typing import Callable, List, Type

Expand Down Expand Up @@ -54,6 +55,7 @@ class NewTransitionClass(
transition_tool_name=cls._transition_tool_name,
blockchain_test_network_name=cls._blockchain_test_network_name,
solc_name=cls._solc_name,
ignore=cls._ignore,
):
pass

Expand Down
4 changes: 0 additions & 4 deletions src/ethereum_test_tools/tests/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ def test_code_operations(code: Code, expected_bytes: bytes):
def fork(request: pytest.FixtureRequest):
"""
Return the target evm-version (fork) for solc compilation.
Note:
- Homestead.
- forks_from_until: Used to remove the Glacier forks
"""
return request.param

Expand Down
28 changes: 14 additions & 14 deletions src/pytest_plugins/forks/forks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Pytest plugin to enable fork range configuration for the test session.
"""

import itertools
import sys
import textwrap
Expand All @@ -13,7 +14,6 @@
from ethereum_test_forks import (
Fork,
ForkAttribute,
forks_from_until,
get_deployed_forks,
get_forks,
get_transition_forks,
Expand Down Expand Up @@ -186,9 +186,7 @@ def get_fork_option(config, option_name):
forks_until = get_fork_option(config, "forks_until")
show_fork_help = config.getoption("show_fork_help")

all_forks = get_forks()
# TODO: Tricky, this removes the *Glacier forks.
config.all_forks = forks_from_until(all_forks[0], all_forks[-1])
config.all_forks = [fork for fork in get_forks() if not fork.ignore()]
config.fork_map = {fork.name(): fork for fork in config.all_forks}
config.fork_names = list(config.fork_map.keys())

Expand Down Expand Up @@ -433,17 +431,19 @@ def pytest_generate_tests(metafunc):
)
else:
pytest_params = [
ForkParametrizer(
fork=fork,
mark=pytest.mark.skip(
reason=(
f"Fork '{fork}' unsupported by "
f"'{metafunc.config.getoption('evm_bin')}'."
)
),
(
ForkParametrizer(
fork=fork,
mark=pytest.mark.skip(
reason=(
f"Fork '{fork}' unsupported by "
f"'{metafunc.config.getoption('evm_bin')}'."
)
),
)
if fork.name() in metafunc.config.unsupported_forks
else ForkParametrizer(fork=fork)
)
if fork.name() in metafunc.config.unsupported_forks
else ForkParametrizer(fork=fork)
for fork in intersection_range
]
add_fork_covariant_parameters(metafunc, pytest_params)
Expand Down

0 comments on commit 7c03cb5

Please sign in to comment.