Skip to content

test_sstore_refund_scales_with_cpsb()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py::test_sstore_refund_scales_with_cpsb@2119b382.

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

Test SSTORE restoration refund scales with block gas limit.

Zero-to-nonzero-to-zero in the same tx refunds the state gas (64 * cpsb) via refund_counter.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
@pytest.mark.parametrize("block_gas_limit", BLOCK_GAS_LIMITS)
@pytest.mark.valid_from("EIP8037")
def test_sstore_refund_scales_with_cpsb(
    state_test: StateTestFiller,
    pre: Alloc,
    block_gas_limit: int,
    fork: Fork,
) -> None:
    """
    Test SSTORE restoration refund scales with block gas limit.

    Zero-to-nonzero-to-zero in the same tx refunds the state gas
    (64 * cpsb) via refund_counter.
    """
    gas_limit_cap = fork.transaction_gas_limit_cap()
    assert gas_limit_cap is not None
    env = Environment(gas_limit=block_gas_limit)
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    contract = pre.deploy_contract(
        code=(Op.SSTORE(0, 1) + Op.SSTORE(0, 0)),
    )

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

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

Parametrized Test Cases

This test generates 10 parametrized test cases across 1 fork.