Skip to content

Commit 79ad559

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

File tree

9 files changed

+89
-0
lines changed

9 files changed

+89
-0
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ 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",
353354
TransactionException.TYPE_3_TX_INVALID_BLOB_VERSIONED_HASH: "invalid blob hash version",
354355
TransactionException.TYPE_3_TX_BLOB_COUNT_EXCEEDED: "blob gas limit exceeded",
355356
TransactionException.TYPE_3_TX_ZERO_BLOBS: "empty blob hashes list",

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ 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_2_TX_PRE_FORK: (
58+
"transaction type not supported"
59+
),
5760
TransactionException.TYPE_3_TX_PRE_FORK: (
5861
"transaction type not supported"
5962
),

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ class NethermindExceptionMapper(ExceptionMapper):
395395
TransactionException.INSUFFICIENT_MAX_FEE_PER_BLOB_GAS: (
396396
"InsufficientMaxFeePerBlobGas: Not enough to cover blob gas fee"
397397
),
398+
TransactionException.TYPE_2_TX_PRE_FORK: (
399+
"InvalidTxType: Transaction type in Custom is not supported"
400+
),
398401
TransactionException.TYPE_3_TX_PRE_FORK: (
399402
"InvalidTxType: Transaction type in Custom is not supported"
400403
),

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

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

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ class TransactionException(ExceptionBase):
153153
"""
154154
Transaction's initcode for a contract-creating transaction is too large.
155155
"""
156+
TYPE_2_TX_PRE_FORK = auto()
157+
"""Transaction type 2 included before activation fork."""
156158
TYPE_3_TX_PRE_FORK = auto()
157159
"""Transaction type 3 included before activation fork."""
158160
TYPE_3_TX_ZERO_BLOBS_PRE_FORK = auto()

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+
Test for validation rules that apply for all forks starting from London.
3+
"""
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"""Test the tx type validation for EIP-1559."""
2+
3+
import pytest
4+
from execution_testing.base_types.composite_types import Account, Alloc
5+
from execution_testing.exceptions.exceptions import TransactionException
6+
from execution_testing.forks import Byzantium, London
7+
from execution_testing.forks.helpers import Fork
8+
from execution_testing.specs.state import StateTestFiller
9+
from execution_testing.test_types.block_types import Environment
10+
from execution_testing.test_types.transaction_types import Transaction
11+
from execution_testing.vm import Opcodes as Op
12+
from requests_cache import Callable
13+
14+
15+
@pytest.fixture
16+
def eip1559_tx_validity_test(
17+
state_test: StateTestFiller, pre: Alloc, fork: Fork, env: Environment
18+
) -> Callable[[], None]:
19+
"""
20+
Returns a function which applies a `state_test`, where a typed transaction
21+
is either valid and has an effect on state or not, depending on the fork.
22+
"""
23+
24+
def test_function() -> None:
25+
valid = fork >= London
26+
27+
account = pre.deploy_contract(
28+
code=Op.SSTORE(0, 1),
29+
storage={0: 0xDEADBEEF},
30+
)
31+
sender = pre.fund_eoa()
32+
33+
tx = Transaction(
34+
to=account,
35+
sender=sender,
36+
gas_limit=100_000,
37+
max_priority_fee_per_gas=1,
38+
protected=fork >= Byzantium,
39+
error=TransactionException.TYPE_2_TX_PRE_FORK
40+
if not valid
41+
else None,
42+
)
43+
44+
post = {account: Account(storage={0: 0xDEADBEEF if not valid else 1})}
45+
if not valid:
46+
post[sender] = pre[sender]
47+
48+
state_test(env=env, pre=pre, post=post, tx=tx)
49+
50+
return test_function
51+
52+
53+
@pytest.mark.exception_test
54+
@pytest.mark.valid_until("Berlin")
55+
def test_eip1559_tx_invalid(
56+
eip1559_tx_validity_test: Callable[[], None],
57+
) -> None:
58+
"""
59+
Tests that an EIP-1559 tx has no effect before London.
60+
"""
61+
eip1559_tx_validity_test()
62+
63+
64+
@pytest.mark.valid_from("London")
65+
def test_eip1559_tx_valid(
66+
eip1559_tx_validity_test: Callable[[], None],
67+
) -> None:
68+
"""
69+
Tests that an EIP-1559 tx has an effect after London.
70+
"""
71+
eip1559_tx_validity_test()

0 commit comments

Comments
 (0)