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@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

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

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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
@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")
@pytest.mark.eels_base_coverage
def test_tx_gas_limit_cap_full_calldata(
    state_test: StateTestFiller,
    pre: Alloc,
    zero_byte: bool,
    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"
    )
    byte_data = b"\x00" if zero_byte else b"\xff"
    max_num_of_bytes = max_count_with_intrinsic_cost_at_most(
        lambda calldata_size: intrinsic_cost(
            calldata=byte_data * calldata_size
        ),
        tx_gas_limit_cap,
    )
    num_of_bytes = max_num_of_bytes + int(exceed_tx_gas_limit)

    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

This test generates 6 parametrized test cases across 2 forks.