Skip to content

test_call_new_account_state_gas_boundary()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_call_new_account_state_gas_boundary@622620d8.

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

Pin the CALL new-account state charge at its exact-fit boundary.

With gas_limit set explicitly the transaction has no reservoir, so the charge spills from gas_left. At exact_fit the target is materialized; one gas short the caller frame goes out of gas and the value transfer is rolled back.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
@pytest.mark.parametrize(
    "gas_delta",
    [pytest.param(0, id="exact_fit"), pytest.param(-1, id="one_short")],
)
@EIPChecklist.GasCostChanges.Test.OutOfGas()
@pytest.mark.valid_from("EIP8037")
def test_call_new_account_state_gas_boundary(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    gas_delta: int,
) -> None:
    """
    Pin the CALL new-account state charge at its exact-fit boundary.

    With `gas_limit` set explicitly the transaction has no reservoir, so
    the charge spills from `gas_left`. At `exact_fit` the target is
    materialized; one gas short the caller frame goes out of gas and the
    value transfer is rolled back.
    """
    target = pre.nonexistent_account()
    caller_code = (
        Op.CALL(
            gas=0,
            address=target,
            value=1,
            value_transfer=True,
            account_new=True,
        )
        + Op.STOP
    )
    caller = pre.deploy_contract(code=caller_code, balance=1)

    state_gas = caller_code.state_cost(fork)
    execution_gas = (
        fork.transaction_intrinsic_cost_calculator()()
        + caller_code.execution_cost(fork)
    )
    exact_fit = execution_gas + state_gas

    post: dict
    if gas_delta == 0:
        gas_used = exact_fit - fork.call_value_stipend()
        post = {target: Account(balance=1), caller: Account(balance=0)}
    else:
        gas_used = exact_fit + gas_delta
        post = {target: Account.NONEXISTENT, caller: Account(balance=1)}

    tx = Transaction(
        to=caller,
        gas_limit=exact_fit + gas_delta,
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(cumulative_gas_used=gas_used),
    )

    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.