Skip to content

test_intrinsic_gas_cost()

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

Generate fixtures for these test cases for Amsterdam with:

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

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
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
@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 3 forks.