Skip to content

test_blob_gas_subtraction_tx()

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

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
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
@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.