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@892e6d1e.

Generate fixtures for these test cases for Amsterdam 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 Amsterdam

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
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
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
@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"
    )
    access_address = Address("0x1234567890123456789012345678901234567890")

    def intrinsic_cost_for_num_storage_keys(storage_key_count: int) -> int:
        return intrinsic_cost(
            access_list=[
                AccessList(
                    address=access_address,
                    storage_keys=[Hash(i) for i in range(storage_key_count)],
                )
            ]
        )

    num_storage_keys = max_count_with_intrinsic_cost_at_most(
        intrinsic_cost_for_num_storage_keys, tx_gas_limit_cap
    ) + int(exceed_tx_gas_limit)
    storage_keys = [Hash(i) for i in range(num_storage_keys)]

    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

This test generates 3 parametrized test cases across 2 forks.