Skip to content

test_intrinsic_gas_cost()

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

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
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
@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 3 forks.