Skip to content

test_selfdestruct_new_beneficiary_header_gas_used()

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

Verify block gas accounting for SELFDESTRUCT to new beneficiary.

A contract with nonzero balance SELFDESTRUCTs to a non-existent beneficiary, charging GAS_NEW_ACCOUNT state gas. The block must be accepted with correct 2D gas accounting in the header.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_selfdestruct.py
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
@pytest.mark.valid_from("EIP8037")
def test_selfdestruct_new_beneficiary_header_gas_used(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify block gas accounting for SELFDESTRUCT to new beneficiary.

    A contract with nonzero balance SELFDESTRUCTs to a non-existent
    beneficiary, charging GAS_NEW_ACCOUNT state gas. The block must
    be accepted with correct 2D gas accounting in the header.
    """
    gas_costs = fork.gas_costs()
    new_account_state_gas = gas_costs.NEW_ACCOUNT

    beneficiary = pre.fund_eoa(amount=0)

    storage = Storage()
    inner = pre.deploy_contract(
        code=Op.SELFDESTRUCT(beneficiary),
        balance=1,
    )
    caller = pre.deploy_contract(
        code=(
            Op.CALL(gas=100_000, address=inner)
            + Op.SSTORE(storage.store_next(1, "completed"), 1)
        ),
    )

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

    blockchain_test(
        pre=pre,
        blocks=[
            Block(txs=[tx]),
        ],
        post={caller: Account(storage=storage)},
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.