Skip to content

Commit b2025e8

Browse files
pdobaczpacrob
authored andcommitted
new(tests): EIP-7873 expand legacy creation tx tests (ethereum#1489)
1 parent 064180f commit b2025e8

File tree

1 file changed

+86
-5
lines changed

1 file changed

+86
-5
lines changed

tests/osaka/eip7692_eof_v1/eip7873_tx_create/test_creation_tx.py

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import pytest
44

5+
from ethereum_test_base_types.base_types import Address, Bytes
6+
from ethereum_test_exceptions.exceptions import TransactionException
57
from ethereum_test_tools import (
68
Account,
79
Alloc,
@@ -10,6 +12,8 @@
1012
Transaction,
1113
)
1214
from ethereum_test_tools.code.generators import Initcode as LegacyInitcode
15+
from ethereum_test_types.eof.v1 import Container
16+
from tests.prague.eip7702_set_code_tx.spec import Spec
1317

1418
from .. import EOF_FORK_NAME
1519
from ..eip7620_eof_create.helpers import (
@@ -24,16 +28,32 @@
2428

2529

2630
@pytest.mark.with_all_contract_creating_tx_types(selector=lambda tx_type: tx_type != 6)
31+
@pytest.mark.parametrize(
32+
"deploy_code",
33+
[
34+
Bytes("0xEF"),
35+
Bytes("0xEF00"),
36+
Bytes("0xEF0001"),
37+
Bytes("0xEF01"),
38+
smallest_runtime_subcontainer,
39+
smallest_initcode_subcontainer,
40+
],
41+
)
2742
def test_legacy_create_tx_legacy_initcode_eof_bytecode(
2843
state_test: StateTestFiller,
2944
pre: Alloc,
3045
tx_type: int,
46+
deploy_code: Bytes | Container,
3147
):
32-
"""Test that a legacy contract creation tx cannot create EOF code."""
48+
"""
49+
Test that a legacy contract creation tx cannot create EOF code.
50+
51+
This tests only ensures EIP-3541 behavior is kept, not altered by EIP-7873
52+
"""
3353
env = Environment()
3454
sender = pre.fund_eoa()
3555

36-
initcode = LegacyInitcode(deploy_code=smallest_runtime_subcontainer)
56+
initcode = LegacyInitcode(deploy_code=deploy_code)
3757

3858
tx = Transaction(
3959
ty=tx_type,
@@ -58,13 +78,26 @@ def test_legacy_create_tx_legacy_initcode_eof_bytecode(
5878

5979

6080
@pytest.mark.with_all_contract_creating_tx_types(selector=lambda tx_type: tx_type != 6)
61-
@pytest.mark.xfail(reason="evmone incorrectly deploys the contract")
81+
@pytest.mark.parametrize(
82+
"initcode",
83+
[
84+
Bytes("0xEF00"),
85+
Bytes("0xEF0001"),
86+
smallest_runtime_subcontainer,
87+
smallest_initcode_subcontainer,
88+
],
89+
)
90+
@pytest.mark.exception_test
6291
def test_legacy_create_tx_eof_initcode(
6392
state_test: StateTestFiller,
6493
pre: Alloc,
6594
tx_type: int,
95+
initcode: Bytes | Container,
6696
):
67-
"""Test that a legacy contract creation tx cannot use EOF initcode."""
97+
"""
98+
Test that a legacy contract creation tx with EOF initcode (or anything starting with
99+
`0xEF00` in data) is invalid.
100+
"""
68101
env = Environment()
69102
sender = pre.fund_eoa()
70103

@@ -73,7 +106,55 @@ def test_legacy_create_tx_eof_initcode(
73106
sender=sender,
74107
to=None,
75108
gas_limit=100_000,
76-
data=smallest_initcode_subcontainer,
109+
data=initcode,
110+
error=TransactionException.EOF_CREATION_TRANSACTION,
111+
)
112+
113+
destination_contract_address = tx.created_contract
114+
115+
post = {
116+
destination_contract_address: Account.NONEXISTENT,
117+
}
118+
119+
state_test(
120+
env=env,
121+
pre=pre,
122+
post=post,
123+
tx=tx,
124+
)
125+
126+
127+
@pytest.mark.with_all_contract_creating_tx_types(selector=lambda tx_type: tx_type != 6)
128+
@pytest.mark.parametrize(
129+
"initcode",
130+
[
131+
Bytes("0xEF"),
132+
Bytes("0xEF01"),
133+
Bytes("0xEF0101"),
134+
Spec.delegation_designation(Address(0xAA)),
135+
Bytes("0xEF02"),
136+
],
137+
)
138+
def test_legacy_create_tx_prefix_initcode(
139+
state_test: StateTestFiller,
140+
pre: Alloc,
141+
tx_type: int,
142+
initcode: Bytes,
143+
):
144+
"""
145+
Test that a legacy contract creation tx behaves as it did before EIP-7873 for
146+
initcode stating with `EF`, but not falling into the special case of `EF00`.
147+
The transaction should be valid but fail on executing of the first byte `EF`.
148+
"""
149+
env = Environment()
150+
sender = pre.fund_eoa()
151+
152+
tx = Transaction(
153+
ty=tx_type,
154+
sender=sender,
155+
to=None,
156+
gas_limit=100_000,
157+
data=initcode,
77158
)
78159

79160
destination_contract_address = tx.created_contract

0 commit comments

Comments
 (0)