Skip to content

test_reservoir_returned_on_revert()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_reservoir_returned_on_revert@5c024cbb.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_reservoir_returned_on_revert --fork Amsterdam

Test state gas reservoir is returned to parent on child revert.

The child contract reverts. The parent should recover the reservoir and be able to use it for its own SSTORE.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
@pytest.mark.valid_from("EIP8037")
def test_reservoir_returned_on_revert(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test state gas reservoir is returned to parent on child revert.

    The child contract reverts. The parent should recover the
    reservoir and be able to use it for its own SSTORE.
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    child = pre.deploy_contract(code=Op.REVERT(0, 0))

    parent_storage = Storage()
    parent = pre.deploy_contract(
        code=(
            # Call child that reverts (returns 0)
            Op.POP(Op.CALL(gas=100_000, address=child))
            # Parent can still use reservoir for its own SSTORE
            + Op.SSTORE(parent_storage.store_next(1), 1)
        ),
    )

    tx = Transaction(
        to=parent,
        state_gas_reservoir=sstore_state_gas,
        sender=pre.fund_eoa(),
    )

    post = {parent: Account(storage=parent_storage)}
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.