Skip to content

test_gas_opcode_excludes_reservoir()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_gas_opcode_excludes_reservoir@2119b382.

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

Test GAS opcode returns gas_left only, excluding the reservoir.

The spec states the GAS opcode reports only gas_left. When the reservoir is non-empty, the GAS return value should be less than the total remaining gas (gas_left + reservoir).

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
@pytest.mark.valid_from("EIP8037")
def test_gas_opcode_excludes_reservoir(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test GAS opcode returns gas_left only, excluding the reservoir.

    The spec states the GAS opcode reports only gas_left. When the
    reservoir is non-empty, the GAS return value should be less than
    the total remaining gas (gas_left + reservoir).
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    storage = Storage()
    contract = pre.deploy_contract(
        code=(
            # Store GAS opcode result — should only reflect gas_left
            Op.SSTORE(0, Op.GAS)
            # Store 1 to prove execution reached this point
            + Op.SSTORE(storage.store_next(1), 1)
        ),
    )

    # Provide large reservoir — GAS should NOT include it
    reservoir_gas = sstore_state_gas * 100
    tx = Transaction(
        to=contract,
        state_gas_reservoir=reservoir_gas,
        sender=pre.fund_eoa(),
    )

    # Verify: slot 0 should hold a value <= TX_MAX_GAS_LIMIT
    # (gas_left is capped by TX_MAX_GAS_LIMIT - intrinsic.regular)
    # We can't check the exact value, but we verify the SSTORE
    # succeeded and the contract executed correctly
    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.