Skip to content

test_refund_cap_includes_state_gas()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py::test_refund_cap_includes_state_gas@c74f1a67.

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

Test the ⅕ refund cap includes state gas used from gas_left.

When state gas is drawn from gas_left (no reservoir), it counts toward tx_gas_used_before_refund. The ⅕ refund cap applies to the combined total of regular + state gas consumed. This test performs an SSTORE zero-to-nonzero-to-zero sequence to generate a refund and verifies the transaction succeeds.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
@EIPChecklist.GasRefundsChanges.Test.RefundCalculation()
@pytest.mark.valid_from("EIP8037")
def test_refund_cap_includes_state_gas(
    state_test: StateTestFiller,
    pre: Alloc,
) -> None:
    """
    Test the 1/5 refund cap includes state gas used from gas_left.

    When state gas is drawn from gas_left (no reservoir), it counts
    toward tx_gas_used_before_refund. The 1/5 refund cap applies to
    the combined total of regular + state gas consumed. This test
    performs an SSTORE zero-to-nonzero-to-zero sequence to generate
    a refund and verifies the transaction succeeds.
    """
    contract = pre.deploy_contract(
        code=(Op.SSTORE(0, 1) + Op.SSTORE(0, 0)),
    )

    # No reservoir — all gas from gas_left, refund cap applies
    tx = Transaction(
        to=contract,
        state_gas_reservoir=0,
        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.