Skip to content

test_tx_inclusion_at_regular_gas_block_limit_small()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py::test_tx_inclusion_at_regular_gas_block_limit_small@c74f1a67.

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_inclusion_at_regular_gas_block_limit_small --fork Amsterdam

Probe the regular-gas inclusion boundary with a small-gas tx.

The second tx's gas_limit is the remaining regular budget plus delta. The inclusion check uses strict >, so delta=0 must pass and delta=1 must reject with GAS_ALLOWANCE_EXCEEDED. Catches an off-by-one >= bug.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py
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
@pytest.mark.parametrize(
    "delta",
    [
        pytest.param(0, id="exactly_fits"),
        pytest.param(1, id="exceeds", marks=pytest.mark.exception_test),
    ],
)
# Cumulative block-gas inclusion is a pre-existing rule, not an
# EIP-8037 novelty. Floor is Osaka only because the gas-cap guard
# below relies on EIP-7825's transaction_gas_limit_cap().
@pytest.mark.valid_from("Osaka")
def test_tx_inclusion_at_regular_gas_block_limit_small(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    delta: int,
) -> None:
    """
    Probe the regular-gas inclusion boundary with a small-gas tx.

    The second tx's ``gas_limit`` is the remaining regular budget
    plus ``delta``. The inclusion check uses strict ``>``, so
    ``delta=0`` must pass and ``delta=1`` must reject with
    ``GAS_ALLOWANCE_EXCEEDED``. Catches an off-by-one ``>=`` bug.
    """
    gas_limit_cap = fork.transaction_gas_limit_cap()
    assert gas_limit_cap is not None
    intrinsic_gas = fork.transaction_intrinsic_cost_calculator()(
        sends_value=True,
    )

    filler_tx_count = (fork.minimum_block_gas_limit() // intrinsic_gas) + 1
    block_gas_limit = intrinsic_gas * (filler_tx_count + 1)

    dest_contract = pre.deploy_contract(code=Op.STOP)
    filler_sender = pre.fund_eoa()
    filler_txs = [
        Transaction(
            to=dest_contract,
            gas_limit=intrinsic_gas,
            value=1,
            sender=filler_sender,
        )
        for _ in range(filler_tx_count)
    ]

    excess_tx_gas_limit = intrinsic_gas + delta
    assert excess_tx_gas_limit < gas_limit_cap
    error = TransactionException.GAS_ALLOWANCE_EXCEEDED if delta else None
    excess_tx = Transaction(
        to=dest_contract,
        gas_limit=excess_tx_gas_limit,
        value=1,
        sender=pre.fund_eoa(),
        error=error,
    )

    blockchain_test(
        genesis_environment=Environment(gas_limit=block_gas_limit),
        pre=pre,
        blocks=[
            Block(
                txs=filler_txs + [excess_tx],
                gas_limit=block_gas_limit,
                exception=error,
                header_verify=Header(gas_used=block_gas_limit)
                if not error
                else None,
            )
        ],
        post={},
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 2 forks.