Skip to content

test_create_insufficient_balance_returns_reservoir()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_create_insufficient_balance_returns_reservoir@c74f1a67.

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

Test CREATE with insufficient balance returns reservoir to parent.

When CREATE is called but the sender doesn't have enough balance for the endowment, the operation fails and both gas and state gas reservoir are returned to the parent frame.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
@pytest.mark.valid_from("EIP8037")
def test_create_insufficient_balance_returns_reservoir(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test CREATE with insufficient balance returns reservoir to parent.

    When CREATE is called but the sender doesn't have enough balance
    for the endowment, the operation fails and both gas and state gas
    reservoir are returned to the parent frame.
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    storage = Storage()
    contract = pre.deploy_contract(
        code=(
            Op.MSTORE(0, int.from_bytes(bytes(Op.STOP), "big") << 248)
            # CREATE with 1 wei endowment — fails (contract has 0 balance)
            + Op.SSTORE(
                storage.store_next(0, "create_fails"),
                Op.CREATE(1, 0, 1),
            )
            # Reservoir returned — SSTORE still works
            + Op.SSTORE(storage.store_next(1, "sstore_after"), 1)
        ),
    )

    tx = Transaction(
        to=contract,
        state_gas_reservoir=sstore_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.