Skip to content

Commit d26c90b

Browse files
committed
refactor(tests) Changes from comments on pr #1890:
- Move default transaction logic to a ``conftest.py`` setup. - Add ``conftest.py`` files for each fork with the respective transaction pytest fixtures. - Opt for `Type | None` over `Optional[Type]` to avoid an extra import.
1 parent eab5984 commit d26c90b

File tree

11 files changed

+188
-309
lines changed

11 files changed

+188
-309
lines changed

src/cli/pytest_commands/pytest_ini_files/pytest-execute.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ addopts =
1717
-p pytest_plugins.execute.rpc.remote_seed_sender
1818
-p pytest_plugins.execute.rpc.remote
1919
-p pytest_plugins.forks.forks
20-
-p pytest_plugins.pytest_fixtures.transaction_fixtures
2120
-p pytest_plugins.help.help
2221
--tb short
2322
--dist loadscope

src/pytest_plugins/forks/forks.py

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@
2525
transition_fork_to,
2626
)
2727

28-
# Import transaction fixtures to make them available when this plugin is loaded
29-
from .transaction_fixtures import ( # noqa: F401
30-
type_0_default_transaction,
31-
type_1_default_transaction,
32-
type_2_default_transaction,
33-
type_3_default_transaction,
34-
type_4_default_transaction,
35-
typed_transaction,
36-
)
37-
3828

3929
def pytest_addoption(parser):
4030
"""Add command-line options to pytest."""
@@ -349,13 +339,6 @@ def covariant_decorator(
349339
fork_attribute_name="tx_types",
350340
argnames=["tx_type"],
351341
),
352-
covariant_decorator(
353-
marker_name="with_all_typed_transactions",
354-
description="marks a test to be parametrized with transaction types, the typed_tx fixture "
355-
"will provide the corresponding Transaction object for each type",
356-
fork_attribute_name="tx_types",
357-
argnames=["typed_transaction"],
358-
),
359342
covariant_decorator(
360343
marker_name="with_all_contract_creating_tx_types",
361344
description="marks a test to be parametrized for all tx types that can create a contract"
@@ -989,26 +972,9 @@ def add_fork_covariant_parameters(
989972
metafunc: Metafunc, fork_parametrizers: List[ForkParametrizer]
990973
) -> None:
991974
"""Iterate over the fork covariant descriptors and add their values to the test function."""
992-
# Special handling for with_all_typed_transactions
993-
if list(metafunc.definition.iter_markers("with_all_typed_transactions")):
994-
# This marker needs special handling for indirect parametrization
975+
for covariant_descriptor in fork_covariant_decorators:
995976
for fork_parametrizer in fork_parametrizers:
996-
fork = fork_parametrizer.fork
997-
tx_types = fork.tx_types(block_number=0, timestamp=0)
998-
values = [pytest.param(tx_type) for tx_type in tx_types]
999-
fork_parametrizer.fork_covariant_parameters.append(
1000-
ForkCovariantParameter(names=["typed_transaction"], values=values)
1001-
)
1002-
else:
1003-
# Regular covariant descriptors
1004-
for covariant_descriptor in fork_covariant_decorators:
1005-
# Skip with_all_typed_transactions as it's handled above
1006-
if covariant_descriptor.marker_name == "with_all_typed_transactions":
1007-
continue
1008-
for fork_parametrizer in fork_parametrizers:
1009-
covariant_descriptor(metafunc=metafunc).add_values(
1010-
fork_parametrizer=fork_parametrizer
1011-
)
977+
covariant_descriptor(metafunc=metafunc).add_values(fork_parametrizer=fork_parametrizer)
1012978

1013979
for marker in metafunc.definition.iter_markers():
1014980
if marker.name == "parametrize_by_fork":
@@ -1063,11 +1029,6 @@ def parameters_from_fork_parametrizer_list(
10631029

10641030
def parametrize_fork(metafunc: Metafunc, fork_parametrizers: List[ForkParametrizer]) -> None:
10651031
"""Add the fork parameters to the test function."""
1066-
param_names, param_values = parameters_from_fork_parametrizer_list(fork_parametrizers)
1067-
1068-
# Check if typed_transaction is in the parameters and needs indirect parametrization
1069-
indirect = []
1070-
if "typed_transaction" in param_names:
1071-
indirect.append("typed_transaction")
1072-
1073-
metafunc.parametrize(param_names, param_values, scope="function", indirect=indirect)
1032+
metafunc.parametrize(
1033+
*parameters_from_fork_parametrizer_list(fork_parametrizers), scope="function"
1034+
)

src/pytest_plugins/forks/tests/test_covariant_markers.py

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -262,97 +262,6 @@ def test_case(state_test, system_contract):
262262
None,
263263
id="with_all_system_contracts",
264264
),
265-
pytest.param(
266-
"""
267-
import pytest
268-
from ethereum_test_tools import Transaction
269-
@pytest.mark.with_all_typed_transactions()
270-
@pytest.mark.valid_from("Berlin")
271-
@pytest.mark.valid_until("Berlin")
272-
@pytest.mark.state_test_only
273-
def test_case(state_test, typed_transaction, pre):
274-
assert isinstance(typed_transaction, Transaction)
275-
assert typed_transaction.ty in [0, 1] # Berlin supports types 0 and 1
276-
""",
277-
{"passed": 2, "failed": 0, "skipped": 0, "errors": 0},
278-
None,
279-
id="with_all_typed_transactions_berlin",
280-
),
281-
pytest.param(
282-
"""
283-
import pytest
284-
from ethereum_test_tools import Transaction
285-
@pytest.mark.with_all_typed_transactions()
286-
@pytest.mark.valid_from("London")
287-
@pytest.mark.valid_until("London")
288-
@pytest.mark.state_test_only
289-
def test_case(state_test, typed_transaction, pre):
290-
assert isinstance(typed_transaction, Transaction)
291-
assert typed_transaction.ty in [0, 1, 2] # London supports types 0, 1, 2
292-
""",
293-
{"passed": 3, "failed": 0, "skipped": 0, "errors": 0},
294-
None,
295-
id="with_all_typed_transactions_london",
296-
),
297-
pytest.param(
298-
"""
299-
import pytest
300-
from ethereum_test_tools import Transaction
301-
@pytest.mark.with_all_typed_transactions()
302-
@pytest.mark.valid_from("London")
303-
@pytest.mark.valid_until("London")
304-
@pytest.mark.state_test_only
305-
def test_case(state_test, typed_transaction, pre):
306-
assert isinstance(typed_transaction, Transaction)
307-
# Test with marks to skip type 0
308-
if typed_transaction.ty == 0:
309-
pytest.skip("Testing skip functionality")
310-
""",
311-
{"passed": 2, "failed": 0, "skipped": 1, "errors": 0},
312-
None,
313-
id="with_all_typed_transactions_with_skip",
314-
),
315-
pytest.param(
316-
"""
317-
import pytest
318-
from ethereum_test_tools import Transaction
319-
from ethereum_test_base_types import AccessList
320-
321-
# Override the type 3 transaction fixture
322-
@pytest.fixture
323-
def type_3_default_transaction(pre):
324-
sender = pre.fund_eoa()
325-
326-
return Transaction(
327-
ty=3,
328-
sender=sender,
329-
max_fee_per_gas=10**10,
330-
max_priority_fee_per_gas=10**9,
331-
max_fee_per_blob_gas=10**8,
332-
gas_limit=300_000,
333-
data=b"\\xFF" * 50,
334-
access_list=[
335-
AccessList(address=0x1111, storage_keys=[10, 20]),
336-
],
337-
blob_versioned_hashes=[
338-
0x0111111111111111111111111111111111111111111111111111111111111111,
339-
],
340-
)
341-
342-
@pytest.mark.with_all_typed_transactions()
343-
@pytest.mark.valid_at("Cancun")
344-
@pytest.mark.state_test_only
345-
def test_case(state_test, typed_transaction, pre):
346-
assert isinstance(typed_transaction, Transaction)
347-
if typed_transaction.ty == 3:
348-
# Verify our override worked
349-
assert typed_transaction.data == b"\\xFF" * 50
350-
assert len(typed_transaction.blob_versioned_hashes) == 1
351-
""",
352-
{"passed": 4, "failed": 0, "skipped": 0, "errors": 0},
353-
None,
354-
id="with_all_typed_transactions_with_override",
355-
),
356265
pytest.param(
357266
"""
358267
import pytest

src/pytest_plugins/forks/transaction_fixtures.py

Lines changed: 0 additions & 166 deletions
This file was deleted.

tests/berlin/conftest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Fixtures for Berlin fork tests."""
2+
3+
import pytest
4+
5+
from ethereum_test_base_types import AccessList
6+
from ethereum_test_types import Transaction
7+
8+
9+
@pytest.fixture
10+
def type_1_default_transaction(sender):
11+
"""Type 1 (access list) default transaction introduced in Berlin fork."""
12+
return Transaction(
13+
ty=1,
14+
sender=sender,
15+
gas_price=10**9,
16+
gas_limit=100_000,
17+
data=b"\x00" * 100,
18+
access_list=[
19+
AccessList(address=0x1234, storage_keys=[0, 1, 2]),
20+
AccessList(address=0x5678, storage_keys=[3, 4, 5]),
21+
AccessList(address=0x9ABC, storage_keys=[]),
22+
],
23+
)

0 commit comments

Comments
 (0)