Skip to content

test_selfdestruct_to_self_in_create_tx()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_selfdestruct.py::test_selfdestruct_to_self_in_create_tx@5c024cbb.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_selfdestruct.py::test_selfdestruct_to_self_in_create_tx --fork Amsterdam

Test SELFDESTRUCT to self in the transaction the contract was created.

When a contract created in the current transaction SELFDESTRUCTs to itself, the balance is burned and the account is deleted. No new account state gas is charged since the beneficiary already exists.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_selfdestruct.py
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
@pytest.mark.valid_from("EIP8037")
def test_selfdestruct_to_self_in_create_tx(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test SELFDESTRUCT to self in the transaction the contract was created.

    When a contract created in the current transaction SELFDESTRUCTs
    to itself, the balance is burned and the account is deleted. No
    new account state gas is charged since the beneficiary already
    exists.
    """
    gas_limit_cap = fork.transaction_gas_limit_cap()
    assert gas_limit_cap is not None

    inner_code = Op.SELFDESTRUCT(Op.ADDRESS)

    contract = pre.deploy_contract(
        code=(
            Op.MSTORE(
                0,
                int.from_bytes(bytes(inner_code), "big")
                << (256 - 8 * len(inner_code)),
            )
            + Op.POP(Op.CREATE(1, 0, len(inner_code)))
        ),
        balance=1,
    )

    tx = Transaction(
        to=contract,
        gas_limit=gas_limit_cap * 2,
        sender=pre.fund_eoa(),
    )

    state_test(pre=pre, post={}, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.