Skip to content

test_intrinsic_gas_cost()

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

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
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
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
@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.