Skip to content

test_block_gas_limit_below_minimum()

Documentation for tests/frontier/validation/test_header.py::test_block_gas_limit_below_minimum@5fa5938b.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/frontier/validation/test_header.py::test_block_gas_limit_below_minimum --fork Amsterdam

Tests that a block with a gas limit below the minimum throws an error.

Source code in tests/frontier/validation/test_header.py
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
74
75
76
77
78
79
@pytest.mark.parametrize_by_fork("gas_limit", gas_limit_cases_by_fork)
def test_block_gas_limit_below_minimum(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    gas_limit: int,
    env: Environment,
    fork: Fork,
) -> None:
    """
    Tests that a block with a gas limit below the minimum throws an error.
    """
    modified_fields = {"gas_limit": gas_limit}
    minimum_block_gas_limit = fork.minimum_block_gas_limit()
    env.gas_limit = ZeroPaddedHexNumber(minimum_block_gas_limit)

    block = Block(txs=[])

    if gas_limit < minimum_block_gas_limit:
        block.rlp_modifier = Header(**modified_fields)
        if gas_limit < PROTOCOL_GAS_LIMIT_FLOOR:
            block.exception = (
                [
                    BlockException.INVALID_GASLIMIT,
                    BlockException.BLOCK_ACCESS_LIST_GAS_LIMIT_EXCEEDED,
                ]
                if fork.is_eip_enabled(7928)
                else BlockException.INVALID_GASLIMIT
            )
        else:
            block.exception = (
                BlockException.BLOCK_ACCESS_LIST_GAS_LIMIT_EXCEEDED
            )

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

Parametrized Test Cases

This test generates 4 parametrized test cases across 16 forks.