Skip to content

test_tx_gas_limit_block_boundary()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py::test_tx_gas_limit_block_boundary@622620d8.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py::test_tx_gas_limit_block_boundary --fork Amsterdam

Reject tx whose gas_limit exceeds the block gas_limit.

EIP-8037 inclusion rule: min(TX_MAX_GAS_LIMIT, tx.gas) <= execution_gas_available and tx.gas <= state_gas_available. At block start both budgets equal block_gas_limit.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
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
671
672
673
674
675
676
677
678
679
@pytest.mark.inclusion_test
@pytest.mark.parametrize(
    "tx_gas_delta, expected_exception",
    [
        pytest.param(
            -1,
            None,
            id="gas_one_below",
            marks=EIPChecklist.BlockLevelConstraint.Test.Boundary.Under(),
        ),
        pytest.param(
            0,
            None,
            id="gas_equal",
            marks=EIPChecklist.BlockLevelConstraint.Test.Boundary.Exact(),
        ),
        pytest.param(
            1,
            TransactionException.GAS_ALLOWANCE_EXCEEDED,
            id="gas_one_above",
            marks=[
                pytest.mark.exception_test,
                EIPChecklist.BlockLevelConstraint.Test.Boundary.Over(),
            ],
        ),
        pytest.param(
            2,
            TransactionException.GAS_ALLOWANCE_EXCEEDED,
            id="gas_two_above",
            marks=[
                pytest.mark.exception_test,
                EIPChecklist.BlockLevelConstraint.Test.Boundary.Over(),
            ],
        ),
    ],
)
@pytest.mark.parametrize(
    "block_gas_limit",
    [
        pytest.param(0x0FFFFFD, id="bgl_0x0fffffd"),
        pytest.param(0x01FFFFE, id="bgl_0x01ffffe"),
    ],
)
@pytest.mark.parametrize(
    "tx_type, contract_creation",
    [
        pytest.param(0, False, id="type_0_call"),
        pytest.param(0, True, id="type_0_create"),
        pytest.param(1, False, id="type_1_call"),
        pytest.param(1, True, id="type_1_create"),
        pytest.param(2, False, id="type_2_call"),
        pytest.param(2, True, id="type_2_create"),
        pytest.param(3, False, id="type_3_blob"),
        pytest.param(4, False, id="type_4_set_code"),
    ],
)
@EIPChecklist.BlockLevelConstraint.Test.Content.TransactionTypes()
@pytest.mark.valid_from("EIP8037")
def test_tx_gas_limit_block_boundary(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    tx_type: int,
    contract_creation: bool,
    block_gas_limit: int,
    tx_gas_delta: int,
    expected_exception: TransactionException | None,
) -> None:
    """
    Reject tx whose ``gas_limit`` exceeds the block ``gas_limit``.

    EIP-8037 inclusion rule: ``min(TX_MAX_GAS_LIMIT, tx.gas) <=
    execution_gas_available`` and ``tx.gas <= state_gas_available``.
    At block start both budgets equal ``block_gas_limit``.
    """
    gas_limit = block_gas_limit + tx_gas_delta
    gas_price = 10
    sender = pre.fund_eoa(amount=gas_limit * gas_price + 10**18)

    to = None if contract_creation else pre.fund_eoa(amount=0)
    access_list = None
    authorization_list = None
    blob_versioned_hashes = None
    extra_fee_args: dict = {}
    if tx_type == 1:
        access_list = [AccessList(address=Address(1), storage_keys=[Hash(0)])]
    elif tx_type == 2:
        access_list = []
    elif tx_type == 3:
        blob_versioned_hashes = add_kzg_version(
            [Hash(1)], EIP4844_Spec.BLOB_COMMITMENT_VERSION_KZG
        )
        extra_fee_args["max_fee_per_blob_gas"] = 1
    elif tx_type == 4:
        authorization_list = [
            AuthorizationTuple(
                signer=pre.fund_eoa(amount=0), address=Address(1)
            )
        ]

    if tx_type in (0, 1):
        fee_args: dict = {"gas_price": gas_price}
    else:
        fee_args = {
            "max_fee_per_gas": gas_price,
            "max_priority_fee_per_gas": 0,
        }
    fee_args.update(extra_fee_args)

    tx = Transaction(
        ty=tx_type,
        sender=sender,
        to=to,
        gas_limit=gas_limit,
        access_list=access_list,
        authorization_list=authorization_list,
        blob_versioned_hashes=blob_versioned_hashes,
        error=expected_exception,
        **fee_args,
    )

    blockchain_test(
        genesis_environment=Environment(gas_limit=block_gas_limit),
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                gas_limit=block_gas_limit,
                exception=expected_exception,
            )
        ],
        post={},
    )

Parametrized Test Cases

This test generates 64 parametrized test cases across 1 fork.