Skip to content

test_tx_gas_limit_cap_access_list_with_diff_keys()

Documentation for tests/osaka/eip7825_transaction_gas_limit_cap/test_tx_gas_limit.py::test_tx_gas_limit_cap_access_list_with_diff_keys@88e9fb8f.

Generate fixtures for these test cases for Osaka with:

fill -v tests/osaka/eip7825_transaction_gas_limit_cap/test_tx_gas_limit.py::test_tx_gas_limit_cap_access_list_with_diff_keys --fork Osaka

Test the transaction gas limit cap behavior for access list with different storage keys.

Source code in tests/osaka/eip7825_transaction_gas_limit_cap/test_tx_gas_limit.py
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
@pytest.mark.parametrize(
    "exceed_tx_gas_limit,correct_intrinsic_cost_in_transaction_gas_limit",
    [
        pytest.param(True, False, marks=pytest.mark.exception_test),
        pytest.param(True, True, marks=pytest.mark.exception_test),
        pytest.param(False, True),
    ],
)
@pytest.mark.valid_from("Osaka")
def test_tx_gas_limit_cap_access_list_with_diff_keys(
    state_test: StateTestFiller,
    exceed_tx_gas_limit: bool,
    correct_intrinsic_cost_in_transaction_gas_limit: bool,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test the transaction gas limit cap behavior for access list with different
    storage keys.
    """
    intrinsic_cost = fork.transaction_intrinsic_cost_calculator()
    tx_gas_limit_cap = fork.transaction_gas_limit_cap()
    assert tx_gas_limit_cap is not None, "Fork does not have a transaction gas limit cap"
    gas_available = tx_gas_limit_cap - intrinsic_cost()

    gas_costs = fork.gas_costs()
    gas_per_address = gas_costs.G_ACCESS_LIST_ADDRESS
    gas_per_storage_key = gas_costs.G_ACCESS_LIST_STORAGE

    gas_after_address = gas_available - gas_per_address
    num_storage_keys = gas_after_address // gas_per_storage_key + int(exceed_tx_gas_limit)

    access_address = Address("0x1234567890123456789012345678901234567890")
    storage_keys = []
    for i in range(num_storage_keys):
        storage_keys.append(Hash(i))

    access_list = [
        AccessList(
            address=access_address,
            storage_keys=storage_keys,
        )
    ]

    correct_intrinsic_cost = intrinsic_cost(access_list=access_list)
    if exceed_tx_gas_limit:
        assert correct_intrinsic_cost > tx_gas_limit_cap, (
            "Correct intrinsic cost should exceed the tx gas limit cap"
        )
    else:
        assert correct_intrinsic_cost <= tx_gas_limit_cap, (
            "Correct intrinsic cost should be less than or equal to the tx gas limit cap"
        )

    tx_gas_limit = (
        correct_intrinsic_cost
        if correct_intrinsic_cost_in_transaction_gas_limit
        else tx_gas_limit_cap
    )

    tx = Transaction(
        to=pre.fund_eoa(),
        gas_limit=tx_gas_limit,
        sender=pre.fund_eoa(),
        access_list=access_list,
        error=TransactionException.GAS_LIMIT_EXCEEDS_MAXIMUM
        if correct_intrinsic_cost_in_transaction_gas_limit and exceed_tx_gas_limit
        else TransactionException.INTRINSIC_GAS_TOO_LOW
        if exceed_tx_gas_limit
        else None,
    )

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

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) exceed_tx_gas_limit correct_intrinsic_cost_in_transaction_gas_limit
...fork_Osaka-state_test-exceed_tx_gas_limit_True-correct_intrinsic_cost_in_transaction_gas_limit_False True False
...fork_Osaka-state_test-exceed_tx_gas_limit_True-correct_intrinsic_cost_in_transaction_gas_limit_True True True
...fork_Osaka-state_test-exceed_tx_gas_limit_False-correct_intrinsic_cost_in_transaction_gas_limit_True False True
...fork_Osaka-blockchain_test_from_state_test-exceed_tx_gas_limit_True-correct_intrinsic_cost_in_transaction_gas_limit_False True False
...fork_Osaka-blockchain_test_from_state_test-exceed_tx_gas_limit_True-correct_intrinsic_cost_in_transaction_gas_limit_True True True
...fork_Osaka-blockchain_test_from_state_test-exceed_tx_gas_limit_False-correct_intrinsic_cost_in_transaction_gas_limit_True False True