Skip to content

test_tx_gas_limit_cap_full_calldata()

Documentation for tests/osaka/eip7825_transaction_gas_limit_cap/test_tx_gas_limit.py::test_tx_gas_limit_cap_full_calldata@88e9fb8f.

Generate fixtures for these test cases for Osaka with:

fill -v tests/osaka/eip7825_transaction_gas_limit_cap/test_tx_gas_limit.py::test_tx_gas_limit_cap_full_calldata --fork Osaka

Test the transaction gas limit cap behavior for full calldata.

Source code in tests/osaka/eip7825_transaction_gas_limit_cap/test_tx_gas_limit.py
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
@pytest.mark.xdist_group(name="bigmem")
@pytest.mark.parametrize(
    "exceed_tx_gas_limit,correct_intrinsic_cost_in_transaction_gas_limit",
    [
        pytest.param(True, False, marks=pytest.mark.exception_test),
        pytest.param(True, True, marks=pytest.mark.exception_test),
        pytest.param(False, True),
    ],
)
@pytest.mark.parametrize("zero_byte", [True, False])
@pytest.mark.valid_from("Osaka")
def test_tx_gas_limit_cap_full_calldata(
    state_test: StateTestFiller,
    pre: Alloc,
    zero_byte: bool,
    total_cost_floor_per_token: int,
    exceed_tx_gas_limit: bool,
    correct_intrinsic_cost_in_transaction_gas_limit: bool,
    fork: Fork,
) -> None:
    """Test the transaction gas limit cap behavior for full calldata."""
    intrinsic_cost = fork.transaction_intrinsic_cost_calculator()
    tx_gas_limit_cap = fork.transaction_gas_limit_cap()
    assert tx_gas_limit_cap is not None, "Fork does not have a transaction gas limit cap"
    gas_available = tx_gas_limit_cap - intrinsic_cost()

    max_tokens_in_calldata = gas_available // total_cost_floor_per_token
    num_of_bytes = max_tokens_in_calldata if zero_byte else max_tokens_in_calldata // 4

    num_of_bytes += int(exceed_tx_gas_limit)

    # Gas cost calculation based on EIP-7623:
    # (https://eips.ethereum.org/EIPS/eip-7623)
    #
    # Simplified in this test case:
    # - No execution gas used (no opcodes are executed)
    # - Not a contract creation (no initcode)
    #
    # Token accounting:
    #   tokens_in_calldata = zero_bytes + 4 * non_zero_bytes

    byte_data = b"\x00" if zero_byte else b"\xff"

    correct_intrinsic_cost = intrinsic_cost(calldata=byte_data * num_of_bytes)
    if exceed_tx_gas_limit:
        assert correct_intrinsic_cost > tx_gas_limit_cap, (
            "Correct intrinsic cost should exceed the tx gas limit cap"
        )
    else:
        assert correct_intrinsic_cost <= tx_gas_limit_cap, (
            "Correct intrinsic cost should be less than or equal to the tx gas limit cap"
        )

    tx_gas_limit = (
        correct_intrinsic_cost
        if correct_intrinsic_cost_in_transaction_gas_limit
        else tx_gas_limit_cap
    )

    tx = Transaction(
        to=pre.fund_eoa(),
        data=byte_data * num_of_bytes,
        gas_limit=tx_gas_limit,
        sender=pre.fund_eoa(),
        error=TransactionException.GAS_LIMIT_EXCEEDS_MAXIMUM
        if correct_intrinsic_cost_in_transaction_gas_limit and exceed_tx_gas_limit
        else TransactionException.INTRINSIC_GAS_BELOW_FLOOR_GAS_COST
        if exceed_tx_gas_limit
        else None,
    )

    state_test(
        pre=pre,
        post={},
        tx=tx,
    )

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) zero_byte exceed_tx_gas_limit correct_intrinsic_cost_in_transaction_gas_limit
...fork_Osaka-state_test-zero_byte_True-exceed_tx_gas_limit_True-correct_intrinsic_cost_in_transaction_gas_limit_False True True False
...fork_Osaka-state_test-zero_byte_True-exceed_tx_gas_limit_True-correct_intrinsic_cost_in_transaction_gas_limit_True True True True
...fork_Osaka-state_test-zero_byte_True-exceed_tx_gas_limit_False-correct_intrinsic_cost_in_transaction_gas_limit_True True False True
...fork_Osaka-state_test-zero_byte_False-exceed_tx_gas_limit_True-correct_intrinsic_cost_in_transaction_gas_limit_False False True False
...fork_Osaka-state_test-zero_byte_False-exceed_tx_gas_limit_True-correct_intrinsic_cost_in_transaction_gas_limit_True False True True
...fork_Osaka-state_test-zero_byte_False-exceed_tx_gas_limit_False-correct_intrinsic_cost_in_transaction_gas_limit_True False False True
...fork_Osaka-blockchain_test_from_state_test-zero_byte_True-exceed_tx_gas_limit_True-correct_intrinsic_cost_in_transaction_gas_limit_False True True False
...fork_Osaka-blockchain_test_from_state_test-zero_byte_True-exceed_tx_gas_limit_True-correct_intrinsic_cost_in_transaction_gas_limit_True True True True
...fork_Osaka-blockchain_test_from_state_test-zero_byte_True-exceed_tx_gas_limit_False-correct_intrinsic_cost_in_transaction_gas_limit_True True False True
...fork_Osaka-blockchain_test_from_state_test-zero_byte_False-exceed_tx_gas_limit_True-correct_intrinsic_cost_in_transaction_gas_limit_False False True False
...fork_Osaka-blockchain_test_from_state_test-zero_byte_False-exceed_tx_gas_limit_True-correct_intrinsic_cost_in_transaction_gas_limit_True False True True
...fork_Osaka-blockchain_test_from_state_test-zero_byte_False-exceed_tx_gas_limit_False-correct_intrinsic_cost_in_transaction_gas_limit_True False False True