Skip to content

Commit 51b8181

Browse files
committed
fix(tests): EOF: always use Container
1 parent 0b30805 commit 51b8181

File tree

7 files changed

+176
-179
lines changed

7 files changed

+176
-179
lines changed

tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_container_size.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_max_size(
4141
)
4242
assert len(code) == MAX_INITCODE_SIZE + over_limit
4343
eof_test(
44-
data=bytes(code),
44+
data=code,
4545
expect_exception=None if over_limit == 0 else EOFException.CONTAINER_SIZE_ABOVE_LIMIT,
4646
)
4747

@@ -59,7 +59,7 @@ def test_above_max_size_raw(
5959
"""
6060
code = Op.INVALID * size
6161
eof_test(
62-
data=bytes(code),
62+
data=Container(raw_bytes=bytes(code)),
6363
expect_exception=EOFException.CONTAINER_SIZE_ABOVE_LIMIT,
6464
)
6565

@@ -109,6 +109,6 @@ def test_section_after_end_of_container(
109109
Verify EOF container is invalid if any of sections declares above container size
110110
"""
111111
eof_test(
112-
data=bytes(code),
112+
data=code,
113113
expect_exception=EOFException.INVALID_SECTION_BODIES_SIZE,
114114
)

tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_container_validation.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
EOF validation tests for EIP-3540 container format
33
"""
44

5-
65
import pytest
76

87
from ethereum_test_tools import EOFException, EOFTestFiller
@@ -154,7 +153,7 @@ def test_valid_containers(
154153
container.validity_error is None
155154
), f"Valid container with validity error: {container.validity_error}"
156155
eof_test(
157-
data=bytes(container),
156+
data=container,
158157
)
159158

160159

@@ -1098,7 +1097,7 @@ def test_invalid_containers(
10981097
"""
10991098
assert container.validity_error is not None, "Invalid container without validity error"
11001099
eof_test(
1101-
data=bytes(container),
1100+
data=container,
11021101
expect_exception=container.validity_error,
11031102
)
11041103

@@ -1117,7 +1116,7 @@ def test_magic_validation(
11171116
code[0] = magic_0
11181117
code[1] = magic_1
11191118
eof_test(
1120-
data=bytes(code),
1119+
data=Container(raw_bytes=bytes(code)),
11211120
expect_exception=None if magic_0 == 0xEF and magic_1 == 0 else EOFException.INVALID_MAGIC,
11221121
)
11231122

@@ -1133,7 +1132,7 @@ def test_version_validation(
11331132
code = bytearray(bytes(VALID_CONTAINER))
11341133
code[2] = version
11351134
eof_test(
1136-
data=bytes(code),
1135+
data=Container(raw_bytes=bytes(code)),
11371136
expect_exception=None if version == 1 else EOFException.INVALID_VERSION,
11381137
)
11391138

tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_migrated_valid_invalid.py

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
),
7171
pytest.param(
7272
# Type section size incomplete
73-
bytes.fromhex("ef00010100"),
73+
Container(raw_bytes=bytes.fromhex("ef00010100")),
7474
[EOFException.INCOMPLETE_SECTION_SIZE, EOFException.INVALID_TYPE_SECTION_SIZE],
7575
id="EOF1I3540_0011_type_section_size_incomplete",
7676
),
@@ -101,109 +101,113 @@
101101
),
102102
pytest.param(
103103
# No data section after code section size
104-
bytes.fromhex("ef00010100040200010001"),
104+
Container(raw_bytes=bytes.fromhex("ef00010100040200010001")),
105105
EOFException.MISSING_HEADERS_TERMINATOR,
106106
id="EOF1I3540_0017_no_data_section_after_code_section_size",
107107
),
108108
pytest.param(
109109
# No data size
110-
bytes.fromhex("ef0001010004020001000104"),
110+
Container(raw_bytes=bytes.fromhex("ef0001010004020001000104")),
111111
[EOFException.MISSING_HEADERS_TERMINATOR, EOFException.INCOMPLETE_DATA_HEADER],
112112
id="EOF1I3540_0018_no_data_size",
113113
),
114114
pytest.param(
115115
# Data size incomplete
116-
bytes.fromhex("ef000101000402000100010400"),
116+
Container(raw_bytes=bytes.fromhex("ef000101000402000100010400")),
117117
[EOFException.INCOMPLETE_SECTION_SIZE, EOFException.INCOMPLETE_DATA_HEADER],
118118
id="EOF1I3540_0019_data_size_incomplete",
119119
),
120120
pytest.param(
121121
# No section terminator after data section size
122-
bytes.fromhex("ef00010100040200010001040002"),
122+
Container(raw_bytes=bytes.fromhex("ef00010100040200010001040002")),
123123
EOFException.MISSING_HEADERS_TERMINATOR,
124124
id="EOF1I3540_0020_no_section_terminator_after_data_section_size",
125125
),
126126
pytest.param(
127127
# No type section contents
128-
bytes.fromhex("ef0001010004020001000104000200"),
128+
Container(raw_bytes=bytes.fromhex("ef0001010004020001000104000200")),
129129
EOFException.INVALID_SECTION_BODIES_SIZE,
130130
id="EOF1I3540_0021_no_type_section_contents",
131131
),
132132
pytest.param(
133133
# Type section contents (no outputs and max stack)
134-
bytes.fromhex("ef000101000402000100010400020000"),
134+
Container(raw_bytes=bytes.fromhex("ef000101000402000100010400020000")),
135135
EOFException.INVALID_SECTION_BODIES_SIZE,
136136
id="EOF1I3540_0022_invalid_type_section_no_outputs_and_max_stack",
137137
),
138138
pytest.param(
139139
# Type section contents (no max stack)
140-
bytes.fromhex("ef00010100040200010001040002000000"),
140+
Container(raw_bytes=bytes.fromhex("ef00010100040200010001040002000000")),
141141
EOFException.INVALID_SECTION_BODIES_SIZE,
142142
id="EOF1I3540_0023_invalid_type_section_no_max_stack",
143143
),
144144
pytest.param(
145145
# Type section contents (max stack incomplete)
146-
bytes.fromhex("ef0001010004020001000104000200000000"),
146+
Container(raw_bytes=bytes.fromhex("ef0001010004020001000104000200000000")),
147147
EOFException.INVALID_SECTION_BODIES_SIZE,
148148
id="EOF1I3540_0024_invalid_type_section_max_stack_incomplete",
149149
),
150150
pytest.param(
151151
# No code section contents
152-
bytes.fromhex("ef000101000402000100010400020000000000"),
152+
Container(raw_bytes=bytes.fromhex("ef000101000402000100010400020000000000")),
153153
EOFException.INVALID_SECTION_BODIES_SIZE,
154154
id="EOF1I3540_0025_no_code_section_contents",
155155
),
156156
pytest.param(
157157
# Code section contents incomplete
158-
bytes.fromhex("ef0001010004020001002904000000000000027f"),
158+
Container(raw_bytes=bytes.fromhex("ef0001010004020001002904000000000000027f")),
159159
EOFException.INVALID_SECTION_BODIES_SIZE,
160160
id="EOF1I3540_0026_code_section_contents_incomplete",
161161
),
162162
pytest.param(
163163
# Trailing bytes after code section
164-
bytes.fromhex("ef0001 010004 0200010001 040000 00 00800000 fe aabbcc"),
164+
Container(
165+
raw_bytes=bytes.fromhex("ef0001 010004 0200010001 040000 00 00800000 fe aabbcc")
166+
),
165167
EOFException.INVALID_SECTION_BODIES_SIZE,
166168
id="EOF1I3540_0027_trailing_bytes_after_code_section",
167169
),
168170
pytest.param(
169171
# Trailing bytes after code section with wrong first section type
170-
bytes.fromhex("ef0001 010004 0200010001 040000 00 00000000 fe aabbcc"),
172+
Container(
173+
raw_bytes=bytes.fromhex("ef0001 010004 0200010001 040000 00 00000000 fe aabbcc")
174+
),
171175
EOFException.INVALID_FIRST_SECTION_TYPE,
172176
id="EOF1I3540_0027_trailing_bytes_after_code_section_with_wrong_first_section_type",
173177
),
174178
pytest.param(
175179
# Empty code section
176-
bytes.fromhex("ef000101000402000100000400000000000000"),
180+
Container(raw_bytes=bytes.fromhex("ef000101000402000100000400000000000000")),
177181
EOFException.ZERO_SECTION_SIZE,
178182
id="EOF1I3540_0028_empty_code_section",
179183
),
180184
pytest.param(
181185
# Code section preceding type section
182-
bytes.fromhex("ef000102000100010100040400020000000000feaabb"),
186+
Container(raw_bytes=bytes.fromhex("ef000102000100010100040400020000000000feaabb")),
183187
[EOFException.MISSING_TYPE_HEADER, EOFException.UNEXPECTED_HEADER_KIND],
184188
id="EOF1I3540_0030_code_section_preceding_type_section",
185189
),
186190
pytest.param(
187191
# Data section preceding type section
188-
bytes.fromhex("ef000104000201000402000100010000000000feaabb"),
192+
Container(raw_bytes=bytes.fromhex("ef000104000201000402000100010000000000feaabb")),
189193
[EOFException.MISSING_TYPE_HEADER, EOFException.UNEXPECTED_HEADER_KIND],
190194
id="EOF1I3540_0031_data_section_preceding_type_section",
191195
),
192196
pytest.param(
193197
# Data section preceding code section
194-
bytes.fromhex("ef000101000404000202000100010000000000feaabb"),
198+
Container(raw_bytes=bytes.fromhex("ef000101000404000202000100010000000000feaabb")),
195199
[EOFException.MISSING_CODE_HEADER, EOFException.UNEXPECTED_HEADER_KIND],
196200
id="EOF1I3540_0032_data_section_preceding_code_section",
197201
),
198202
pytest.param(
199203
# Data section without code section
200-
bytes.fromhex("ef00010100040400020000000000aabb"),
204+
Container(raw_bytes=bytes.fromhex("ef00010100040400020000000000aabb")),
201205
[EOFException.MISSING_CODE_HEADER, EOFException.UNEXPECTED_HEADER_KIND],
202206
id="EOF1I3540_0033_data_section_without_code_section",
203207
),
204208
pytest.param(
205209
# No data section
206-
bytes.fromhex("ef000101000402000100010000000000fe"),
210+
Container(raw_bytes=bytes.fromhex("ef000101000402000100010000000000fe")),
207211
[EOFException.MISSING_DATA_SECTION, EOFException.UNEXPECTED_HEADER_KIND],
208212
id="EOF1I3540_0034_no_data_section",
209213
),
@@ -222,91 +226,99 @@
222226
),
223227
pytest.param(
224228
# Trailing bytes after data section with wrong first section type
225-
bytes.fromhex("ef0001 010004 0200010001 040002 00 00000000 fe aabbccdd"),
229+
Container(
230+
raw_bytes=bytes.fromhex("ef0001 010004 0200010001 040002 00 00000000 fe aabbccdd")
231+
),
226232
EOFException.INVALID_FIRST_SECTION_TYPE,
227233
id="EOF1I3540_0035_trailing_bytes_after_data_section_with_wrong_first_section_type",
228234
),
229235
pytest.param(
230236
# Multiple data sections
231-
bytes.fromhex("ef000101000402000100010400020400020000000000feaabbaabb"),
237+
Container(
238+
raw_bytes=bytes.fromhex("ef000101000402000100010400020400020000000000feaabbaabb")
239+
),
232240
[EOFException.MISSING_TERMINATOR, EOFException.UNEXPECTED_HEADER_KIND],
233241
id="EOF1I3540_0036_multiple_data_sections",
234242
),
235243
pytest.param(
236244
# Multiple code and data sections
237-
bytes.fromhex("ef000101000802000200010001040002040002000000000000000000fefeaabbaabb"),
245+
Container(
246+
raw_bytes=bytes.fromhex(
247+
"ef000101000802000200010001040002040002000000000000000000fefeaabbaabb"
248+
)
249+
),
238250
[EOFException.MISSING_TERMINATOR, EOFException.UNEXPECTED_HEADER_KIND],
239251
id="EOF1I3540_0037_multiple_code_and_data_sections",
240252
),
241253
pytest.param(
242254
# Unknown section ID (at the beginning)
243-
bytes.fromhex("ef000105000101000402000100010400000000000000fe"),
255+
Container(raw_bytes=bytes.fromhex("ef000105000101000402000100010400000000000000fe")),
244256
[EOFException.MISSING_TYPE_HEADER, EOFException.UNEXPECTED_HEADER_KIND],
245257
id="EOF1I3540_0038_unknown_section_id_at_the_beginning_05",
246258
),
247259
pytest.param(
248260
# Unknown section ID (at the beginning)
249-
bytes.fromhex("ef000106000101000402000100010400000000000000fe"),
261+
Container(raw_bytes=bytes.fromhex("ef000106000101000402000100010400000000000000fe")),
250262
[EOFException.MISSING_TYPE_HEADER, EOFException.UNEXPECTED_HEADER_KIND],
251263
id="EOF1I3540_0039_unknown_section_id_at_the_beginning_06",
252264
),
253265
pytest.param(
254266
# Unknown section ID (at the beginning)
255-
bytes.fromhex("ef0001ff000101000402000100010400000000000000fe"),
267+
Container(raw_bytes=bytes.fromhex("ef0001ff000101000402000100010400000000000000fe")),
256268
[EOFException.MISSING_TYPE_HEADER, EOFException.UNEXPECTED_HEADER_KIND],
257269
id="EOF1I3540_0040_unknown_section_id_at_the_beginning_ff",
258270
),
259271
pytest.param(
260272
# Unknown section ID (after types section)
261-
bytes.fromhex("ef000101000405000102000100010400000000000000fe"),
273+
Container(raw_bytes=bytes.fromhex("ef000101000405000102000100010400000000000000fe")),
262274
[EOFException.MISSING_CODE_HEADER, EOFException.UNEXPECTED_HEADER_KIND],
263275
id="EOF1I3540_0041_unknown_section_id_after_types_section_05",
264276
),
265277
pytest.param(
266278
# Unknown section ID (after types section)
267-
bytes.fromhex("ef000101000406000102000100010400000000000000fe"),
279+
Container(raw_bytes=bytes.fromhex("ef000101000406000102000100010400000000000000fe")),
268280
[EOFException.MISSING_CODE_HEADER, EOFException.UNEXPECTED_HEADER_KIND],
269281
id="EOF1I3540_0042_unknown_section_id_after_types_section_06",
270282
),
271283
pytest.param(
272284
# Unknown section ID (after types section)
273-
bytes.fromhex("ef0001010004ff000102000100010400000000000000fe"),
285+
Container(raw_bytes=bytes.fromhex("ef0001010004ff000102000100010400000000000000fe")),
274286
[EOFException.MISSING_CODE_HEADER, EOFException.UNEXPECTED_HEADER_KIND],
275287
id="EOF1I3540_0043_unknown_section_id_after_types_section_ff",
276288
),
277289
pytest.param(
278290
# Unknown section ID (after code section)
279-
bytes.fromhex("ef000101000402000100010500010400000000000000fe"),
291+
Container(raw_bytes=bytes.fromhex("ef000101000402000100010500010400000000000000fe")),
280292
[EOFException.MISSING_DATA_SECTION, EOFException.UNEXPECTED_HEADER_KIND],
281293
id="EOF1I3540_0044_unknown_section_id_after_code_section_05",
282294
),
283295
pytest.param(
284296
# Unknown section ID (after code section)
285-
bytes.fromhex("ef000101000402000100010600010400000000000000fe"),
297+
Container(raw_bytes=bytes.fromhex("ef000101000402000100010600010400000000000000fe")),
286298
[EOFException.MISSING_DATA_SECTION, EOFException.UNEXPECTED_HEADER_KIND],
287299
id="EOF1I3540_0045_unknown_section_id_after_code_section_06",
288300
),
289301
pytest.param(
290302
# Unknown section ID (after code section)
291-
bytes.fromhex("ef00010100040200010001ff00010400000000000000fe"),
303+
Container(raw_bytes=bytes.fromhex("ef00010100040200010001ff00010400000000000000fe")),
292304
[EOFException.MISSING_DATA_SECTION, EOFException.UNEXPECTED_HEADER_KIND],
293305
id="EOF1I3540_0046_unknown_section_id_after_code_section_ff",
294306
),
295307
pytest.param(
296308
# Unknown section ID (after data section)
297-
bytes.fromhex("ef000101000402000100010400000500010000000000fe"),
309+
Container(raw_bytes=bytes.fromhex("ef000101000402000100010400000500010000000000fe")),
298310
[EOFException.MISSING_TERMINATOR, EOFException.UNEXPECTED_HEADER_KIND],
299311
id="EOF1I3540_0047_unknown_section_id_after_data_section_05",
300312
),
301313
pytest.param(
302314
# Unknown section ID (after data section)
303-
bytes.fromhex("ef000101000402000100010400000600010000000000fe"),
315+
Container(raw_bytes=bytes.fromhex("ef000101000402000100010400000600010000000000fe")),
304316
[EOFException.MISSING_TERMINATOR, EOFException.UNEXPECTED_HEADER_KIND],
305317
id="EOF1I3540_0048_unknown_section_id_after_data_section_06",
306318
),
307319
pytest.param(
308320
# Unknown section ID (after data section)
309-
bytes.fromhex("ef00010100040200010001040000ff00010000000000fe"),
321+
Container(raw_bytes=bytes.fromhex("ef00010100040200010001040000ff00010000000000fe")),
310322
[EOFException.MISSING_TERMINATOR, EOFException.UNEXPECTED_HEADER_KIND],
311323
id="EOF1I3540_0049_unknown_section_id_after_data_section_ff",
312324
),

tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_section_size.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def test_truncated_container_without_data(
155155
container = Container(sections=[Section.Code(Op.INVALID + Op.INVALID)])
156156
bytecode = bytes(container)
157157
eof_test(
158-
data=bytecode[: len(bytecode) - truncation_len],
158+
data=Container(raw_bytes=bytecode[: len(bytecode) - truncation_len]),
159159
expect_exception=exception,
160160
)
161161

@@ -180,6 +180,6 @@ def test_truncated_container_with_data(
180180
container = Container(sections=[Section.Code(Op.INVALID), Section.Data("aabb")])
181181
bytecode = bytes(container)
182182
eof_test(
183-
data=bytecode[: len(bytecode) - truncation_len],
183+
data=Container(raw_bytes=bytecode[: len(bytecode) - truncation_len]),
184184
expect_exception=exception,
185185
)

tests/prague/eip7692_eof_v1/eip4750_functions/test_code_validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,6 @@ def test_eof_validity(
198198
Test EOF container validaiton for features around EIP-4750 / Functions / Code Sections
199199
"""
200200
eof_test(
201-
data=bytes(container),
201+
data=container,
202202
expect_exception=container.validity_error,
203203
)

tests/prague/eip7692_eof_v1/eip7069_extcall/test_gas.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ def gas_test(
4848
if warm_gas is None:
4949
warm_gas = cold_gas
5050

51-
sender = pre.fund_eoa(10**18)
51+
sender = pre.fund_eoa()
5252

53-
address_baseline = pre.deploy_contract(setup_code + tear_down_code)
54-
address_subject = pre.deploy_contract(setup_code + subject_code + tear_down_code)
53+
address_baseline = pre.deploy_contract(
54+
setup_code + tear_down_code, evm_code_type=EVMCodeType.EOF_V1
55+
)
56+
address_subject = pre.deploy_contract(
57+
setup_code + subject_code + tear_down_code, evm_code_type=EVMCodeType.EOF_V1
58+
)
5559
address_legacy_harness = pre.deploy_contract(
5660
code=(
5761
# warm subject and baseline without executing

0 commit comments

Comments
 (0)