Skip to content

test_call_access_gas()

Documentation for tests/amsterdam/eip8038_state_access_gas_cost_increase/test_call_gas.py::test_call_access_gas@2119b382.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8038_state_access_gas_cost_increase/test_call_gas.py::test_call_access_gas --fork Amsterdam

Measure the access cost of every call opcode with no value transfer.

EIP-8038 charges COLD_ACCOUNT_ACCESS (3,000) cold and WARM_ACCESS (100) warm for all four call opcodes.

Source code in tests/amsterdam/eip8038_state_access_gas_cost_increase/test_call_gas.py
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
@EIPChecklist.GasCostChanges.Test.GasUpdatesMeasurement()
@pytest.mark.with_all_call_opcodes()
@pytest.mark.parametrize("warm", [False, True], ids=["cold", "warm"])
def test_call_access_gas(
    state_test: StateTestFiller,
    env: Environment,
    pre: Alloc,
    fork: Fork,
    call_opcode: Op,
    warm: bool,
) -> None:
    """
    Measure the access cost of every call opcode with no value transfer.

    EIP-8038 charges ``COLD_ACCOUNT_ACCESS`` (3,000) cold and
    ``WARM_ACCESS`` (100) warm for all four call opcodes.
    """
    gas_costs = fork.gas_costs()

    target = pre.deploy_contract(Op.STOP)

    measured_code = call_opcode(gas=0, address=target)
    cost_metadata = call_opcode(address_warm=warm)
    measure_address = _measure_call(
        pre, fork, measured_code, call_opcode(address_warm=False)
    )

    expected_gas = (
        gas_costs.WARM_ACCESS if warm else gas_costs.COLD_ACCOUNT_ACCESS
    )
    # Cross-check the framework opcode model agrees with the formula.
    assert expected_gas == cost_metadata.gas_cost(fork)

    access_list = (
        [AccessList(address=target, storage_keys=[])] if warm else None
    )
    tx = Transaction(
        to=measure_address,
        sender=pre.fund_eoa(),
        access_list=access_list,
    )

    post = {measure_address: Account(storage={0: expected_gas})}
    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 8 parametrized test cases across 1 fork.