Skip to content

Commit

Permalink
new(tests): migrate EOF "embedded container" tests
Browse files Browse the repository at this point in the history
Migrate EOFTests/efValidation/EOF1_embedded_container_.json.
  • Loading branch information
chfast committed Aug 26, 2024
1 parent e35feea commit 0bcbb6a
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 17 deletions.
1 change: 1 addition & 0 deletions converted-ethereum-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ GeneralStateTests/stCreate2/call_then_create2_successful_then_returndatasize.jso
([#598](https://github.com/ethereum/execution-spec-tests/pull/598))
EOFTests/EIP3540/validInvalid.json

EOFTests/efValidation/EOF1_embedded_container_.json
EOFTests/efValidation/EOF1_eofcreate_valid_.json
EOFTests/efValidation/EOF1_truncated_section_.json

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,13 @@
code=Op.SSTORE(slot_code_worked, value_code_worked) + Op.RETURNCONTRACT[0](0, 0),
max_stack_height=2,
)
stop_sub_container = Section.Container(container=Container(sections=[Section.Code(code=Op.STOP)]))
return_sub_container = Section.Container(
container=Container(sections=[Section.Code(code=Op.RETURN(0, 0), max_stack_height=2)])
)
revert_sub_container = Section.Container(
container=Container(sections=[Section.Code(code=Op.REVERT(0, 0), max_stack_height=2)])
)
stop_sub_container = Section.Container(Container.Code(Op.STOP))
return_sub_container = Section.Container(Container.Code(Op.RETURN(0, 0)))
revert_sub_container = Section.Container(Container.Code(Op.REVERT(0, 0)))
returncontract_sub_container = Section.Container(
container=Container(
Container(
sections=[
Section.Code(
code=Op.RETURNCONTRACT[0](0, 0),
max_stack_height=2,
),
Section.Code(Op.RETURNCONTRACT[0](0, 0)),
stop_sub_container,
],
)
Expand Down Expand Up @@ -474,9 +467,9 @@ def test_container_both_kinds_different_sub(eof_test: EOFTestFiller):
@pytest.mark.parametrize(
["deepest_container", "exception"],
[
pytest.param(Container(sections=[Section.Code(code=Op.STOP)]), None, id="valid"),
pytest.param(Container.Code(Op.STOP), None, id="valid"),
pytest.param(
Container(sections=[Section.Code(code=Op.PUSH0)]),
Container.Code(code=Op.PUSH0),
EOFException.MISSING_STOP_OPCODE,
id="code-error",
),
Expand Down Expand Up @@ -572,14 +565,72 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
+ Op.POP
+ Op.STOP
),
Section.Container(Container(sections=[Section.Code(Op.INVALID)])),
Section.Container(Container.Code(Op.INVALID)),
],
expected_bytecode="""
ef0001010004020001000b0300010014040000000080000436600060ff6000ec005000ef000101000402
000100010400000000800000fe""",
),
id="EOF1_eofcreate_valid_0",
),
pytest.param(
Container(
sections=[
Section.Code(Op.PUSH1[0] + Op.RJUMP[0] + Op.STOP),
Section.Container(Container.Code(Op.INVALID)),
],
expected_bytecode="""
ef00010100040200010006030001001404000000008000016000e0000000ef0001010004020001000104
00000000800000fe""",
# Originally this test was "valid" because it was created
# before "orphan subcontainer" rule was introduced.
validity_error=EOFException.ORPHAN_SUBCONTAINER,
),
id="EOF1_embedded_container_0",
),
pytest.param(
Container(
sections=[
Section.Code(Op.PUSH1[0] + Op.RJUMP[0] + Op.STOP),
Section.Container(Container.Code(Op.INVALID)),
Section.Data(custom_size=2),
],
expected_bytecode="""
ef00010100040200010006030001001404000200008000016000e0000000ef0001010004020001000104
00000000800000fe""",
# Originally this test was "valid" but against the current spec
# it contains two errors: data section truncated and orphan subcontainer.
validity_error=EOFException.TOPLEVEL_CONTAINER_TRUNCATED,
),
id="EOF1_embedded_container_1",
),
pytest.param(
Container(
sections=[
Section.Code(Op.PUSH1[0] + Op.RJUMP[0] + Op.STOP),
Section.Container(Container.Code(Op.INVALID)),
Section.Data("aabb"),
],
expected_bytecode="""
ef00010100040200010006030001001404000200008000016000e0000000ef0001010004020001000104
00000000800000feaabb""",
# Originally this test was "valid" because it was created
# before "orphan subcontainer" rule was introduced.
validity_error=EOFException.ORPHAN_SUBCONTAINER,
),
id="EOF1_embedded_container_2",
),
pytest.param(
Container(
sections=[
Section.Code(Op.EOFCREATE[0](0, 0, 0, 0) + Op.STOP),
Section.Container("aabbccddeeff"),
],
# The original test has been modified to reference the subcontainer by EOFCREATE.
validity_error=EOFException.INVALID_MAGIC,
),
id="EOF1_embedded_container_3",
),
pytest.param(
Container(
sections=[
Expand All @@ -593,7 +644,7 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
+ Op.STOP
)
]
+ 2 * [Section.Container(Container(sections=[Section.Code(Op.INVALID)]))],
+ 2 * [Section.Container(Container.Code(Op.INVALID))],
expected_bytecode="""
ef0001010004020001000b03000200140014040000000080000436600060ff6000ec015000ef00010100
0402000100010400000000800000feef000101000402000100010400000000800000fe""",
Expand All @@ -603,6 +654,22 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
),
id="EOF1_eofcreate_valid_1",
),
pytest.param(
Container(
sections=[
Section.Code(Op.PUSH1[0] + Op.RJUMP[0] + Op.STOP),
Section.Container(Container.Code(Op.INVALID)),
Section.Container(Container.Code(Op.PUSH0 + Op.PUSH0 + Op.RETURN)),
],
expected_bytecode="""
ef000101000402000100060300020014001604000000008000016000e0000000ef000101000402000100
010400000000800000feef0001010004020001000304000000008000025f5ff3""",
# Originally this test was "valid" because it was created
# before "orphan subcontainer" rule was introduced.
validity_error=EOFException.ORPHAN_SUBCONTAINER,
),
id="EOF1_embedded_container_4",
),
pytest.param(
Container(
sections=[
Expand All @@ -616,13 +683,23 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
+ Op.STOP
)
]
+ 256 * [Section.Container(Container(sections=[Section.Code(Op.INVALID)]))],
+ 256 * [Section.Container(Container.Code(Op.INVALID))],
# Originally this test was "valid" because it was created
# before "orphan subcontainer" rule was introduced.
validity_error=EOFException.ORPHAN_SUBCONTAINER,
),
id="EOF1_eofcreate_valid_2",
),
pytest.param(
Container(
sections=[Section.Code(Op.PUSH1[0] + Op.RJUMP[0] + Op.STOP)]
+ 256 * [Section.Container(Container.Code(Op.INVALID))],
# Originally this test was "valid" because it was created
# before "orphan subcontainer" rule was introduced.
validity_error=EOFException.ORPHAN_SUBCONTAINER,
),
id="EOF1_embedded_container_5",
),
],
)
def test_migrated_eofcreate(eof_test: EOFTestFiller, container: Container):
Expand Down

0 comments on commit 0bcbb6a

Please sign in to comment.