Skip to content

test_selfdestruct_new_beneficiary_scales_with_cpsb()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py::test_selfdestruct_new_beneficiary_scales_with_cpsb@5c024cbb.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py::test_selfdestruct_new_beneficiary_scales_with_cpsb --fork Amsterdam

Test SELFDESTRUCT to new beneficiary scales with block gas limit.

Destructing to a non-existent address with balance charges 120 * cpsb of state gas for the new beneficiary account.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
@pytest.mark.parametrize("block_gas_limit", BLOCK_GAS_LIMITS)
@pytest.mark.valid_from("EIP8037")
def test_selfdestruct_new_beneficiary_scales_with_cpsb(
    state_test: StateTestFiller,
    pre: Alloc,
    block_gas_limit: int,
    fork: Fork,
) -> None:
    """
    Test SELFDESTRUCT to new beneficiary scales with block gas limit.

    Destructing to a non-existent address with balance charges
    120 * cpsb of state gas for the new beneficiary account.
    """
    gas_limit_cap = fork.transaction_gas_limit_cap()
    assert gas_limit_cap is not None
    env = Environment(gas_limit=block_gas_limit)
    gas_costs = fork.gas_costs()
    new_account_state_gas = gas_costs.NEW_ACCOUNT

    beneficiary = pre.fund_eoa(0)
    storage = Storage()
    caller = pre.deploy_contract(
        code=(
            Op.SSTORE(
                storage.store_next(1, "selfdestruct_ran"),
                1,
            )
            + Op.SELFDESTRUCT(beneficiary)
        ),
        balance=1,
    )

    tx_gas = min(gas_limit_cap + new_account_state_gas, block_gas_limit)
    tx = Transaction(
        to=caller,
        gas_limit=tx_gas,
        sender=pre.fund_eoa(),
    )

    post = {caller: Account(storage=storage)}
    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 10 parametrized test cases across 1 fork.