Skip to content

test_charge_spills_to_gas_left()

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

Test state gas spills from reservoir to gas_left.

When the reservoir has some gas but not enough to cover the full state charge, the remainder is taken from gas_left. The SSTORE should still succeed.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py
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
@pytest.mark.valid_from("EIP8037")
def test_charge_spills_to_gas_left(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test state gas spills from reservoir to gas_left.

    When the reservoir has some gas but not enough to cover the full
    state charge, the remainder is taken from gas_left. The SSTORE
    should still succeed.
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    storage = Storage()
    contract = pre.deploy_contract(
        code=Op.SSTORE(storage.store_next(1), 1),
    )

    # Provide half the state gas in the reservoir, rest from gas_left
    half_state_gas = sstore_state_gas // 2
    tx = Transaction(
        to=contract,
        state_gas_reservoir=half_state_gas,
        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.