Skip to content

test_selfdestruct_new_beneficiary_account_write_cost()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_selfdestruct.py::test_selfdestruct_new_beneficiary_account_write_cost@622620d8.

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

Verify SELFDESTRUCT to a new beneficiary charges ACCOUNT_WRITE execution gas plus the account-creation state gas, and not the legacy combined execution account-creation cost.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_selfdestruct.py
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
@pytest.mark.valid_from("EIP8037")
def test_selfdestruct_new_beneficiary_account_write_cost(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify SELFDESTRUCT to a new beneficiary charges `ACCOUNT_WRITE`
    execution gas plus the account-creation state gas, and not the
    legacy combined execution account-creation cost.
    """
    beneficiary = pre.fund_eoa(amount=0)

    victim_code = Op.SELFDESTRUCT(beneficiary, account_new=True)
    victim = pre.deploy_contract(code=victim_code, balance=1)

    storage = Storage()
    execution_cost = victim_code.execution_cost(fork)
    state_cost = victim_code.state_cost(fork)

    slot = storage.store_next(1, "subcall_succeeds")

    caller_code = Op.SSTORE(
        slot,
        Op.CALL(gas=execution_cost, address=victim),
        # gas accounting
        key_warm=False,
        original_value=2,
        current_value=2,
        new_value=1,
    )
    caller = pre.deploy_contract(code=caller_code, storage={slot: 2})

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

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.