Skip to content

test_initcode_revert()

Documentation for tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_eofcreate_failures.py::test_initcode_revert@21fb11c8.

Generate fixtures for these test cases for Osaka with:

fill -v tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_eofcreate_failures.py::test_initcode_revert --fork Osaka

Verifies proper handling of REVERT in initcode.

Source code in tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_eofcreate_failures.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
@pytest.mark.parametrize(
    "revert",
    [
        pytest.param(b"", id="empty"),
        pytest.param(b"\x08\xc3\x79\xa0", id="Error(string)"),
    ],
)
def test_initcode_revert(state_test: StateTestFiller, pre: Alloc, revert: bytes):
    """Verifies proper handling of REVERT in initcode."""
    env = Environment()
    revert_size = len(revert)

    initcode_subcontainer = Container(
        name="Initcode Subcontainer that reverts",
        sections=[
            Section.Code(
                code=Op.MSTORE(0, Op.PUSH32(revert)) + Op.REVERT(32 - revert_size, revert_size),
            ),
        ],
    )

    factory_contract = Container(
        name="factory contract",
        sections=[
            Section.Code(
                code=Op.SSTORE(slot_create_address, Op.EOFCREATE[0](0, 0, 0, 0))
                + Op.SSTORE(slot_returndata_size, Op.RETURNDATASIZE)
                + Op.RETURNDATACOPY(Op.SUB(32, Op.RETURNDATASIZE), 0, Op.RETURNDATASIZE)
                + Op.SSTORE(slot_returndata, Op.MLOAD(0))
                + Op.SSTORE(slot_code_worked, value_code_worked)
                + Op.STOP,
            ),
            Section.Container(container=initcode_subcontainer),
        ],
    )

    sender = pre.fund_eoa()
    contract_address = pre.deploy_contract(code=factory_contract)

    post = {
        contract_address: Account(
            storage={
                slot_create_address: EOFCREATE_FAILURE,
                slot_returndata_size: revert_size,
                slot_returndata: revert,
                slot_code_worked: value_code_worked,
            }
        )
    }
    tx = Transaction(
        to=contract_address,
        gas_limit=10_000_000,
        gas_price=10,
        protected=False,
        sender=sender,
    )
    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) revert
...fork_Osaka-state_test-empty
...fork_Osaka-state_test-Error(string) 08c379a0
...fork_Osaka-blockchain_test_from_state_test-empty
...fork_Osaka-blockchain_test_from_state_test-Error(string) 08c379a0