Skip to content

test_block_2d_gas_tx_gas_limit_exceeds_regular_remaining()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py::test_block_2d_gas_tx_gas_limit_exceeds_regular_remaining@5c024cbb.

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

Verify a block is valid when a later tx's gas_limit exceeds the regular budget remaining but its capped regular contribution fits.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
@pytest.mark.parametrize(
    "tx2_gas_limit_equals_block_gas_limit",
    [
        pytest.param(True, id="tx_gas_limit_equals_block_limit"),
        pytest.param(False, id="tx_gas_limit_just_above_remaining"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_block_2d_gas_tx_gas_limit_exceeds_regular_remaining(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    tx2_gas_limit_equals_block_gas_limit: bool,
) -> None:
    """
    Verify a block is valid when a later tx's gas_limit exceeds the
    regular budget remaining but its capped regular contribution fits.
    """
    gas_limit_cap = fork.transaction_gas_limit_cap()
    assert gas_limit_cap is not None
    intrinsic_gas = fork.transaction_intrinsic_cost_calculator()()
    env = Environment()
    block_gas_limit = int(env.gas_limit)

    if tx2_gas_limit_equals_block_gas_limit:
        tx2_gas_limit = block_gas_limit
    else:
        tx2_gas_limit = block_gas_limit - intrinsic_gas + 1

    assert tx2_gas_limit > gas_limit_cap
    assert tx2_gas_limit > block_gas_limit - intrinsic_gas

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

    storage = Storage()
    sstore_contract = pre.deploy_contract(
        code=Op.SSTORE(storage.store_next(1), 1),
    )

    tx1_regular = intrinsic_gas
    tx2_regular, tx2_state = sstore_tx_gas(fork)
    expected_gas_used = max(tx1_regular + tx2_regular, tx2_state)

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[
                    Transaction(
                        to=stop_contract,
                        gas_limit=intrinsic_gas,
                        sender=pre.fund_eoa(),
                    ),
                    Transaction(
                        to=sstore_contract,
                        gas_limit=tx2_gas_limit,
                        sender=pre.fund_eoa(),
                    ),
                ],
                header_verify=Header(gas_used=expected_gas_used),
            ),
        ],
        post={sstore_contract: Account(storage=storage)},
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.