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@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_new_beneficiary_account_write_cost --fork Amsterdam

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

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_selfdestruct.py
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
@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`
    regular gas plus the account-creation state gas, and not the
    legacy combined regular 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)

    # Tight budget: slack is less than the legacy 25,000 regular
    # account-creation cost minus `ACCOUNT_WRITE`, so any regular draw
    # beyond `ACCOUNT_WRITE` would OOG. The opcode metadata folds the
    # `ACCOUNT_WRITE` regular cost and the account-creation state gas
    # into `gas_cost`.
    intrinsic = fork.transaction_intrinsic_cost_calculator()()
    tx = Transaction(
        to=victim,
        gas_limit=(intrinsic + victim_code.gas_cost(fork) + 4_000),
        sender=pre.fund_eoa(),
    )

    state_test(pre=pre, post={beneficiary: Account(balance=1)}, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.