Skip to content

Commit db112a8

Browse files
committed
fix(tests): EOF - Container types
1 parent e71f2ea commit db112a8

File tree

3 files changed

+130
-94
lines changed

3 files changed

+130
-94
lines changed

tests/prague/eip7692_eof_v1/eip3540_eof_v1/container.py

Lines changed: 16 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44

55
from typing import List
66

7-
from ethereum_test_tools.eof.v1 import VERSION_MAX_SECTION_KIND, AutoSection, Container, Section
8-
from ethereum_test_tools.eof.v1 import SectionKind as Kind
7+
from ethereum_test_tools.eof.v1 import (
8+
VERSION_MAX_SECTION_KIND,
9+
AutoSection,
10+
Container,
11+
Section,
12+
SectionKind,
13+
)
914
from ethereum_test_tools.eof.v1.constants import (
1015
MAX_CODE_INPUTS,
1116
MAX_CODE_OUTPUTS,
@@ -15,76 +20,6 @@
1520
from ethereum_test_tools.exceptions import EOFException
1621
from ethereum_test_tools.vm.opcode import Opcodes as Op
1722

18-
VALID: List[Container] = [
19-
Container(
20-
name="single_code_single_data_section",
21-
sections=[
22-
Section.Code(
23-
code=Op.PUSH0 + Op.POP + Op.STOP,
24-
max_stack_height=1,
25-
),
26-
Section.Data(data="0x00"),
27-
],
28-
),
29-
Container(
30-
name="max_code_sections",
31-
sections=[
32-
Section.Code(Op.JUMPF[i + 1] if i < (MAX_CODE_SECTIONS - 1) else Op.STOP)
33-
for i in range(MAX_CODE_SECTIONS)
34-
],
35-
),
36-
Container(
37-
name="max_code_sections_plus_data",
38-
sections=[
39-
Section.Code(Op.JUMPF[i + 1] if i < (MAX_CODE_SECTIONS - 1) else Op.STOP)
40-
for i in range(MAX_CODE_SECTIONS)
41-
]
42-
+ [Section.Data(data="0x00")],
43-
),
44-
Container(
45-
name="max_code_sections_plus_container",
46-
sections=[
47-
Section.Code(
48-
Op.JUMPF[i + 1] if i < (MAX_CODE_SECTIONS - 1) else Op.RETURNCONTRACT[0](0, 0)
49-
)
50-
for i in range(MAX_CODE_SECTIONS)
51-
]
52-
+ [
53-
Section.Container(
54-
container=Container(
55-
name="max_code_sections",
56-
sections=[
57-
Section.Code(Op.JUMPF[i + 1] if i < (MAX_CODE_SECTIONS - 1) else Op.STOP)
58-
for i in range(MAX_CODE_SECTIONS)
59-
],
60-
)
61-
)
62-
],
63-
),
64-
Container(
65-
name="max_code_sections_plus_data_plus_container",
66-
sections=[
67-
Section.Code(
68-
Op.JUMPF[i + 1] if i < (MAX_CODE_SECTIONS - 1) else Op.RETURNCONTRACT[0](0, 0)
69-
)
70-
for i in range(MAX_CODE_SECTIONS)
71-
]
72-
+ [
73-
Section.Container(
74-
container=Container(
75-
name="max_code_sections",
76-
sections=[
77-
Section.Code(Op.JUMPF[i + 1] if i < (MAX_CODE_SECTIONS - 1) else Op.STOP)
78-
for i in range(MAX_CODE_SECTIONS)
79-
],
80-
)
81-
)
82-
]
83-
+ [Section.Data(data="0x00")],
84-
),
85-
# TODO: Add more valid scenarios
86-
]
87-
8823
INVALID: List[Container] = [
8924
Container(
9025
name="single_code_section_no_data_section",
@@ -202,7 +137,7 @@
202137
Container(
203138
name="no_code_section",
204139
sections=[
205-
Section(kind=Kind.TYPE, data=bytes([0] * 4)),
140+
Section(kind=SectionKind.TYPE, data=bytes([0] * 4)),
206141
Section.Data("0x00"),
207142
],
208143
auto_type_section=AutoSection.NONE,
@@ -471,8 +406,8 @@
471406
Container(
472407
name="too_many_type_sections",
473408
sections=[
474-
Section(kind=Kind.TYPE, data="0x00000000"),
475-
Section(kind=Kind.TYPE, data="0x00000000"),
409+
Section(kind=SectionKind.TYPE, data="0x00000000"),
410+
Section(kind=SectionKind.TYPE, data="0x00000000"),
476411
Section.Code(Op.STOP),
477412
],
478413
auto_type_section=AutoSection.NONE,
@@ -481,7 +416,7 @@
481416
Container(
482417
name="empty_type_section",
483418
sections=[
484-
Section(kind=Kind.TYPE, data="0x"),
419+
Section(kind=SectionKind.TYPE, data="0x"),
485420
Section.Code(Op.STOP),
486421
],
487422
auto_type_section=AutoSection.NONE,
@@ -491,7 +426,7 @@
491426
Container(
492427
name="type_section_too_small_1",
493428
sections=[
494-
Section(kind=Kind.TYPE, data="0x00"),
429+
Section(kind=SectionKind.TYPE, data="0x00"),
495430
Section.Code(Op.STOP),
496431
],
497432
auto_type_section=AutoSection.NONE,
@@ -500,7 +435,7 @@
500435
Container(
501436
name="type_section_too_small_2",
502437
sections=[
503-
Section(kind=Kind.TYPE, data="0x000000"),
438+
Section(kind=SectionKind.TYPE, data="0x000000"),
504439
Section.Code(Op.STOP),
505440
],
506441
auto_type_section=AutoSection.NONE,
@@ -509,7 +444,7 @@
509444
Container(
510445
name="type_section_too_big",
511446
sections=[
512-
Section(kind=Kind.TYPE, data="0x0000000000"),
447+
Section(kind=SectionKind.TYPE, data="0x0000000000"),
513448
Section.Code(Op.STOP),
514449
],
515450
auto_type_section=AutoSection.NONE,
@@ -523,7 +458,7 @@
523458
EIP-4750 Valid and Invalid Containers
524459
"""
525460

526-
VALID += [
461+
VALID = [
527462
Container(
528463
name="single_code_section_max_stack_size",
529464
sections=[
@@ -633,7 +568,7 @@
633568
Container(
634569
name="single_code_section_incomplete_type",
635570
sections=[
636-
Section(kind=Kind.TYPE, data="0x00", custom_size=2),
571+
Section(kind=SectionKind.TYPE, data="0x00", custom_size=2),
637572
Section.Code(Op.STOP),
638573
],
639574
validity_error=EOFException.INVALID_SECTION_BODIES_SIZE,

tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_container_validation.py

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
EOF validation tests for EIP-3540 container format
33
"""
44

5+
56
import pytest
67

78
from ethereum_test_tools import EOFTestFiller
89
from ethereum_test_tools import Opcodes as Op
9-
from ethereum_test_tools.eof.v1 import Container, EOFException, Section
10+
from ethereum_test_tools.eof.v1 import Container, ContainerKind, Section
11+
from ethereum_test_tools.eof.v1.constants import MAX_CODE_SECTIONS
12+
from ethereum_test_tools.exceptions import EOFException
1013

1114
from .. import EOF_FORK_NAME
1215

@@ -51,3 +54,79 @@ def test_version_validation(
5154
data=bytes(code),
5255
expect_exception=None if version == 1 else EOFException.INVALID_VERSION,
5356
)
57+
58+
59+
@pytest.mark.parametrize("plus_data", [False, True])
60+
@pytest.mark.parametrize("plus_container", [False, True])
61+
def test_single_code_section(
62+
eof_test: EOFTestFiller,
63+
plus_data: bool,
64+
plus_container: bool,
65+
):
66+
"""
67+
Verify EOF container maximum number of code sections
68+
"""
69+
sections = [Section.Code(Op.RETURNCONTRACT[0](0, 0) if plus_container else Op.STOP)]
70+
if plus_container:
71+
sections.append(
72+
Section.Container(
73+
container=Container(
74+
sections=[
75+
Section.Code(Op.JUMPF[i + 1] if i < (MAX_CODE_SECTIONS - 1) else Op.STOP)
76+
for i in range(MAX_CODE_SECTIONS)
77+
],
78+
)
79+
)
80+
)
81+
if plus_data:
82+
sections.append(Section.Data(data=b"\0"))
83+
eof_test(
84+
data=Container(
85+
name="max_code_sections",
86+
sections=sections,
87+
kind=ContainerKind.INITCODE if plus_container else ContainerKind.RUNTIME,
88+
),
89+
)
90+
91+
92+
@pytest.mark.parametrize("plus_data", [False, True])
93+
@pytest.mark.parametrize("plus_container", [False, True])
94+
def test_max_code_sections(
95+
eof_test: EOFTestFiller,
96+
plus_data: bool,
97+
plus_container: bool,
98+
):
99+
"""
100+
Verify EOF container maximum number of code sections
101+
"""
102+
if plus_container:
103+
sections = [
104+
Section.Code(
105+
Op.JUMPF[i + 1] if i < (MAX_CODE_SECTIONS - 1) else Op.RETURNCONTRACT[0](0, 0)
106+
)
107+
for i in range(MAX_CODE_SECTIONS)
108+
]
109+
sections.append(
110+
Section.Container(
111+
container=Container(
112+
sections=[
113+
Section.Code(Op.JUMPF[i + 1] if i < (MAX_CODE_SECTIONS - 1) else Op.STOP)
114+
for i in range(MAX_CODE_SECTIONS)
115+
],
116+
)
117+
)
118+
)
119+
else:
120+
sections = [
121+
Section.Code(Op.JUMPF[i + 1] if i < (MAX_CODE_SECTIONS - 1) else Op.STOP)
122+
for i in range(MAX_CODE_SECTIONS)
123+
]
124+
if plus_data:
125+
sections.append(Section.Data(data=b"\0"))
126+
eof_test(
127+
data=Container(
128+
name="max_code_sections",
129+
sections=sections,
130+
kind=ContainerKind.INITCODE if plus_container else ContainerKind.RUNTIME,
131+
),
132+
)

tests/prague/eip7692_eof_v1/eip7620_eof_create/test_subcontainer_validation.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ def test_simple_create_from_creation(
6363
):
6464
"""Simple EOF creation from a create transaction container"""
6565
eof_state_test(
66-
deploy_tx=True,
6766
data=Container(
6867
sections=[
6968
returncontract_code_section,
7069
stop_sub_container,
7170
],
71+
kind=ContainerKind.INITCODE,
7272
),
7373
container_post=Account(storage={slot_code_worked: value_code_worked}),
7474
)
@@ -85,22 +85,24 @@ def test_reverting_container(
8585
):
8686
"""Test revert containers"""
8787
eof_state_test(
88-
deploy_tx=zero_section == returncontract_code_section,
8988
data=Container(
9089
sections=[
9190
zero_section,
9291
revert_sub_container,
9392
],
93+
kind=ContainerKind.INITCODE
94+
if zero_section == returncontract_code_section
95+
else ContainerKind.RUNTIME,
9496
),
9597
container_post=Account(storage={slot_code_worked: value_code_worked}),
9698
)
9799

98100

99101
@pytest.mark.parametrize(
100-
"code_section,first_sub_container",
102+
"code_section,first_sub_container,container_kind",
101103
[
102-
(eofcreate_code_section, returncontract_sub_container),
103-
(returncontract_code_section, stop_sub_container),
104+
(eofcreate_code_section, returncontract_sub_container, ContainerKind.RUNTIME),
105+
(returncontract_code_section, stop_sub_container, ContainerKind.INITCODE),
104106
],
105107
ids=["eofcreate", "returncontract"],
106108
)
@@ -114,6 +116,7 @@ def test_orphan_container(
114116
code_section: Section,
115117
first_sub_container: Container,
116118
extra_sub_container: Container,
119+
container_kind: ContainerKind,
117120
):
118121
"""Test orphaned containers"""
119122
eof_test(
@@ -123,43 +126,61 @@ def test_orphan_container(
123126
first_sub_container,
124127
extra_sub_container,
125128
],
126-
kind=ContainerKind.INITCODE,
129+
kind=container_kind,
127130
),
128131
expect_exception=EOFException.ORPHAN_SUBCONTAINER,
129132
)
130133

131134

132135
@pytest.mark.parametrize(
133-
"code_section,sub_container",
136+
"code_section,sub_container,container_kind",
134137
[
135138
pytest.param(
136139
eofcreate_code_section,
137140
returncontract_sub_container,
141+
ContainerKind.RUNTIME,
138142
id="EOFCREATE/RETURNCONTRACT",
139143
),
140-
pytest.param(returncontract_code_section, stop_sub_container, id="RETURNCONTRACT/STOP"),
141144
pytest.param(
142-
returncontract_code_section, return_sub_container, id="RETURNCONTRACT/RETURN"
145+
returncontract_code_section,
146+
stop_sub_container,
147+
ContainerKind.INITCODE,
148+
id="RETURNCONTRACT/STOP",
143149
),
144-
pytest.param(eofcreate_code_section, revert_sub_container, id="EOFCREATE/REVERT"),
145150
pytest.param(
146-
returncontract_code_section, revert_sub_container, id="RETURNCONTRACT/REVERT"
151+
returncontract_code_section,
152+
return_sub_container,
153+
ContainerKind.INITCODE,
154+
id="RETURNCONTRACT/RETURN",
155+
),
156+
pytest.param(
157+
eofcreate_code_section,
158+
revert_sub_container,
159+
ContainerKind.RUNTIME,
160+
id="EOFCREATE/REVERT",
161+
),
162+
pytest.param(
163+
returncontract_code_section,
164+
revert_sub_container,
165+
ContainerKind.INITCODE,
166+
id="RETURNCONTRACT/REVERT",
147167
),
148168
],
149169
)
150170
def test_container_combos_valid(
151171
eof_state_test: EOFStateTestFiller,
152172
code_section: Section,
153173
sub_container: Container,
174+
container_kind: ContainerKind,
154175
):
155176
"""Test valid subcontainer reference / opcode combos"""
156177
eof_state_test(
157-
deploy_tx=code_section == returncontract_code_section,
158178
data=Container(
159179
sections=[
160180
code_section,
161181
sub_container,
162182
],
183+
kind=container_kind,
163184
),
164185
container_post=Account(storage={slot_code_worked: value_code_worked}),
165186
)
@@ -238,5 +259,6 @@ def test_container_both_kinds_different_sub(eof_test: EOFTestFiller):
238259
returncontract_sub_container,
239260
stop_sub_container,
240261
],
262+
kind=ContainerKind.INITCODE,
241263
),
242264
)

0 commit comments

Comments
 (0)