Coverage for tests/wallet/test_send.py: 100%
199 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-22 19:49 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-22 19:49 +0000
1from __future__ import annotations
3import logging
4from typing import Optional
6import pytest
7from monero import (
8 MoneroDaemonRpc,
9 MoneroFeeEstimate,
10 MoneroIntegratedAddress,
11 MoneroSubaddress,
12 MoneroTxConfig,
13 MoneroTxPriority,
14 MoneroTxQuery,
15 MoneroTxWallet,
16 MoneroUtils,
17 MoneroWallet,
18 MoneroWalletConfig,
19)
20from typing_extensions import override
22from utils import TestUtils, TxWalletUtils, WalletSendUtils
23from .base_test_monero_wallet import BaseTestMoneroWallet
24from .wallet_support import FullWalletSupport, RpcWalletSupport, KeysWalletSupport
26logger: logging.Logger = logging.getLogger("TestMoneroWalletSend")
29class BaseTestMoneroWalletSend(BaseTestMoneroWallet):
30 """Common wallet send tests."""
32 # Validates inputs when sending funds
33 @pytest.mark.skipif(TestUtils.TEST_RELAYS is False, reason="TEST_RELAYS disabled")
34 @pytest.mark.flaky(reruns=5, reruns_delay=5, only_rerun=[])
35 def test_validate_inputs_sending_funds(self, wallet: MoneroWallet) -> None:
36 # try sending with invalid address
37 tx_config: MoneroTxConfig = MoneroTxConfig()
38 tx_config.address = "my invalid address"
39 tx_config.account_index = 0
40 tx_config.amount = TxWalletUtils.MAX_FEE
41 with pytest.raises(Exception) as exc_info:
42 wallet.create_tx(tx_config)
43 assert str(exc_info.value) == "Invalid destination address"
45 # Can send to self
46 @pytest.mark.skipif(TestUtils.TEST_RELAYS is False, reason="TEST_RELAYS disabled")
47 def test_send_to_self(self, wallet: MoneroWallet) -> None:
48 # wait for txs to confirm and for sufficient unlocked balance
49 TestUtils.WALLET_TX_TRACKER.wait_for_txs_to_clear_pool(wallet)
50 amount: int = TxWalletUtils.MAX_FEE * 3
51 TestUtils.WALLET_TX_TRACKER.wait_for_unlocked_balance(wallet, 0, None, amount)
53 # collect sender balances before
54 balance1: int = wallet.get_balance()
55 unlocked_balance1: int = wallet.get_unlocked_balance()
57 # test error sending funds to self with integrated subaddress
58 # TODO (monero-project): sending funds to self
59 # with integrated subaddress throws error: https://github.com/monero-project/monero/issues/8380
61 tx_config: MoneroTxConfig = MoneroTxConfig()
62 tx_config.account_index = 0
63 subaddress: MoneroSubaddress = wallet.get_subaddress(0, 1)
64 assert subaddress.address is not None
65 address: str = subaddress.address
66 tx_config.address = MoneroUtils.get_integrated_address(TestUtils.NETWORK_TYPE, address, '').integrated_address
67 tx_config.amount = amount
68 tx_config.relay = True
69 with pytest.raises(Exception, match="Total received by"):
70 wallet.create_tx(tx_config)
72 # send funds to self
73 tx_config = MoneroTxConfig()
74 tx_config.account_index = 0
75 tx_config.address = wallet.get_integrated_address().integrated_address
76 tx_config.amount = amount
77 tx_config.relay = True
79 tx: MoneroTxWallet = wallet.create_tx(tx_config)
81 # test balances after
82 balance2: int = wallet.get_balance()
83 unlocked_balance2: int = wallet.get_unlocked_balance()
85 # unlocked balance should decrease
86 assert unlocked_balance2 < unlocked_balance1
87 assert tx.fee is not None
88 expected_balance: int = balance1 - tx.fee
89 assert expected_balance == balance2, "Balance after send was not balance before - fee"
91 # Can send to external address
92 @pytest.mark.skipif(TestUtils.TEST_RELAYS is False, reason="TEST_RELAYS disabled")
93 def test_send_to_external(self, wallet: MoneroWallet) -> None:
94 recipient: Optional[MoneroWallet] = None
95 try:
96 # wait for txs to confirm and for sufficient unlocked balance
97 TestUtils.WALLET_TX_TRACKER.wait_for_txs_to_clear_pool(wallet)
98 amount: int = TxWalletUtils.MAX_FEE * 3
99 TestUtils.WALLET_TX_TRACKER.wait_for_unlocked_balance(wallet, 0, None, amount)
101 # create recipient wallet
102 recipient = self._create_wallet(MoneroWalletConfig())
104 balance1: int = wallet.get_balance()
105 unlocked_balance1: int = wallet.get_unlocked_balance()
107 # send funds to recipient
108 tx_config: MoneroTxConfig = MoneroTxConfig()
109 tx_config.account_index = 0
110 tx_config.address = wallet.get_integrated_address(recipient.get_primary_address(), "54491f3bb3572a37").integrated_address
111 tx_config.amount = amount
112 tx_config.relay = True
113 tx: MoneroTxWallet = wallet.create_tx(tx_config)
115 # test sender balances after
116 balance2: int = wallet.get_balance()
117 unlocked_balance2: int = wallet.get_unlocked_balance()
119 # unlocked balance should decrease
120 assert unlocked_balance2 < unlocked_balance1
121 assert tx.fee is not None
122 expected_balance: int = balance1 - tx.get_outgoing_amount() - tx.fee
123 assert expected_balance == balance2, "Balance after send was not balance before - net tx amount - fee (5 - 1 != 4 test)"
125 tx_query: MoneroTxQuery = MoneroTxQuery()
126 tx_query.is_confirmed = False
127 txs: list[MoneroTxWallet] = wallet.get_txs(tx_query)
128 assert len(txs) > 0
130 # test recipient balance after
131 recipient.sync()
132 assert amount == recipient.get_balance()
134 finally:
135 if recipient is not None:
136 self._close_wallet(recipient)
138 # Can send to multiple subaddresses in a single transaction
139 @pytest.mark.skipif(TestUtils.TEST_RELAYS is False, reason="TEST_RELAYS disabled")
140 def test_send_to_multiple(self, wallet: MoneroWallet) -> None:
141 WalletSendUtils.test_send_to_multiple(wallet, 5, 3, False)
143 # Can send to multiple addresses in split transactions
144 @pytest.mark.skipif(TestUtils.TEST_RELAYS is False, reason="TEST_RELAYS disabled")
145 def test_send_to_multiple_split(self, wallet: MoneroWallet) -> None:
146 WalletSendUtils.test_send_to_multiple(wallet, 3, 15, True)
148 # Can send dust to multiple addresses in split transactions
149 @pytest.mark.skipif(TestUtils.TEST_RELAYS is False, reason="TEST_RELAYS disabled")
150 def test_send_dust_to_multiple_split(self, daemon: MoneroDaemonRpc, wallet: MoneroWallet) -> None:
151 estimate: MoneroFeeEstimate = daemon.get_fee_estimate()
152 assert estimate.fee is not None
153 dust_amount: int = int(estimate.fee / 2)
154 WalletSendUtils.test_send_to_multiple(wallet, 5, 3, True, dust_amount)
156 # Can subtract fees from destinations
157 @pytest.mark.skipif(TestUtils.TEST_RELAYS is False, reason="TEST_RELAYS disabled")
158 def test_subtract_fee_from(self, wallet: MoneroWallet) -> None:
159 WalletSendUtils.test_send_to_multiple(wallet, 5, 3, False, None, True)
161 # Cannot subtract fees from destinations in split transactions
162 @pytest.mark.skipif(TestUtils.TEST_RELAYS is False, reason="TEST_RELAYS disabled")
163 def test_subtract_fee_from_split(self, wallet: MoneroWallet) -> None:
164 WalletSendUtils.test_send_to_multiple(wallet, 3, 15, True, None, True)
166 # Can send from multiple subaddresses in a single transaction
167 @pytest.mark.skipif(TestUtils.TEST_RELAYS is False, reason="TEST_RELAYS disabled")
168 def test_send_from_subaddresses(self, wallet: MoneroWallet) -> None:
169 WalletSendUtils.test_send_from_multiple(wallet, None)
171 # Can send from multiple subaddresses in split transactions
172 @pytest.mark.skipif(TestUtils.TEST_RELAYS is False, reason="TEST_RELAYS disabled")
173 def test_send_from_subaddresses_split(self, wallet: MoneroWallet) -> None:
174 WalletSendUtils.test_send_from_multiple(wallet, True)
176 # Can send to an address in a single transaction
177 @pytest.mark.skipif(TestUtils.TEST_RELAYS is False, reason="TEST_RELAYS disabled")
178 def test_send(self, wallet: MoneroWallet) -> None:
179 WalletSendUtils.test_send_to_single(wallet, False)
181 # Can send to an address in a single transaction with a payment id
182 # NOTE this test will be invalid when payment hashes are fully removed
183 @pytest.mark.skipif(TestUtils.TEST_RELAYS is False, reason="TEST_RELAYS disabled")
184 def test_send_with_payment_id(self, wallet: MoneroWallet) -> None:
185 integrated_address: MoneroIntegratedAddress = wallet.get_integrated_address()
186 assert integrated_address.payment_id is not None
187 payment_id: str = integrated_address.payment_id
188 msg = "Standalone payment IDs are obsolete. Use subaddresses or integrated addresses instead"
189 with pytest.raises(Exception) as exc_info:
190 WalletSendUtils.test_send_to_single(wallet, False, None, f"{payment_id}{payment_id}{payment_id}")
191 assert str(exc_info.value) == msg
193 # Can send to an address with split transactions
194 @pytest.mark.skipif(TestUtils.TEST_RELAYS is False, reason="TEST_RELAYS disabled")
195 def test_send_split(self, wallet: MoneroWallet) -> None:
196 WalletSendUtils.test_send_to_single(wallet, True)
198 # Can create then relay a transaction to send to a single address
199 @pytest.mark.skipif(TestUtils.TEST_RELAYS is False, reason="TEST_RELAYS disabled")
200 def test_create_then_relay(self, wallet: MoneroWallet) -> None:
201 WalletSendUtils.test_send_to_single(wallet, False, False)
203 # Can create then relay split transactions to send to a single address
204 @pytest.mark.skipif(TestUtils.TEST_RELAYS is False, reason="TEST_RELAYS disabled")
205 def test_create_then_relay_split(self, wallet: MoneroWallet) -> None:
206 WalletSendUtils.test_send_to_single(wallet, True, False)
208 # Can get the default fee priority
209 @pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
210 def test_get_default_fee_priority(self, wallet: MoneroWallet) -> None:
211 default_priority: MoneroTxPriority = wallet.get_default_fee_priority()
212 assert int(default_priority) > 0
215@pytest.mark.integration
216class TestMoneroWalletFullSend(FullWalletSupport, BaseTestMoneroWalletSend):
217 """Full wallet send integration tests."""
220@pytest.mark.integration
221class TestMoneroWalletRpcSend(RpcWalletSupport, BaseTestMoneroWalletSend):
222 """Rpc wallet send integration tests."""
225@pytest.mark.unit
226class TestMoneroWalletKeysSend(KeysWalletSupport, BaseTestMoneroWalletSend):
227 """Keys-only wallet send unit tests."""
229 @pytest.mark.not_supported
230 @override
231 def test_send(self, wallet: MoneroWallet) -> None:
232 return super().test_send(wallet)
234 @pytest.mark.not_implemented
235 @override
236 def test_send_with_payment_id(self, wallet: MoneroWallet) -> None:
237 return super().test_send_with_payment_id(wallet)
239 @pytest.mark.not_supported
240 @override
241 def test_send_split(self, wallet: MoneroWallet) -> None:
242 return super().test_send_split(wallet)
244 @pytest.mark.not_supported
245 @override
246 def test_create_then_relay(self, wallet: MoneroWallet) -> None:
247 return super().test_create_then_relay(wallet)
249 @pytest.mark.not_supported
250 @override
251 def test_create_then_relay_split(self, wallet: MoneroWallet) -> None:
252 return super().test_create_then_relay_split(wallet)
254 @pytest.mark.not_supported
255 @override
256 def test_validate_inputs_sending_funds(self, wallet: MoneroWallet) -> None:
257 return super().test_validate_inputs_sending_funds(wallet)
259 @pytest.mark.not_supported
260 @override
261 def test_send_to_self(self, wallet: MoneroWallet) -> None:
262 return super().test_send_to_self(wallet)
264 @pytest.mark.not_supported
265 @override
266 def test_send_to_external(self, wallet: MoneroWallet) -> None:
267 return super().test_send_to_external(wallet)
269 @pytest.mark.not_supported
270 @override
271 def test_get_default_fee_priority(self, wallet: MoneroWallet) -> None:
272 return super().test_get_default_fee_priority(wallet)
274 @pytest.mark.not_supported
275 @override
276 def test_send_from_subaddresses(self, wallet: MoneroWallet) -> None:
277 return super().test_send_from_subaddresses(wallet)
279 @pytest.mark.not_supported
280 @override
281 def test_send_from_subaddresses_split(self, wallet: MoneroWallet) -> None:
282 return super().test_send_from_subaddresses_split(wallet)
284 @pytest.mark.not_supported
285 @override
286 def test_send_to_multiple(self, wallet: MoneroWallet) -> None:
287 return super().test_send_to_multiple(wallet)
289 @pytest.mark.not_supported
290 @override
291 def test_send_to_multiple_split(self, wallet: MoneroWallet) -> None:
292 return super().test_send_to_multiple_split(wallet)
294 @pytest.mark.not_supported
295 @override
296 def test_send_dust_to_multiple_split(self, daemon: MoneroDaemonRpc, wallet: MoneroWallet) -> None:
297 return super().test_send_dust_to_multiple_split(daemon, wallet)
299 @pytest.mark.not_supported
300 @override
301 def test_subtract_fee_from(self, wallet: MoneroWallet) -> None:
302 return super().test_subtract_fee_from(wallet)
304 @pytest.mark.not_supported
305 @override
306 def test_subtract_fee_from_split(self, wallet: MoneroWallet) -> None:
307 return super().test_subtract_fee_from_split(wallet)