Skip to content

Commit ed3503d

Browse files
committed
feat(tests): Typed txs are invalid and void before their fork
1 parent 9674b7a commit ed3503d

File tree

13 files changed

+227
-126
lines changed

13 files changed

+227
-126
lines changed

packages/testing/src/execution_testing/client_clis/clis/ethrex.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class EthrexExceptionMapper(ExceptionMapper):
5050
TransactionException.TYPE_3_TX_INVALID_BLOB_VERSIONED_HASH: (
5151
r"blob version not supported|Invalid blob versioned hash"
5252
),
53+
TransactionException.TYPE_3_TX_PRE_FORK: (
54+
r"Type 2 transactions are not supported before the London fork"
55+
),
5356
TransactionException.TYPE_3_TX_PRE_FORK: (
5457
r"blob versioned hashes not supported|"
5558
r"Type 3 transactions are not supported before the Cancun fork"

packages/testing/src/execution_testing/client_clis/clis/evmone.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ class EvmoneExceptionMapper(ExceptionMapper):
350350
),
351351
TransactionException.TYPE_4_TX_PRE_FORK: "transaction type not supported",
352352
TransactionException.TYPE_3_TX_PRE_FORK: "transaction type not supported",
353+
TransactionException.TYPE_2_TX_PRE_FORK: "transaction type not supported",
354+
TransactionException.TYPE_1_TX_PRE_FORK: "transaction type not supported",
353355
TransactionException.TYPE_3_TX_INVALID_BLOB_VERSIONED_HASH: "invalid blob hash version",
354356
TransactionException.TYPE_3_TX_BLOB_COUNT_EXCEEDED: "blob gas limit exceeded",
355357
TransactionException.TYPE_3_TX_ZERO_BLOBS: "empty blob hashes list",

packages/testing/src/execution_testing/client_clis/clis/geth.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ class GethExceptionMapper(ExceptionMapper):
5454
TransactionException.PRIORITY_GREATER_THAN_MAX_FEE_PER_GAS: (
5555
"max priority fee per gas higher than max fee per gas"
5656
),
57+
TransactionException.TYPE_1_TX_PRE_FORK: (
58+
"transaction type not supported"
59+
),
60+
TransactionException.TYPE_2_TX_PRE_FORK: (
61+
"transaction type not supported"
62+
),
5763
TransactionException.TYPE_3_TX_PRE_FORK: (
5864
"transaction type not supported"
5965
),

packages/testing/src/execution_testing/client_clis/clis/nethermind.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,12 @@ class NethermindExceptionMapper(ExceptionMapper):
395395
TransactionException.INSUFFICIENT_MAX_FEE_PER_BLOB_GAS: (
396396
"InsufficientMaxFeePerBlobGas: Not enough to cover blob gas fee"
397397
),
398+
TransactionException.TYPE_1_TX_PRE_FORK: (
399+
"InvalidTxType: Transaction type in Custom is not supported"
400+
),
401+
TransactionException.TYPE_2_TX_PRE_FORK: (
402+
"InvalidTxType: Transaction type in Custom is not supported"
403+
),
398404
TransactionException.TYPE_3_TX_PRE_FORK: (
399405
"InvalidTxType: Transaction type in Custom is not supported"
400406
),

packages/testing/src/execution_testing/exceptions/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ class TransactionException(ExceptionBase):
269269
"""
270270
Transaction's initcode for a contract-creating transaction is too large.
271271
"""
272+
TYPE_1_TX_PRE_FORK = auto()
273+
"""Transaction type 1 included before activation fork."""
274+
TYPE_2_TX_PRE_FORK = auto()
275+
"""Transaction type 2 included before activation fork."""
272276
TYPE_3_TX_PRE_FORK = auto()
273277
"""Transaction type 3 included before activation fork."""
274278
TYPE_3_TX_ZERO_BLOBS_PRE_FORK = auto()

packages/testing/src/execution_testing/exceptions/exceptions/transaction.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ class TransactionException(ExceptionBase):
153153
"""
154154
Transaction's initcode for a contract-creating transaction is too large.
155155
"""
156+
TYPE_1_TX_PRE_FORK = auto()
157+
"""Transaction type 1 included before activation fork."""
158+
TYPE_2_TX_PRE_FORK = auto()
159+
"""Transaction type 2 included before activation fork."""
156160
TYPE_3_TX_PRE_FORK = auto()
157161
"""Transaction type 3 included before activation fork."""
158162
TYPE_3_TX_ZERO_BLOBS_PRE_FORK = auto()
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
"""Test the tx type validation for EIP-2930."""
2+
3+
import pytest
4+
from execution_testing import (
5+
Account,
6+
Alloc,
7+
Environment,
8+
Fork,
9+
StateTestFiller,
10+
Transaction,
11+
TransactionException,
12+
)
13+
from execution_testing import Opcodes as Op
14+
from execution_testing.forks import Berlin, Byzantium
15+
from requests_cache import Callable
16+
17+
from .spec import ref_spec_2930
18+
19+
REFERENCE_SPEC_GIT_PATH = ref_spec_2930.git_path
20+
REFERENCE_SPEC_VERSION = ref_spec_2930.version
21+
22+
23+
@pytest.fixture
24+
def eip2930_tx_validity_test(
25+
state_test: StateTestFiller, pre: Alloc, fork: Fork, env: Environment
26+
) -> Callable[[], None]:
27+
"""
28+
Returns a function which applies a `state_test`, where a typed transaction
29+
is either valid and has an effect on state or not, depending on the fork.
30+
"""
31+
32+
def test_function() -> None:
33+
valid = fork >= Berlin
34+
35+
account = pre.deploy_contract(
36+
code=Op.SSTORE(0, 1),
37+
storage={0: 0xDEADBEEF},
38+
)
39+
sender = pre.fund_eoa()
40+
41+
tx = Transaction(
42+
to=account,
43+
sender=sender,
44+
gas_limit=100_000,
45+
access_list=[],
46+
protected=fork >= Byzantium,
47+
error=TransactionException.TYPE_1_TX_PRE_FORK
48+
if not valid
49+
else None,
50+
)
51+
52+
post = {account: Account(storage={0: 0xDEADBEEF if not valid else 1})}
53+
if not valid:
54+
post[sender] = pre[sender] # type: ignore
55+
56+
state_test(env=env, pre=pre, post=post, tx=tx)
57+
58+
return test_function
59+
60+
61+
@pytest.mark.ported_from(
62+
[
63+
"https://github.com/ethereum/legacytests/blob/master/src/LegacyTests/Cancun/GeneralStateTestsFiller/stExample/accessListExampleFiller.yml"
64+
],
65+
pr=["https://github.com/ethereum/execution-specs/pull/1754"],
66+
)
67+
@pytest.mark.exception_test
68+
@pytest.mark.valid_until("Istanbul")
69+
def test_eip2930_tx_invalid(
70+
eip2930_tx_validity_test: Callable[[], None],
71+
) -> None:
72+
"""
73+
Tests that an EIP-2930 tx has no effect before Berlin.
74+
"""
75+
eip2930_tx_validity_test()
76+
77+
78+
@pytest.mark.ported_from(
79+
[
80+
"https://github.com/ethereum/legacytests/blob/master/src/LegacyTests/Cancun/GeneralStateTestsFiller/stExample/accessListExampleFiller.yml"
81+
],
82+
pr=["https://github.com/ethereum/execution-specs/pull/1754"],
83+
)
84+
@pytest.mark.valid_from("Berlin")
85+
def test_eip2930_tx_valid(
86+
eip2930_tx_validity_test: Callable[[], None],
87+
) -> None:
88+
"""
89+
Tests that an EIP-2930 tx has an effect after Berlin.
90+
"""
91+
eip2930_tx_validity_test()

tests/london/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Test cases for EVM functionality introduced in London."""
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
Tests for [EIP-1559: Fee market change for ETH 1.0 chain](https://eips.ethereum.org/EIPS/eip-1559).
3+
"""
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""Defines EIP-1559 specification constants and functions."""
2+
3+
from dataclasses import dataclass
4+
5+
6+
@dataclass(frozen=True)
7+
class ReferenceSpec:
8+
"""Defines the reference spec version and git path."""
9+
10+
git_path: str
11+
version: str
12+
13+
14+
ref_spec_1559 = ReferenceSpec(
15+
"EIPS/eip-1559.md", "ba6c342c23164072adb500c3136e3ae6eabff306"
16+
)

0 commit comments

Comments
 (0)