Skip to content

test_tx_gas_limit()

Documentation for tests/frontier/validation/test_transaction.py::test_tx_gas_limit@02aafd78.

Generate fixtures for these test cases for Bogota with:

fill -v tests/frontier/validation/test_transaction.py::test_tx_gas_limit --fork Bogota

Tests that if a tx gas limit is higher than the block gas limit, an exception is raised.

The block gas limit is kept well above what an empty block's access list needs under the EIP-7928 item cap (gas_limit // 2000 items, against the system-contract reads every Amsterdam block carries), so the transaction's gas allowance is the only thing wrong with the block and clients do not disagree on which check to report.

Source code in tests/frontier/validation/test_transaction.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
@pytest.mark.inclusion_test
@pytest.mark.exception_test
@pytest.mark.eels_base_coverage
def test_tx_gas_limit(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    env: Environment,
) -> None:
    """
    Tests that if a tx gas limit is higher than the block gas limit,
    an exception is raised.

    The block gas limit is kept well above what an empty block's access
    list needs under the EIP-7928 item cap (`gas_limit // 2000` items,
    against the system-contract reads every Amsterdam block carries), so
    the transaction's gas allowance is the only thing wrong with the
    block and clients do not disagree on which check to report.
    """
    sender = pre.fund_eoa()
    to = pre.fund_eoa()

    block_gas_limit = 100_000
    tx = Transaction(
        gas_limit=block_gas_limit + 1,
        to=to,
        gas_price=0x10,  # Must be >= base fee to isolate gas limit validation
        sender=sender,
        protected=False,
        error=TransactionException.GAS_ALLOWANCE_EXCEEDED,
    )

    modified_fields = {"gas_limit": ZeroPaddedHexNumber(block_gas_limit)}
    env.gas_limit = ZeroPaddedHexNumber(block_gas_limit)

    block = Block(
        txs=[tx],
        rlp_modifier=Header(**modified_fields),
        exception=TransactionException.GAS_ALLOWANCE_EXCEEDED,
    )

    blockchain_test(pre=pre, post={}, blocks=[block], genesis_environment=env)

Parametrized Test Cases

This test generates 1 parametrized test case across 17 forks.