Skip to content

Commit

Permalink
feat(specs): Marked slow tests pass slow_request parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Dec 19, 2024
1 parent c50c5ad commit c0e8acf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
19 changes: 15 additions & 4 deletions src/ethereum_test_specs/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

from .base import BaseTest, verify_result
from .debugging import print_traces
from .helpers import verify_transactions
from .helpers import is_slow_test, verify_transactions


def environment_from_parent_header(parent: "FixtureHeader") -> "Environment":
Expand Down Expand Up @@ -384,6 +384,7 @@ def generate_block_data(
previous_env: Environment,
previous_alloc: Alloc,
eips: Optional[List[int]] = None,
slow: bool = False,
) -> Tuple[FixtureHeader, List[Transaction], List[Bytes] | None, Alloc, Environment]:
"""
Generate common block data for both make_fixture and make_hive_fixture.
Expand Down Expand Up @@ -420,6 +421,7 @@ def generate_block_data(
reward=fork.get_reward(env.number, env.timestamp),
eips=eips,
debug_output_path=self.get_next_transition_tool_output_path(),
slow_request=slow,
)

try:
Expand Down Expand Up @@ -528,6 +530,7 @@ def make_fixture(
t8n: TransitionTool,
fork: Fork,
eips: Optional[List[int]] = None,
slow: bool = False,
) -> Fixture:
"""
Create a fixture from the blockchain test definition.
Expand All @@ -552,6 +555,7 @@ def make_fixture(
previous_env=env,
previous_alloc=alloc,
eips=eips,
slow=slow,
)
fixture_block = FixtureBlockBase(
header=header,
Expand Down Expand Up @@ -610,6 +614,7 @@ def make_hive_fixture(
t8n: TransitionTool,
fork: Fork,
eips: Optional[List[int]] = None,
slow: bool = False,
) -> EngineFixture:
"""
Create a hive fixture from the blocktest definition.
Expand All @@ -623,7 +628,13 @@ def make_hive_fixture(

for block in self.blocks:
header, txs, requests, new_alloc, new_env = self.generate_block_data(
t8n=t8n, fork=fork, block=block, previous_env=env, previous_alloc=alloc, eips=eips
t8n=t8n,
fork=fork,
block=block,
previous_env=env,
previous_alloc=alloc,
eips=eips,
slow=slow,
)
if block.rlp is None:
fixture_payloads.append(
Expand Down Expand Up @@ -701,9 +712,9 @@ def generate(
"""
t8n.reset_traces()
if fixture_format == BlockchainEngineFixture:
return self.make_hive_fixture(t8n, fork, eips)
return self.make_hive_fixture(t8n, fork, eips, slow=is_slow_test(request))
elif fixture_format == BlockchainFixture:
return self.make_fixture(t8n, fork, eips)
return self.make_fixture(t8n, fork, eips, slow=is_slow_test(request))

raise Exception(f"Unknown fixture format: {fixture_format}")

Expand Down
12 changes: 11 additions & 1 deletion src/ethereum_test_specs/helpers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""
Helper functions
"""

from dataclasses import dataclass
from typing import Dict, List

import pytest

from ethereum_clis import Result
from ethereum_test_exceptions import ExceptionBase, ExceptionMapper, UndefinedException
from ethereum_test_types import Transaction
Expand Down Expand Up @@ -150,3 +151,12 @@ def verify_transactions(
verify_transaction_exception(exception_mapper=exception_mapper, info=info)

return list(rejected_txs.keys())


def is_slow_test(request: pytest.FixtureRequest) -> bool:
"""
Check if the test is slow
"""
if hasattr(request, "node"):
return request.node.get_closest_marker("slow") is not None
return False
6 changes: 4 additions & 2 deletions src/ethereum_test_specs/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from .base import BaseTest
from .blockchain import Block, BlockchainTest, Header
from .debugging import print_traces
from .helpers import verify_transactions
from .helpers import is_slow_test, verify_transactions

TARGET_BLOB_GAS_PER_BLOCK = 393216

Expand Down Expand Up @@ -124,6 +124,7 @@ def make_state_test_fixture(
t8n: TransitionTool,
fork: Fork,
eips: Optional[List[int]] = None,
slow: bool = False,
) -> Fixture:
"""
Create a fixture from the state test definition.
Expand Down Expand Up @@ -151,6 +152,7 @@ def make_state_test_fixture(
eips=eips,
debug_output_path=self.get_next_transition_tool_output_path(),
state_test=True,
slow_request=slow,
)

try:
Expand Down Expand Up @@ -199,7 +201,7 @@ def generate(
request=request, t8n=t8n, fork=fork, fixture_format=fixture_format, eips=eips
)
elif fixture_format == StateFixture:
return self.make_state_test_fixture(t8n, fork, eips)
return self.make_state_test_fixture(t8n, fork, eips, slow=is_slow_test(request))

raise Exception(f"Unknown fixture format: {fixture_format}")

Expand Down

0 comments on commit c0e8acf

Please sign in to comment.