Skip to content

test_blob_gas_subtraction_tx()

Documentation for tests/cancun/eip4844_blobs/test_blob_txs.py::test_blob_gas_subtraction_tx@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/cancun/eip4844_blobs/test_blob_txs.py::test_blob_gas_subtraction_tx --fork Bogota

Check that the blob gas fee for a transaction is subtracted from the sender balance before the transaction is executed.

  • Transactions with max fee equal or higher than current block base fee
  • Transactions with and without value
  • Transactions with and without calldata
  • Transactions with max fee per blob gas lower or higher than the priority fee
  • Transactions where an externally owned account sends funds to the sender mid execution
Source code in tests/cancun/eip4844_blobs/test_blob_txs.py
@pytest.mark.parametrize_by_fork(
    "blobs_per_tx",
    lambda fork: [
        pytest.param([1], id="single_blob"),
        pytest.param([fork.max_blobs_per_tx()], id="max_blobs"),
    ],
)
@pytest.mark.parametrize(
    "tx_access_list",
    [[], [AccessList(address=100, storage_keys=[100, 200])]],
    ids=["no_access_list", "access_list"],
)
@pytest.mark.parametrize("tx_max_fee_per_gas", [7, 14])
@pytest.mark.parametrize("tx_max_priority_fee_per_gas", [0, 7])
@pytest.mark.parametrize("tx_value", [0, 1])
@pytest.mark.parametrize(
    "tx_calldata",
    [b"", b"\x01"],
    ids=["no_calldata", "single_non_zero_byte_calldata"],
)
@pytest.mark.parametrize("tx_max_fee_per_blob_gas_multiplier", [1, 100])
@pytest.mark.parametrize(
    "tx_gas", [500_000], ids=[""]
)  # Increase gas to account for contract code
@pytest.mark.parametrize(
    "destination_account_balance", [100], ids=["100_wei_mid_execution"]
)  # Amount sent by the contract to the sender mid execution
@pytest.mark.parametrize(
    "destination_account_code",
    [
        Op.SSTORE(0, Op.BALANCE(Op.ORIGIN))
        + Op.CALL(
            Op.GAS, Op.ORIGIN, Op.SUB(Op.SELFBALANCE, Op.CALLVALUE), 0, 0, 0, 0
        )
        + Op.SSTORE(1, Op.BALANCE(Op.ORIGIN))
    ],
    ids=[""],
)  # Amount sent by the contract to the sender mid execution
@pytest.mark.valid_from("Cancun")
def test_blob_gas_subtraction_tx(
    state_test: StateTestFiller,
    state_env: Environment,
    pre: Alloc,
    sender_initial_balance: int,
    txs: List[Transaction],
    destination_account: Address,
    destination_account_balance: int,
    total_account_transactions_fee: int,
) -> None:
    """
    Check that the blob gas fee for a transaction is subtracted from the sender
    balance before the transaction is executed.

    - Transactions with max fee equal or higher than current block base fee
    - Transactions with and without value
    - Transactions with and without calldata
    - Transactions with max fee per blob gas lower or higher than the priority
        fee
    - Transactions where an externally owned account sends funds to the sender
        mid execution
    """
    assert len(txs) == 1
    post = {
        destination_account: Account(
            storage={
                0: sender_initial_balance - total_account_transactions_fee,
                1: sender_initial_balance
                - total_account_transactions_fee
                + destination_account_balance,
            }
        )
    }
    state_test(
        pre=pre,
        post=post,
        tx=txs[0],
        env=state_env,
    )

Parametrized Test Cases

This test generates 128 parametrized test cases across 5 forks.