Skip to content

test_intrinsic_gas_cost()

Documentation for tests/prague/eip7702_set_code_tx/test_gas.py::test_intrinsic_gas_cost@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/prague/eip7702_set_code_tx/test_gas.py::test_intrinsic_gas_cost --fork Bogota

Test sending a transaction with the exact intrinsic gas required and also insufficient gas.

Source code in tests/prague/eip7702_set_code_tx/test_gas.py
@pytest.mark.inclusion_test
@pytest.mark.parametrize(
    **gas_test_parameter_args(include_pre_authorized=False)
)
@pytest.mark.parametrize(
    "valid",
    [True, pytest.param(False, marks=pytest.mark.exception_test)],
)
def test_intrinsic_gas_cost(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    authorization_list: List[AuthorizationTuple],
    data: bytes,
    access_list: List[AccessList],
    sender: EOA,
    valid: bool,
) -> None:
    """
    Test sending a transaction with the exact intrinsic gas required and also
    insufficient gas.
    """
    # Calculate the intrinsic gas cost of the authorizations, by default the
    # full empty account cost is charged for each authorization.
    intrinsic_gas = fork.transaction_intrinsic_cost_calculator()(
        calldata=data,
        access_list=access_list,
        authorization_list_or_count=authorization_list,
    )

    tx_gas = intrinsic_gas
    if not valid:
        tx_gas -= 1

    test_code = Op.STOP
    test_code_address = pre.deploy_contract(test_code)

    tx = Transaction(
        gas_limit=tx_gas,
        to=test_code_address,
        value=0,
        data=data,
        authorization_list=authorization_list,
        access_list=access_list,
        sender=sender,
        error=TransactionException.INTRINSIC_GAS_TOO_LOW
        if not valid
        else None,
    )

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

Parametrized Test Cases

This test generates 66 parametrized test cases across 4 forks.