Skip to content

Commit

Permalink
fix(tests): EOF: always use Container
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Sep 3, 2024
1 parent 0b30805 commit 51b8181
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_max_size(
)
assert len(code) == MAX_INITCODE_SIZE + over_limit
eof_test(
data=bytes(code),
data=code,
expect_exception=None if over_limit == 0 else EOFException.CONTAINER_SIZE_ABOVE_LIMIT,
)

Expand All @@ -59,7 +59,7 @@ def test_above_max_size_raw(
"""
code = Op.INVALID * size
eof_test(
data=bytes(code),
data=Container(raw_bytes=bytes(code)),
expect_exception=EOFException.CONTAINER_SIZE_ABOVE_LIMIT,
)

Expand Down Expand Up @@ -109,6 +109,6 @@ def test_section_after_end_of_container(
Verify EOF container is invalid if any of sections declares above container size
"""
eof_test(
data=bytes(code),
data=code,
expect_exception=EOFException.INVALID_SECTION_BODIES_SIZE,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
EOF validation tests for EIP-3540 container format
"""


import pytest

from ethereum_test_tools import EOFException, EOFTestFiller
Expand Down Expand Up @@ -154,7 +153,7 @@ def test_valid_containers(
container.validity_error is None
), f"Valid container with validity error: {container.validity_error}"
eof_test(
data=bytes(container),
data=container,
)


Expand Down Expand Up @@ -1098,7 +1097,7 @@ def test_invalid_containers(
"""
assert container.validity_error is not None, "Invalid container without validity error"
eof_test(
data=bytes(container),
data=container,
expect_exception=container.validity_error,
)

Expand All @@ -1117,7 +1116,7 @@ def test_magic_validation(
code[0] = magic_0
code[1] = magic_1
eof_test(
data=bytes(code),
data=Container(raw_bytes=bytes(code)),
expect_exception=None if magic_0 == 0xEF and magic_1 == 0 else EOFException.INVALID_MAGIC,
)

Expand All @@ -1133,7 +1132,7 @@ def test_version_validation(
code = bytearray(bytes(VALID_CONTAINER))
code[2] = version
eof_test(
data=bytes(code),
data=Container(raw_bytes=bytes(code)),
expect_exception=None if version == 1 else EOFException.INVALID_VERSION,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
),
pytest.param(
# Type section size incomplete
bytes.fromhex("ef00010100"),
Container(raw_bytes=bytes.fromhex("ef00010100")),
[EOFException.INCOMPLETE_SECTION_SIZE, EOFException.INVALID_TYPE_SECTION_SIZE],
id="EOF1I3540_0011_type_section_size_incomplete",
),
Expand Down Expand Up @@ -101,109 +101,113 @@
),
pytest.param(
# No data section after code section size
bytes.fromhex("ef00010100040200010001"),
Container(raw_bytes=bytes.fromhex("ef00010100040200010001")),
EOFException.MISSING_HEADERS_TERMINATOR,
id="EOF1I3540_0017_no_data_section_after_code_section_size",
),
pytest.param(
# No data size
bytes.fromhex("ef0001010004020001000104"),
Container(raw_bytes=bytes.fromhex("ef0001010004020001000104")),
[EOFException.MISSING_HEADERS_TERMINATOR, EOFException.INCOMPLETE_DATA_HEADER],
id="EOF1I3540_0018_no_data_size",
),
pytest.param(
# Data size incomplete
bytes.fromhex("ef000101000402000100010400"),
Container(raw_bytes=bytes.fromhex("ef000101000402000100010400")),
[EOFException.INCOMPLETE_SECTION_SIZE, EOFException.INCOMPLETE_DATA_HEADER],
id="EOF1I3540_0019_data_size_incomplete",
),
pytest.param(
# No section terminator after data section size
bytes.fromhex("ef00010100040200010001040002"),
Container(raw_bytes=bytes.fromhex("ef00010100040200010001040002")),
EOFException.MISSING_HEADERS_TERMINATOR,
id="EOF1I3540_0020_no_section_terminator_after_data_section_size",
),
pytest.param(
# No type section contents
bytes.fromhex("ef0001010004020001000104000200"),
Container(raw_bytes=bytes.fromhex("ef0001010004020001000104000200")),
EOFException.INVALID_SECTION_BODIES_SIZE,
id="EOF1I3540_0021_no_type_section_contents",
),
pytest.param(
# Type section contents (no outputs and max stack)
bytes.fromhex("ef000101000402000100010400020000"),
Container(raw_bytes=bytes.fromhex("ef000101000402000100010400020000")),
EOFException.INVALID_SECTION_BODIES_SIZE,
id="EOF1I3540_0022_invalid_type_section_no_outputs_and_max_stack",
),
pytest.param(
# Type section contents (no max stack)
bytes.fromhex("ef00010100040200010001040002000000"),
Container(raw_bytes=bytes.fromhex("ef00010100040200010001040002000000")),
EOFException.INVALID_SECTION_BODIES_SIZE,
id="EOF1I3540_0023_invalid_type_section_no_max_stack",
),
pytest.param(
# Type section contents (max stack incomplete)
bytes.fromhex("ef0001010004020001000104000200000000"),
Container(raw_bytes=bytes.fromhex("ef0001010004020001000104000200000000")),
EOFException.INVALID_SECTION_BODIES_SIZE,
id="EOF1I3540_0024_invalid_type_section_max_stack_incomplete",
),
pytest.param(
# No code section contents
bytes.fromhex("ef000101000402000100010400020000000000"),
Container(raw_bytes=bytes.fromhex("ef000101000402000100010400020000000000")),
EOFException.INVALID_SECTION_BODIES_SIZE,
id="EOF1I3540_0025_no_code_section_contents",
),
pytest.param(
# Code section contents incomplete
bytes.fromhex("ef0001010004020001002904000000000000027f"),
Container(raw_bytes=bytes.fromhex("ef0001010004020001002904000000000000027f")),
EOFException.INVALID_SECTION_BODIES_SIZE,
id="EOF1I3540_0026_code_section_contents_incomplete",
),
pytest.param(
# Trailing bytes after code section
bytes.fromhex("ef0001 010004 0200010001 040000 00 00800000 fe aabbcc"),
Container(
raw_bytes=bytes.fromhex("ef0001 010004 0200010001 040000 00 00800000 fe aabbcc")
),
EOFException.INVALID_SECTION_BODIES_SIZE,
id="EOF1I3540_0027_trailing_bytes_after_code_section",
),
pytest.param(
# Trailing bytes after code section with wrong first section type
bytes.fromhex("ef0001 010004 0200010001 040000 00 00000000 fe aabbcc"),
Container(
raw_bytes=bytes.fromhex("ef0001 010004 0200010001 040000 00 00000000 fe aabbcc")
),
EOFException.INVALID_FIRST_SECTION_TYPE,
id="EOF1I3540_0027_trailing_bytes_after_code_section_with_wrong_first_section_type",
),
pytest.param(
# Empty code section
bytes.fromhex("ef000101000402000100000400000000000000"),
Container(raw_bytes=bytes.fromhex("ef000101000402000100000400000000000000")),
EOFException.ZERO_SECTION_SIZE,
id="EOF1I3540_0028_empty_code_section",
),
pytest.param(
# Code section preceding type section
bytes.fromhex("ef000102000100010100040400020000000000feaabb"),
Container(raw_bytes=bytes.fromhex("ef000102000100010100040400020000000000feaabb")),
[EOFException.MISSING_TYPE_HEADER, EOFException.UNEXPECTED_HEADER_KIND],
id="EOF1I3540_0030_code_section_preceding_type_section",
),
pytest.param(
# Data section preceding type section
bytes.fromhex("ef000104000201000402000100010000000000feaabb"),
Container(raw_bytes=bytes.fromhex("ef000104000201000402000100010000000000feaabb")),
[EOFException.MISSING_TYPE_HEADER, EOFException.UNEXPECTED_HEADER_KIND],
id="EOF1I3540_0031_data_section_preceding_type_section",
),
pytest.param(
# Data section preceding code section
bytes.fromhex("ef000101000404000202000100010000000000feaabb"),
Container(raw_bytes=bytes.fromhex("ef000101000404000202000100010000000000feaabb")),
[EOFException.MISSING_CODE_HEADER, EOFException.UNEXPECTED_HEADER_KIND],
id="EOF1I3540_0032_data_section_preceding_code_section",
),
pytest.param(
# Data section without code section
bytes.fromhex("ef00010100040400020000000000aabb"),
Container(raw_bytes=bytes.fromhex("ef00010100040400020000000000aabb")),
[EOFException.MISSING_CODE_HEADER, EOFException.UNEXPECTED_HEADER_KIND],
id="EOF1I3540_0033_data_section_without_code_section",
),
pytest.param(
# No data section
bytes.fromhex("ef000101000402000100010000000000fe"),
Container(raw_bytes=bytes.fromhex("ef000101000402000100010000000000fe")),
[EOFException.MISSING_DATA_SECTION, EOFException.UNEXPECTED_HEADER_KIND],
id="EOF1I3540_0034_no_data_section",
),
Expand All @@ -222,91 +226,99 @@
),
pytest.param(
# Trailing bytes after data section with wrong first section type
bytes.fromhex("ef0001 010004 0200010001 040002 00 00000000 fe aabbccdd"),
Container(
raw_bytes=bytes.fromhex("ef0001 010004 0200010001 040002 00 00000000 fe aabbccdd")
),
EOFException.INVALID_FIRST_SECTION_TYPE,
id="EOF1I3540_0035_trailing_bytes_after_data_section_with_wrong_first_section_type",
),
pytest.param(
# Multiple data sections
bytes.fromhex("ef000101000402000100010400020400020000000000feaabbaabb"),
Container(
raw_bytes=bytes.fromhex("ef000101000402000100010400020400020000000000feaabbaabb")
),
[EOFException.MISSING_TERMINATOR, EOFException.UNEXPECTED_HEADER_KIND],
id="EOF1I3540_0036_multiple_data_sections",
),
pytest.param(
# Multiple code and data sections
bytes.fromhex("ef000101000802000200010001040002040002000000000000000000fefeaabbaabb"),
Container(
raw_bytes=bytes.fromhex(
"ef000101000802000200010001040002040002000000000000000000fefeaabbaabb"
)
),
[EOFException.MISSING_TERMINATOR, EOFException.UNEXPECTED_HEADER_KIND],
id="EOF1I3540_0037_multiple_code_and_data_sections",
),
pytest.param(
# Unknown section ID (at the beginning)
bytes.fromhex("ef000105000101000402000100010400000000000000fe"),
Container(raw_bytes=bytes.fromhex("ef000105000101000402000100010400000000000000fe")),
[EOFException.MISSING_TYPE_HEADER, EOFException.UNEXPECTED_HEADER_KIND],
id="EOF1I3540_0038_unknown_section_id_at_the_beginning_05",
),
pytest.param(
# Unknown section ID (at the beginning)
bytes.fromhex("ef000106000101000402000100010400000000000000fe"),
Container(raw_bytes=bytes.fromhex("ef000106000101000402000100010400000000000000fe")),
[EOFException.MISSING_TYPE_HEADER, EOFException.UNEXPECTED_HEADER_KIND],
id="EOF1I3540_0039_unknown_section_id_at_the_beginning_06",
),
pytest.param(
# Unknown section ID (at the beginning)
bytes.fromhex("ef0001ff000101000402000100010400000000000000fe"),
Container(raw_bytes=bytes.fromhex("ef0001ff000101000402000100010400000000000000fe")),
[EOFException.MISSING_TYPE_HEADER, EOFException.UNEXPECTED_HEADER_KIND],
id="EOF1I3540_0040_unknown_section_id_at_the_beginning_ff",
),
pytest.param(
# Unknown section ID (after types section)
bytes.fromhex("ef000101000405000102000100010400000000000000fe"),
Container(raw_bytes=bytes.fromhex("ef000101000405000102000100010400000000000000fe")),
[EOFException.MISSING_CODE_HEADER, EOFException.UNEXPECTED_HEADER_KIND],
id="EOF1I3540_0041_unknown_section_id_after_types_section_05",
),
pytest.param(
# Unknown section ID (after types section)
bytes.fromhex("ef000101000406000102000100010400000000000000fe"),
Container(raw_bytes=bytes.fromhex("ef000101000406000102000100010400000000000000fe")),
[EOFException.MISSING_CODE_HEADER, EOFException.UNEXPECTED_HEADER_KIND],
id="EOF1I3540_0042_unknown_section_id_after_types_section_06",
),
pytest.param(
# Unknown section ID (after types section)
bytes.fromhex("ef0001010004ff000102000100010400000000000000fe"),
Container(raw_bytes=bytes.fromhex("ef0001010004ff000102000100010400000000000000fe")),
[EOFException.MISSING_CODE_HEADER, EOFException.UNEXPECTED_HEADER_KIND],
id="EOF1I3540_0043_unknown_section_id_after_types_section_ff",
),
pytest.param(
# Unknown section ID (after code section)
bytes.fromhex("ef000101000402000100010500010400000000000000fe"),
Container(raw_bytes=bytes.fromhex("ef000101000402000100010500010400000000000000fe")),
[EOFException.MISSING_DATA_SECTION, EOFException.UNEXPECTED_HEADER_KIND],
id="EOF1I3540_0044_unknown_section_id_after_code_section_05",
),
pytest.param(
# Unknown section ID (after code section)
bytes.fromhex("ef000101000402000100010600010400000000000000fe"),
Container(raw_bytes=bytes.fromhex("ef000101000402000100010600010400000000000000fe")),
[EOFException.MISSING_DATA_SECTION, EOFException.UNEXPECTED_HEADER_KIND],
id="EOF1I3540_0045_unknown_section_id_after_code_section_06",
),
pytest.param(
# Unknown section ID (after code section)
bytes.fromhex("ef00010100040200010001ff00010400000000000000fe"),
Container(raw_bytes=bytes.fromhex("ef00010100040200010001ff00010400000000000000fe")),
[EOFException.MISSING_DATA_SECTION, EOFException.UNEXPECTED_HEADER_KIND],
id="EOF1I3540_0046_unknown_section_id_after_code_section_ff",
),
pytest.param(
# Unknown section ID (after data section)
bytes.fromhex("ef000101000402000100010400000500010000000000fe"),
Container(raw_bytes=bytes.fromhex("ef000101000402000100010400000500010000000000fe")),
[EOFException.MISSING_TERMINATOR, EOFException.UNEXPECTED_HEADER_KIND],
id="EOF1I3540_0047_unknown_section_id_after_data_section_05",
),
pytest.param(
# Unknown section ID (after data section)
bytes.fromhex("ef000101000402000100010400000600010000000000fe"),
Container(raw_bytes=bytes.fromhex("ef000101000402000100010400000600010000000000fe")),
[EOFException.MISSING_TERMINATOR, EOFException.UNEXPECTED_HEADER_KIND],
id="EOF1I3540_0048_unknown_section_id_after_data_section_06",
),
pytest.param(
# Unknown section ID (after data section)
bytes.fromhex("ef00010100040200010001040000ff00010000000000fe"),
Container(raw_bytes=bytes.fromhex("ef00010100040200010001040000ff00010000000000fe")),
[EOFException.MISSING_TERMINATOR, EOFException.UNEXPECTED_HEADER_KIND],
id="EOF1I3540_0049_unknown_section_id_after_data_section_ff",
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def test_truncated_container_without_data(
container = Container(sections=[Section.Code(Op.INVALID + Op.INVALID)])
bytecode = bytes(container)
eof_test(
data=bytecode[: len(bytecode) - truncation_len],
data=Container(raw_bytes=bytecode[: len(bytecode) - truncation_len]),
expect_exception=exception,
)

Expand All @@ -180,6 +180,6 @@ def test_truncated_container_with_data(
container = Container(sections=[Section.Code(Op.INVALID), Section.Data("aabb")])
bytecode = bytes(container)
eof_test(
data=bytecode[: len(bytecode) - truncation_len],
data=Container(raw_bytes=bytecode[: len(bytecode) - truncation_len]),
expect_exception=exception,
)
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,6 @@ def test_eof_validity(
Test EOF container validaiton for features around EIP-4750 / Functions / Code Sections
"""
eof_test(
data=bytes(container),
data=container,
expect_exception=container.validity_error,
)
10 changes: 7 additions & 3 deletions tests/prague/eip7692_eof_v1/eip7069_extcall/test_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ def gas_test(
if warm_gas is None:
warm_gas = cold_gas

sender = pre.fund_eoa(10**18)
sender = pre.fund_eoa()

address_baseline = pre.deploy_contract(setup_code + tear_down_code)
address_subject = pre.deploy_contract(setup_code + subject_code + tear_down_code)
address_baseline = pre.deploy_contract(
setup_code + tear_down_code, evm_code_type=EVMCodeType.EOF_V1
)
address_subject = pre.deploy_contract(
setup_code + subject_code + tear_down_code, evm_code_type=EVMCodeType.EOF_V1
)
address_legacy_harness = pre.deploy_contract(
code=(
# warm subject and baseline without executing
Expand Down
Loading

0 comments on commit 51b8181

Please sign in to comment.