Skip to content

test_selfdestruct_clears_return_data()

Documentation for tests/byzantium/eip211_return_data/test_selfdestruct.py::test_selfdestruct_clears_return_data@343274cc.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/byzantium/eip211_return_data/test_selfdestruct.py::test_selfdestruct_clears_return_data --fork Amsterdam

Test SELFDESTRUCT returns empty data after an inner call returns data.

The selfdestructing contract first performs a call that leaves 32 bytes in its own return-data buffer. The outer caller must still observe empty return data from the selfdestructing call.

Source code in tests/byzantium/eip211_return_data/test_selfdestruct.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
@pytest.mark.valid_from("Byzantium")
def test_selfdestruct_clears_return_data(
    state_test: StateTestFiller,
    pre: Alloc,
) -> None:
    """
    Test SELFDESTRUCT returns empty data after an inner call returns data.

    The selfdestructing contract first performs a call that leaves 32 bytes in
    its own return-data buffer. The outer caller must still observe empty
    return data from the selfdestructing call.
    """
    returns_32 = pre.deploy_contract(
        code=Op.MSTORE(0, 0x112233) + Op.RETURN(0, 32)
    )

    selfdestructs = pre.deploy_contract(
        code=Op.POP(Op.CALL(address=returns_32, ret_size=0))
        + Op.SELFDESTRUCT(Op.CALLER)
    )

    caller = pre.deploy_contract(
        code=Op.SSTORE(
            0,
            Op.CALL(address=selfdestructs, ret_size=0),
        )
        + Op.SSTORE(1, Op.RETURNDATASIZE)
    )

    tx = Transaction(sender=pre.fund_eoa(), to=caller)

    state_test(
        pre=pre,
        tx=tx,
        post={caller: Account(storage={0: 1, 1: 0})},
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 12 forks.