Skip to content

test_call_value_transfer_existing_account_no_state_gas()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_call_value_transfer_existing_account_no_state_gas@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_call_value_transfer_existing_account_no_state_gas --fork Bogota

Test CALL with value to existing account charges no state gas.

A CALL that transfers value to an already-alive account does not create new state, so no state gas is charged.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
@pytest.mark.valid_from("EIP8037")
def test_call_value_transfer_existing_account_no_state_gas(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test CALL with value to existing account charges no state gas.

    A CALL that transfers value to an already-alive account does not
    create new state, so no state gas is charged.
    """
    # Existing target account
    target = pre.fund_eoa(amount=1)

    parent_storage = Storage()

    call_slot = parent_storage.store_next(1)
    parent_code = Op.SSTORE(
        call_slot,
        Op.CALL(gas=0, address=target, value=1, value_transfer=True),
        original_value=1,
        current_value=1,
        new_value=1,
        key_warm=False,
    )
    parent = pre.deploy_contract(
        code=parent_code, balance=1, storage={call_slot: 1}
    )

    state_gas = parent_code.state_cost(fork)
    execution_gas = (
        fork.transaction_intrinsic_cost_calculator()()
        + parent_code.execution_cost(fork)
        - fork.call_value_stipend()
    )
    expected_gas_used = max(execution_gas, state_gas)
    assert state_gas == 0 and expected_gas_used == execution_gas, (
        "expected no state gas and execution gas to dominate"
    )

    tx = Transaction(
        to=parent,
        state_gas_reservoir=0,
        sender=pre.fund_eoa(),
    )

    post = {
        parent: Account(balance=0, storage=parent_storage),
        target: Account(balance=2),
    }
    state_test(
        pre=pre,
        post=post,
        tx=tx,
        blockchain_test_header_verify=Header(gas_used=expected_gas_used),
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 2 forks.