Skip to content

test_selfdestruct_new_beneficiary_state_gas()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_selfdestruct.py::test_selfdestruct_new_beneficiary_state_gas@c74f1a67.

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_new_beneficiary_state_gas --fork Amsterdam

Test SELFDESTRUCT to a non-existent beneficiary bills NEW_ACCOUNT.

A contract with nonzero balance self-destructs to a non-alive beneficiary, charging new-account state gas. The charge is billed identically whether drawn from the reservoir (out-of-cap tx) or spilled into gas_left (in-cap tx): the block bills NEW_ACCOUNT in the state dimension and the beneficiary is created.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_selfdestruct.py
36
37
38
39
40
41
42
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
@pytest.mark.parametrize("funding", ["reservoir", "spill"])
@pytest.mark.valid_from("EIP8037")
def test_selfdestruct_new_beneficiary_state_gas(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    funding: str,
) -> None:
    """
    Test SELFDESTRUCT to a non-existent beneficiary bills NEW_ACCOUNT.

    A contract with nonzero balance self-destructs to a non-alive
    beneficiary, charging new-account state gas. The charge is billed
    identically whether drawn from the reservoir (out-of-cap tx) or
    spilled into `gas_left` (in-cap tx): the block bills NEW_ACCOUNT in
    the state dimension and the beneficiary is created.
    """
    new_account_state_gas = fork.gas_costs().NEW_ACCOUNT
    beneficiary = 0xDEAD

    contract = pre.deploy_contract(
        code=Op.SELFDESTRUCT(beneficiary), balance=1
    )
    tx = Transaction(
        to=contract,
        sender=pre.fund_eoa(),
        state_gas_reservoir=(
            new_account_state_gas if funding == "reservoir" else 0
        ),
    )

    state_test(
        pre=pre,
        post={
            beneficiary: Account(balance=1),
            contract: Account(balance=0),
        },
        tx=tx,
        blockchain_test_header_verify=Header(gas_used=new_account_state_gas),
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.