From 0bcbb6ab8d6d4f8a67e7136cc53a9a5ead92f77e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 26 Aug 2024 13:41:47 +0200 Subject: [PATCH] new(tests): migrate EOF "embedded container" tests Migrate EOFTests/efValidation/EOF1_embedded_container_.json. --- converted-ethereum-tests.txt | 1 + .../test_subcontainer_validation.py | 111 +++++++++++++++--- 2 files changed, 95 insertions(+), 17 deletions(-) diff --git a/converted-ethereum-tests.txt b/converted-ethereum-tests.txt index 1cc2ed0111..81d3d49a27 100644 --- a/converted-ethereum-tests.txt +++ b/converted-ethereum-tests.txt @@ -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 diff --git a/tests/prague/eip7692_eof_v1/eip7620_eof_create/test_subcontainer_validation.py b/tests/prague/eip7692_eof_v1/eip7620_eof_create/test_subcontainer_validation.py index 1b5e586ca4..12e6065ad3 100644 --- a/tests/prague/eip7692_eof_v1/eip7620_eof_create/test_subcontainer_validation.py +++ b/tests/prague/eip7692_eof_v1/eip7620_eof_create/test_subcontainer_validation.py @@ -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, ], ) @@ -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", ), @@ -572,7 +565,7 @@ 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 @@ -580,6 +573,64 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep ), 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=[ @@ -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""", @@ -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=[ @@ -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):