Skip to content

Commit 41f1656

Browse files
committed
feat(tests,plugins): Add with_all_typed_transactions support
1 parent 05aba5b commit 41f1656

File tree

4 files changed

+127
-5
lines changed

4 files changed

+127
-5
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ 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.fixtures.transaction_fixtures
2021
-p pytest_plugins.help.help
2122
--tb short
2223
--dist loadscope

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ addopts =
1616
-p pytest_plugins.filler.static_filler
1717
-p pytest_plugins.shared.execute_fill
1818
-p pytest_plugins.forks.forks
19+
-p pytest_plugins.fixtures.transaction_fixtures
1920
-p pytest_plugins.eels_resolver
2021
-p pytest_plugins.help.help
2122
--tb short

src/pytest_plugins/forks/forks.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,13 @@ def covariant_decorator(
339339
fork_attribute_name="tx_types",
340340
argnames=["tx_type"],
341341
),
342+
covariant_decorator(
343+
marker_name="with_all_typed_transactions",
344+
description="marks a test to be parametrized with transaction types, the typed_tx fixture "
345+
"will provide the corresponding Transaction object for each type",
346+
fork_attribute_name="tx_types",
347+
argnames=["typed_transaction"],
348+
),
342349
covariant_decorator(
343350
marker_name="with_all_contract_creating_tx_types",
344351
description="marks a test to be parametrized for all tx types that can create a contract"
@@ -972,9 +979,26 @@ def add_fork_covariant_parameters(
972979
metafunc: Metafunc, fork_parametrizers: List[ForkParametrizer]
973980
) -> None:
974981
"""Iterate over the fork covariant descriptors and add their values to the test function."""
975-
for covariant_descriptor in fork_covariant_decorators:
982+
# Special handling for with_all_typed_transactions
983+
if list(metafunc.definition.iter_markers("with_all_typed_transactions")):
984+
# This marker needs special handling for indirect parametrization
976985
for fork_parametrizer in fork_parametrizers:
977-
covariant_descriptor(metafunc=metafunc).add_values(fork_parametrizer=fork_parametrizer)
986+
fork = fork_parametrizer.fork
987+
tx_types = fork.tx_types(block_number=0, timestamp=0)
988+
values = [pytest.param(tx_type) for tx_type in tx_types]
989+
fork_parametrizer.fork_covariant_parameters.append(
990+
ForkCovariantParameter(names=["typed_transaction"], values=values)
991+
)
992+
else:
993+
# Regular covariant descriptors
994+
for covariant_descriptor in fork_covariant_decorators:
995+
# Skip with_all_typed_transactions as it's handled above
996+
if covariant_descriptor.marker_name == "with_all_typed_transactions":
997+
continue
998+
for fork_parametrizer in fork_parametrizers:
999+
covariant_descriptor(metafunc=metafunc).add_values(
1000+
fork_parametrizer=fork_parametrizer
1001+
)
9781002

9791003
for marker in metafunc.definition.iter_markers():
9801004
if marker.name == "parametrize_by_fork":
@@ -1029,6 +1053,11 @@ def parameters_from_fork_parametrizer_list(
10291053

10301054
def parametrize_fork(metafunc: Metafunc, fork_parametrizers: List[ForkParametrizer]) -> None:
10311055
"""Add the fork parameters to the test function."""
1032-
metafunc.parametrize(
1033-
*parameters_from_fork_parametrizer_list(fork_parametrizers), scope="function"
1034-
)
1056+
param_names, param_values = parameters_from_fork_parametrizer_list(fork_parametrizers)
1057+
1058+
# Check if typed_transaction is in the parameters and needs indirect parametrization
1059+
indirect = []
1060+
if "typed_transaction" in param_names:
1061+
indirect.append("typed_transaction")
1062+
1063+
metafunc.parametrize(param_names, param_values, scope="function", indirect=indirect)

src/pytest_plugins/forks/tests/test_covariant_markers.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,97 @@ 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+
),
265356
pytest.param(
266357
"""
267358
import pytest

0 commit comments

Comments
 (0)