Skip to content

test_block_regular_gas_limit()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_reservoir.py::test_block_regular_gas_limit@87aba1a3.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_reservoir.py::test_block_regular_gas_limit --fork Amsterdam

Test check_transaction enforcement of regular gas against block limit.

The regular gas check uses min(TX_MAX_GAS_LIMIT, tx.gas). Fill the block with transactions at TX_MAX_GAS_LIMIT and verify the last one is accepted or rejected based on remaining capacity.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_reservoir.py
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
@pytest.mark.parametrize(
    "exceed_block_gas_limit",
    [
        pytest.param(True, marks=pytest.mark.exception_test),
        pytest.param(False),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_block_regular_gas_limit(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    exceed_block_gas_limit: bool,
    fork: Fork,
) -> None:
    """
    Test check_transaction enforcement of regular gas against block limit.

    The regular gas check uses min(TX_MAX_GAS_LIMIT, tx.gas).
    Fill the block with transactions at TX_MAX_GAS_LIMIT and verify
    the last one is accepted or rejected based on remaining capacity.
    """
    gas_limit_cap = fork.transaction_gas_limit_cap()
    assert gas_limit_cap is not None
    env = Environment()
    tx_count = env.gas_limit // gas_limit_cap

    gas_spender = pre.deploy_contract(code=Op.INVALID)

    total_txs = tx_count + int(exceed_block_gas_limit)
    block = Block(
        txs=[
            Transaction(
                to=gas_spender,
                sender=pre.fund_eoa(),
                gas_limit=gas_limit_cap,
                error=(
                    TransactionException.GAS_ALLOWANCE_EXCEEDED
                    if i >= tx_count
                    else None
                ),
            )
            for i in range(total_txs)
        ],
        exception=(
            TransactionException.GAS_ALLOWANCE_EXCEEDED
            if exceed_block_gas_limit
            else None
        ),
    )

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

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.