22
33import pytest
44
5+ from ethereum_test_base_types .base_types import Bytes
56from ethereum_test_exceptions .exceptions import TransactionException
67from ethereum_test_tools import (
78 Account ,
1112 Transaction ,
1213)
1314from ethereum_test_tools .code .generators import Initcode as LegacyInitcode
15+ from ethereum_test_types .eof .v1 import Container
1416
1517from .. import EOF_FORK_NAME
1618from ..eip7620_eof_create .helpers import (
2527
2628
2729@pytest .mark .with_all_contract_creating_tx_types (selector = lambda tx_type : tx_type != 6 )
30+ @pytest .mark .parametrize (
31+ "deploy_code" ,
32+ [
33+ Bytes ("0xEF" ),
34+ Bytes ("0xEF00" ),
35+ Bytes ("0xEF0001" ),
36+ Bytes ("0xEF01" ),
37+ smallest_runtime_subcontainer ,
38+ smallest_initcode_subcontainer ,
39+ ],
40+ )
2841def test_legacy_create_tx_legacy_initcode_eof_bytecode (
2942 state_test : StateTestFiller ,
3043 pre : Alloc ,
3144 tx_type : int ,
45+ deploy_code : Bytes | Container ,
3246):
33- """Test that a legacy contract creation tx cannot create EOF code."""
47+ """
48+ Test that a legacy contract creation tx cannot create EOF code.
49+
50+ This tests only ensures EIP-3541 behavior is kept, not altered by EIP-7873
51+ """
3452 env = Environment ()
3553 sender = pre .fund_eoa ()
3654
37- initcode = LegacyInitcode (deploy_code = smallest_runtime_subcontainer )
55+ initcode = LegacyInitcode (deploy_code = deploy_code )
3856
3957 tx = Transaction (
4058 ty = tx_type ,
@@ -59,13 +77,26 @@ def test_legacy_create_tx_legacy_initcode_eof_bytecode(
5977
6078
6179@pytest .mark .with_all_contract_creating_tx_types (selector = lambda tx_type : tx_type != 6 )
80+ @pytest .mark .parametrize (
81+ "initcode" ,
82+ [
83+ Bytes ("0xEF00" ),
84+ Bytes ("0xEF0001" ),
85+ smallest_runtime_subcontainer ,
86+ smallest_initcode_subcontainer ,
87+ ],
88+ )
6289@pytest .mark .exception_test
6390def test_legacy_create_tx_eof_initcode (
6491 state_test : StateTestFiller ,
6592 pre : Alloc ,
6693 tx_type : int ,
94+ initcode : Bytes | Container ,
6795):
68- """Test that a legacy contract creation tx cannot use EOF initcode."""
96+ """
97+ Test that a legacy contract creation tx with EOF initcode (or anything starting with
98+ `0xEF00` in data) is invalid.
99+ """
69100 env = Environment ()
70101 sender = pre .fund_eoa ()
71102
@@ -74,7 +105,7 @@ def test_legacy_create_tx_eof_initcode(
74105 sender = sender ,
75106 to = None ,
76107 gas_limit = 100_000 ,
77- data = smallest_initcode_subcontainer ,
108+ data = initcode ,
78109 error = TransactionException .EOF_CREATION_TRANSACTION ,
79110 )
80111
@@ -90,3 +121,50 @@ def test_legacy_create_tx_eof_initcode(
90121 post = post ,
91122 tx = tx ,
92123 )
124+
125+
126+ @pytest .mark .with_all_contract_creating_tx_types (selector = lambda tx_type : tx_type != 6 )
127+ @pytest .mark .parametrize (
128+ "initcode" ,
129+ [
130+ Bytes ("0xEF" ),
131+ Bytes ("0xEF01" ),
132+ Bytes ("0xEF0101" ),
133+ Bytes ("0xEF01" + "" .join ("ab" )),
134+ Bytes ("0xEF02" ),
135+ ],
136+ )
137+ def test_legacy_create_tx_prefix_initcode (
138+ state_test : StateTestFiller ,
139+ pre : Alloc ,
140+ tx_type : int ,
141+ initcode : Bytes ,
142+ ):
143+ """
144+ Test that a legacy contract creation tx behaves as it did before EIP-7873 for
145+ initcode stating with `EF`, but not falling into the special case of `EF00`.
146+ The transaction should be valid but fail on executing of the first byte `EF`.
147+ """
148+ env = Environment ()
149+ sender = pre .fund_eoa ()
150+
151+ tx = Transaction (
152+ ty = tx_type ,
153+ sender = sender ,
154+ to = None ,
155+ gas_limit = 100_000 ,
156+ data = initcode ,
157+ )
158+
159+ destination_contract_address = tx .created_contract
160+
161+ post = {
162+ destination_contract_address : Account .NONEXISTENT ,
163+ }
164+
165+ state_test (
166+ env = env ,
167+ pre = pre ,
168+ post = post ,
169+ tx = tx ,
170+ )
0 commit comments