Skip to content

test_blob_gas_subtraction_tx()

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

Generate fixtures for these test cases for Amsterdam with:

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

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
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
@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 4 forks.