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

Pin the CALL new-account state charge at its exact-fit spill boundary. At exact_fit the charge just fits and the target is materialized; one gas short the caller frame goes out of gas, so nothing is created and the value transfer is rolled back.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
@pytest.mark.parametrize(
    "gas_delta",
    [pytest.param(0, id="exact_fit"), pytest.param(-1, id="one_short")],
)
@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 spill
    boundary. At `exact_fit` the charge just fits and the target is
    materialized; one gas short the caller frame goes out of gas, so
    nothing is created and the value transfer is rolled back.
    """
    gas_costs = fork.gas_costs()
    target = 0xDEAD
    caller_code = Op.CALL(gas=0, address=target, value=1) + Op.STOP
    caller = pre.deploy_contract(code=caller_code, balance=1)

    exact_fit = (
        fork.transaction_intrinsic_cost_calculator()()
        + caller_code.gas_cost(fork)
        + gas_costs.CALL_VALUE
        + gas_costs.NEW_ACCOUNT
    )
    post: dict
    if gas_delta == 0:
        gas_used = exact_fit - gas_costs.CALL_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.