Skip to content

test_tx_gas_limit_cap_authorized_tx()

Documentation for tests/osaka/eip7825_transaction_gas_limit_cap/test_tx_gas_limit.py::test_tx_gas_limit_cap_authorized_tx@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_authorized_tx --fork Osaka

Test a transaction limit cap with authorized tx.

Source code in tests/osaka/eip7825_transaction_gas_limit_cap/test_tx_gas_limit.py
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
@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_authorized_tx(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    exceed_tx_gas_limit: bool,
    correct_intrinsic_cost_in_transaction_gas_limit: bool,
) -> None:
    """Test a transaction limit cap with authorized tx."""
    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

    per_empty_account_cost = 25_000
    auth_list_length = gas_available // (gas_per_address + per_empty_account_cost) + int(
        exceed_tx_gas_limit
    )

    # EIP-7702 authorization transaction cost:
    # 21000 + 16 * non-zero calldata bytes + 4 * zero calldata bytes + 1900 *
    # access list storage key count + 2400 * access list address count +
    # PER_EMPTY_ACCOUNT_COST * authorization list length
    #
    # There is no calldata and no storage keys in this test case and the access
    # address list count is equal to the authorization list length
    #
    # total cost = 21000 + (2400 + 25_000) * auth_list_length

    auth_address = pre.deploy_contract(code=Op.STOP)

    auth_signers = [pre.fund_eoa() for _ in range(auth_list_length)]

    access_list = [
        AccessList(
            address=addr,
            storage_keys=[],
        )
        for addr in auth_signers
    ]

    auth_tuples = [
        AuthorizationTuple(
            signer=signer,
            address=auth_address,
            nonce=signer.nonce,
        )
        for signer in auth_signers
    ]

    correct_intrinsic_cost = intrinsic_cost(
        access_list=access_list, authorization_list_or_count=auth_list_length
    )
    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,
        authorization_list=auth_tuples,
        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