11"""Test the tx type validation for EIP-1559."""
22
3+ from typing import Generator
4+
35import pytest
46from execution_testing import (
57 Account ,
68 Alloc ,
7- Environment ,
89 Fork ,
10+ ParameterSet ,
911 StateTestFiller ,
1012 Transaction ,
1113 TransactionException ,
1214)
1315from execution_testing import Opcodes as Op
14- from execution_testing .forks import Byzantium , London
15- from requests_cache import Callable
16+ from execution_testing .forks import Byzantium
1617
1718from .spec import ref_spec_1559
1819
1920REFERENCE_SPEC_GIT_PATH = ref_spec_1559 .git_path
2021REFERENCE_SPEC_VERSION = ref_spec_1559 .version
2122
23+ TX_TYPE = 2
24+
2225
23- @pytest .fixture
24- def eip1559_tx_validity_test (
25- state_test : StateTestFiller , pre : Alloc , fork : Fork , env : Environment
26- ) -> Callable [[], None ]:
26+ def tx_validity (fork : Fork ) -> Generator [ParameterSet , None , None ]:
2727 """
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.
28+ Return a generator of parameters for the tx validity test.
3029 """
31-
32- def test_function () -> None :
33- valid = fork >= London
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- max_priority_fee_per_gas = 1 ,
46- protected = fork >= Byzantium ,
47- error = TransactionException .TYPE_2_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
30+ valid = TX_TYPE in fork .tx_types ()
31+ yield pytest .param (
32+ valid ,
33+ marks = [pytest .mark .exception_test ] if not valid else [],
34+ id = "valid" if valid else "invalid" ,
35+ )
5936
6037
6138@pytest .mark .ported_from (
@@ -64,28 +41,33 @@ def test_function() -> None:
6441 ],
6542 pr = ["https://github.com/ethereum/execution-specs/pull/1754" ],
6643)
67- @pytest .mark .exception_test
68- @pytest .mark .valid_until ("Berlin" )
69- def test_eip1559_tx_invalid (
70- eip1559_tx_validity_test : Callable [[], None ],
44+ @pytest .mark .parametrize_by_fork ("valid" , tx_validity )
45+ def test_eip1559_tx_validity (
46+ state_test : StateTestFiller ,
47+ fork : Fork ,
48+ pre : Alloc ,
49+ valid : bool ,
7150) -> None :
7251 """
7352 Tests that an EIP-1559 tx has no effect before London.
7453 """
75- eip1559_tx_validity_test ()
54+ account = pre .deploy_contract (
55+ code = Op .SSTORE (0 , 1 ),
56+ storage = {0 : 0xDEADBEEF },
57+ )
58+ sender = pre .fund_eoa ()
7659
60+ tx = Transaction (
61+ to = account ,
62+ sender = sender ,
63+ gas_limit = 100_000 ,
64+ max_priority_fee_per_gas = 1 ,
65+ protected = fork >= Byzantium ,
66+ error = TransactionException .TYPE_2_TX_PRE_FORK if not valid else None ,
67+ )
7768
78- @pytest .mark .ported_from (
79- [
80- "https://github.com/ethereum/legacytests/blob/master/Cancun/GeneralStateTests/stEIP1559/typeTwoBerlin.json"
81- ],
82- pr = ["https://github.com/ethereum/execution-specs/pull/1754" ],
83- )
84- @pytest .mark .valid_from ("London" )
85- def test_eip1559_tx_valid (
86- eip1559_tx_validity_test : Callable [[], None ],
87- ) -> None :
88- """
89- Tests that an EIP-1559 tx has an effect after London.
90- """
91- eip1559_tx_validity_test ()
69+ post = {account : Account (storage = {0 : 0xDEADBEEF if not valid else 1 })}
70+ if not valid :
71+ post [sender ] = pre [sender ] # type: ignore
72+
73+ state_test (pre = pre , post = post , tx = tx )
0 commit comments