From 464b83a3c36b4ef8970955852ab8094a19080a03 Mon Sep 17 00:00:00 2001 From: spencer-tb Date: Sun, 28 Jan 2024 19:12:29 +0700 Subject: [PATCH] feat(tests): Add blob gas subtraction order tests. --- tests/cancun/eip4844_blobs/test_blob_txs.py | 53 +++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/cancun/eip4844_blobs/test_blob_txs.py b/tests/cancun/eip4844_blobs/test_blob_txs.py index 7ed9bee443..cae727a4a9 100644 --- a/tests/cancun/eip4844_blobs/test_blob_txs.py +++ b/tests/cancun/eip4844_blobs/test_blob_txs.py @@ -892,6 +892,59 @@ def test_sufficient_balance_blob_tx_pre_fund_tx( ) +@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"\x00", b"\x01"], + ids=["no_calldata", "single_zero_calldata"], +) +@pytest.mark.parametrize("tx_max_fee_per_blob_gas", [1, 100]) +@pytest.mark.parametrize( + "tx_gas", [500_000], ids=[""] +) # Increase gas to account for contract code +@pytest.mark.parametrize("mid_tx_send_amount", [0, 100]) +@pytest.mark.valid_from("Cancun") +def test_blob_gas_subtraction_tx( + state_test: StateTestFiller, + state_env: Environment, + pre: Dict, + txs: List[Transaction], + destination_account: str, + mid_tx_send_amount: int, +): + """ + Check that the blob gas fee for a transaction is subtracted from the sender balance before the + transaction is executed, including: + + - Transactions with max fee equal or higher than current block base fee + - Transactions with and without priority 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 + pre[destination_account] = Account( + balance=mid_tx_send_amount, + code=Op.SSTORE(0, Op.BALANCE(Op.ORIGIN)) + + Op.CALL(Op.GAS, Op.ORIGIN, mid_tx_send_amount, 0, 0, 0, 0) + + Op.SSTORE(1, Op.BALANCE(Op.ORIGIN)), + ) + state_test( + pre=pre, + post={}, + tx=txs[0], + env=state_env, + ) + + @pytest.mark.parametrize( "blobs_per_tx", all_valid_blob_combinations(),