Skip to content

test_sstore_clear_refund_reversal()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py::test_sstore_clear_refund_reversal@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py::test_sstore_clear_refund_reversal --fork Amsterdam

Test clearing a nonzero slot then un-clearing reverses the refund.

When a slot with a nonzero original value is cleared (set to zero), the clear refund is granted. If the slot is then set back to a nonzero value, the clear refund is reversed via refund_counter.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
@pytest.mark.valid_from("EIP8037")
def test_sstore_clear_refund_reversal(
    state_test: StateTestFiller,
    pre: Alloc,
) -> None:
    """
    Test clearing a nonzero slot then un-clearing reverses the refund.

    When a slot with a nonzero original value is cleared (set to zero),
    the clear refund is granted. If the slot is then set back to a
    nonzero value, the clear refund is reversed via refund_counter.
    """
    contract = pre.deploy_contract(
        code=(Op.SSTORE(0, 0) + Op.SSTORE(0, 2)),
        storage={0: 1},
    )

    tx = Transaction(
        to=contract,
        state_gas_reservoir=0,
        sender=pre.fund_eoa(),
    )

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.