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@ffe48572.

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
@pytest.mark.inclusion_test
@pytest.mark.bigmem
@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.valid_before("EIP8037")
@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_gas_limit(
        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 1 fork.