Skip to content

test_charge_draws_entirely_from_reservoir()

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

Test state gas is drawn entirely from the reservoir.

When the reservoir has enough gas for the SSTORE state cost, gas_left should not be reduced by the state charge. Verify by performing a regular-gas-heavy computation after the SSTORE.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
@pytest.mark.valid_from("EIP8037")
def test_charge_draws_entirely_from_reservoir(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test state gas is drawn entirely from the reservoir.

    When the reservoir has enough gas for the SSTORE state cost,
    gas_left should not be reduced by the state charge. Verify by
    performing a regular-gas-heavy computation after the SSTORE.
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    storage = Storage()
    contract = pre.deploy_contract(
        code=(
            # SSTORE draws state gas from reservoir
            Op.SSTORE(storage.store_next(1), 1)
            # Remaining gas_left is available for regular ops
            + Op.SSTORE(
                storage.store_next(1),
                Op.ADD(1, 0),  # Cheap regular-gas op
            )
        ),
    )

    # Provide exact state gas in the reservoir
    tx = Transaction(
        to=contract,
        state_gas_reservoir=sstore_state_gas * 2,
        sender=pre.fund_eoa(),
    )

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.