Skip to content

test_sstore_restoration_nonzero_no_state_refund()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py::test_sstore_restoration_nonzero_no_state_refund@2119b382.

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

Test nonzero-to-nonzero-to-original restoration has no state gas refund.

When a slot holds a nonzero original value, changing it and restoring it never involves state gas (no state growth occurred), so only regular gas refunds apply.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
@pytest.mark.valid_from("EIP8037")
def test_sstore_restoration_nonzero_no_state_refund(
    state_test: StateTestFiller,
    pre: Alloc,
) -> None:
    """
    Test nonzero-to-nonzero-to-original restoration has no state gas refund.

    When a slot holds a nonzero original value, changing it and
    restoring it never involves state gas (no state growth occurred),
    so only regular gas refunds apply.
    """
    contract = pre.deploy_contract(
        code=(Op.SSTORE(0, 2) + Op.SSTORE(0, 1)),
        storage={0: 1},
    )

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

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.