Skip to content

test_selfdestruct_zero_balance_no_state_gas()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_selfdestruct.py::test_selfdestruct_zero_balance_no_state_gas@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_zero_balance_no_state_gas --fork Amsterdam

Test SELFDESTRUCT with zero balance charges no state gas.

When the originating contract has zero balance, no value is transferred, so no new account is created even if the beneficiary does not exist.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_selfdestruct.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
@pytest.mark.valid_from("EIP8037")
def test_selfdestruct_zero_balance_no_state_gas(
    state_test: StateTestFiller,
    pre: Alloc,
) -> None:
    """
    Test SELFDESTRUCT with zero balance charges no state gas.

    When the originating contract has zero balance, no value is
    transferred, so no new account is created even if the beneficiary
    does not exist.
    """
    # Non-existent beneficiary but contract has zero balance
    beneficiary = 0xDEAD

    contract = pre.deploy_contract(
        code=Op.SELFDESTRUCT(beneficiary),
        balance=0,
    )

    tx = Transaction(
        to=contract,
        state_gas_reservoir=0,
        sender=pre.fund_eoa(),
    )

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.