Skip to content

test_refund_with_reservoir_state_gas()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py::test_refund_with_reservoir_state_gas@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_refund_with_reservoir_state_gas --fork Amsterdam

Test refund when state gas is drawn from reservoir.

When state gas comes from the reservoir, the refund still applies. The refund_counter accumulates state + regular gas refunds, and the ⅕ cap uses tx_gas_used_before_refund which accounts for both dimensions. An SSTORE zero-to-nonzero-to-zero sequence should refund correctly.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
@EIPChecklist.GasRefundsChanges.Test.RefundCalculation()
@pytest.mark.valid_from("EIP8037")
def test_refund_with_reservoir_state_gas(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test refund when state gas is drawn from reservoir.

    When state gas comes from the reservoir, the refund still applies.
    The refund_counter accumulates state + regular gas refunds, and
    the 1/5 cap uses tx_gas_used_before_refund which accounts for
    both dimensions. An SSTORE zero-to-nonzero-to-zero sequence
    should refund correctly.
    """
    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 = Transaction(
        to=contract,
        state_gas_reservoir=sstore_state_gas,
        sender=pre.fund_eoa(),
    )

    # Slot 0 restored to zero
    post = {contract: Account(storage={0: 0})}
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.