Coverage for tests/wallet/test_txs.py: 97%

443 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-22 19:49 +0000

1from __future__ import annotations 

2 

3import logging 

4from random import shuffle 

5from typing import Optional 

6 

7import pytest 

8from monero import ( 

9 MoneroBlock, 

10 MoneroOutputQuery, 

11 MoneroTransferQuery, 

12 MoneroTxQuery, 

13 MoneroTxWallet, 

14 MoneroUtils, 

15 MoneroWallet, 

16) 

17from typing_extensions import override 

18 

19from utils import ( 

20 AssertUtils, 

21 GenUtils, 

22 StringUtils, 

23 TestUtils, 

24 TransferUtils, 

25 TxContext, 

26 TxWalletUtils, 

27 WalletTxsUtils, 

28) 

29from .base_test_monero_wallet import BaseTestMoneroWallet 

30from .wallet_support import FullWalletSupport, RpcWalletSupport, KeysWalletSupport 

31 

32logger: logging.Logger = logging.getLogger("TestMoneroWalletTxs") 

33 

34 

35class BaseTestMoneroWalletTxs(BaseTestMoneroWallet): 

36 """Common wallet txs tests.""" 

37 

38 # Can get transactions in the wallet 

39 @pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") 

40 def test_get_txs_wallet(self, wallet: MoneroWallet) -> None: 

41 #non_default_incoming: bool = False 

42 txs: list[MoneroTxWallet] = WalletTxsUtils.get_and_test_txs(wallet, None, None, True, TestUtils.REGTEST) 

43 assert len(txs) > 0, "Wallet has no txs to test" 

44 # TODO make consistent with test funded wallet 

45 # assert TestUtils.FIRST_RECEIVE_HEIGHT == txs[0].get_height(), "First tx's restore height must match the restore height in TestUtils" 

46 

47 # build test context 

48 ctx: TxContext = TxContext() 

49 ctx.wallet = wallet 

50 

51 # test each transaction 

52 block_per_height: dict[int, MoneroBlock] = {} 

53 for i, tx in enumerate(txs): 

54 TxWalletUtils.test_tx_wallet(tx, ctx) 

55 

56 # test merging equivalent txs 

57 it: MoneroTxWallet = txs[i] # is the same as tx 

58 copy1: MoneroTxWallet = it.copy() 

59 copy2: MoneroTxWallet = it.copy() 

60 

61 if copy1.is_confirmed: 

62 assert it.block is not None 

63 copy1.block = it.block.copy() 

64 copy1.block.txs = [copy1] 

65 

66 if copy2.is_confirmed: 

67 assert it.block is not None 

68 copy2.block = it.block.copy() 

69 copy2.block.txs = [copy2] 

70 

71 copy1.merge(copy2) 

72 TxWalletUtils.test_tx_wallet(copy1, ctx) 

73 

74 # find non-default incoming 

75 for transfer in it.incoming_transfers: 

76 assert transfer.account_index is not None 

77 assert transfer.subaddress_index is not None 

78 #if transfer.account_index != 0 and transfer.subaddress_index != 0: 

79 # non_default_incoming = True 

80 

81 # ensure unique block reference per height 

82 if it.is_confirmed: 

83 h: int | None = it.get_height() 

84 assert h is not None 

85 block: MoneroBlock | None = block_per_height.get(h) 

86 if block is None: 

87 assert it.block is not None 

88 block_per_height[i] = it.block 

89 else: 

90 AssertUtils.assert_equals(block, it.block) 

91 assert block == it.block, "Block references for same height must be same" 

92 

93 # Can get transactions by hash 

94 @pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") 

95 def test_get_txs_by_hash(self, wallet: MoneroWallet) -> None: 

96 # max number of txs to test 

97 max_num_txs: int = 10 

98 

99 # fetch all txs for testing 

100 txs: list[MoneroTxWallet] = wallet.get_txs() 

101 num_txs: int = len(txs) 

102 assert num_txs > 1, f"Test requires at least 2 txs to fetch by hash, got {num_txs}" 

103 

104 # randomly pick a few for fetching by hash 

105 shuffle(txs) 

106 txs = txs[0:min(max_num_txs, num_txs)] 

107 

108 # test fetching by hash 

109 tx_hash: str | None = txs[0].hash 

110 assert tx_hash is not None 

111 fetched_tx: MoneroTxWallet | None = wallet.get_tx(tx_hash) 

112 assert fetched_tx is not None 

113 assert tx_hash == fetched_tx.hash 

114 TxWalletUtils.test_tx_wallet(fetched_tx) 

115 

116 # test fetching by hashes 

117 tx_id1: str | None = txs[0].hash 

118 tx_id2: str | None = txs[1].hash 

119 assert tx_id1 is not None 

120 assert tx_id2 is not None 

121 fetched_txs: list[MoneroTxWallet] = wallet.get_txs([tx_id1, tx_id2]) 

122 num_fetched_txs: int = len(fetched_txs) 

123 assert num_fetched_txs == 2, f"Expected 2 txs, got {num_fetched_txs}" 

124 

125 # test fetching by hashes as collection 

126 tx_hashes: list[str] = [] 

127 for tx in txs: 

128 assert tx.hash is not None 

129 tx_hashes.append(tx.hash) 

130 

131 fetched_txs = wallet.get_txs(tx_hashes) 

132 assert len(txs) == len(fetched_txs) 

133 for i, tx in enumerate(txs): 

134 fetched_tx = fetched_txs[i] 

135 assert tx.hash == fetched_tx.hash 

136 TxWalletUtils.test_tx_wallet(fetched_tx) 

137 

138 # test fetching with missing tx hashes 

139 missing_hash: str = "d01ede9cde813b2a693069b640c4b99c5adbdb49fbbd8da2c16c8087d0c3e320" 

140 tx_hashes.append(missing_hash) 

141 fetched_txs = wallet.get_txs(tx_hashes) 

142 assert len(txs) == len(fetched_txs) 

143 for i, tx in enumerate(txs): 

144 fetched_tx = fetched_txs[i] 

145 assert tx.hash == fetched_tx.hash 

146 TxWalletUtils.test_tx_wallet(fetched_tx) 

147 

148 # Can get transactions with additional configuration 

149 @pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") 

150 def test_get_txs_with_query(self, wallet: MoneroWallet) -> None: 

151 # get random transactions for testing 

152 random_txs: list[MoneroTxWallet] = WalletTxsUtils.get_random_transactions(wallet, None, 3, 5) 

153 for random_tx in random_txs: 

154 TxWalletUtils.test_tx_wallet(random_tx, None) 

155 

156 # get transactions by hash 

157 tx_hashes: list[str] = [] 

158 for random_tx in random_txs: 

159 assert random_tx.hash is not None 

160 tx_hashes.append(random_tx.hash) 

161 query: MoneroTxQuery = MoneroTxQuery() 

162 query.hash = random_tx.hash 

163 txs: list[MoneroTxWallet] = WalletTxsUtils.get_and_test_txs(wallet, query, None, True, TestUtils.REGTEST) 

164 assert len(txs) == 1 

165 # txs change with chain so check mergeability 

166 merged: MoneroTxWallet = txs[0] 

167 merged.merge(random_tx.copy()) 

168 TxWalletUtils.test_tx_wallet(merged) 

169 

170 # get transactions by hashes 

171 query = MoneroTxQuery() 

172 query.hashes = tx_hashes 

173 txs = WalletTxsUtils.get_and_test_txs(wallet, query, None, None, TestUtils.REGTEST) 

174 assert len(txs) == len(random_txs) 

175 for tx in txs: 

176 assert tx.hash in tx_hashes 

177 

178 # get transactions with an outgoing transfer 

179 ctx: TxContext = TxContext() 

180 ctx.has_outgoing_transfer = True 

181 query = MoneroTxQuery() 

182 query.is_outgoing = True 

183 txs = WalletTxsUtils.get_and_test_txs(wallet, query, ctx, True, TestUtils.REGTEST) 

184 for tx in txs: 

185 assert tx.is_outgoing is True 

186 assert tx.outgoing_transfer is not None 

187 TransferUtils.test_transfer(tx.outgoing_transfer, None) 

188 

189 # get transactions without an outgoing transfer 

190 ctx.has_outgoing_transfer = False 

191 query = MoneroTxQuery() 

192 query.is_outgoing = False 

193 txs = WalletTxsUtils.get_and_test_txs(wallet, query, ctx, True, TestUtils.REGTEST) 

194 for tx in txs: 

195 assert tx.outgoing_transfer is None 

196 

197 # get transactions with incoming transfers 

198 ctx = TxContext() 

199 ctx.has_incoming_transfers = True 

200 query = MoneroTxQuery() 

201 query.is_incoming = True 

202 txs = WalletTxsUtils.get_and_test_txs(wallet, query, ctx, True, TestUtils.REGTEST) 

203 for tx in txs: 

204 assert tx.is_incoming is True 

205 assert len(tx.incoming_transfers) > 0 

206 for transfer in tx.incoming_transfers: 

207 TransferUtils.test_transfer(transfer, None) 

208 

209 # get transactions without incoming transfers 

210 ctx.has_incoming_transfers = False 

211 query = MoneroTxQuery() 

212 query.is_incoming = False 

213 txs = WalletTxsUtils.get_and_test_txs(wallet, query, ctx, True, TestUtils.REGTEST) 

214 for tx in txs: 

215 assert tx.is_incoming is False 

216 assert len(tx.incoming_transfers) == 0 

217 

218 # get transactions associated with an account 

219 account_idx: int = 1 

220 query = MoneroTxQuery() 

221 query.transfer_query = MoneroTransferQuery() 

222 query.transfer_query.account_index = account_idx 

223 txs = wallet.get_txs(query) 

224 

225 for tx in txs: 

226 found: bool = False 

227 if tx.is_outgoing and tx.outgoing_transfer.account_index == account_idx: # type: ignore 

228 found = True 

229 elif len(tx.incoming_transfers) > 0: 

230 for transfer in tx.incoming_transfers: 

231 if transfer.account_index == account_idx: 

232 found = True 

233 break 

234 

235 assert found, f"Transaction is not associated with account {account_idx}: \n{tx.serialize()}" 

236 

237 # get txs with manually built query that are confirmed and have an outgoing transfer from account 0 

238 ctx = TxContext() 

239 ctx.has_outgoing_transfer = True 

240 tx_query: MoneroTxQuery = MoneroTxQuery() 

241 tx_query.is_confirmed = True 

242 tx_query.transfer_query = MoneroTransferQuery() 

243 tx_query.transfer_query.account_index = 0 

244 tx_query.transfer_query.outgoing = True 

245 txs = WalletTxsUtils.get_and_test_txs(wallet, tx_query, ctx, True, TestUtils.REGTEST) 

246 for tx in txs: 

247 if tx.is_confirmed is not True: 

248 logger.warning(f"{tx.serialize()}") 

249 assert tx.is_confirmed is True 

250 assert tx.is_outgoing is True 

251 assert tx.outgoing_transfer is not None 

252 assert tx.outgoing_transfer.account_index == 0 

253 

254 # get txs with outgoing transfers that have destinations to account 1 

255 tx_query = MoneroTxQuery() 

256 tx_query.is_confirmed = True 

257 tx_query.transfer_query = MoneroTransferQuery() 

258 tx_query.transfer_query.account_index = 0 

259 tx_query.transfer_query.has_destinations = True 

260 

261 txs = WalletTxsUtils.get_and_test_txs(wallet, tx_query, None, None, TestUtils.REGTEST) 

262 for tx in txs: 

263 assert tx.is_outgoing is True 

264 assert tx.outgoing_transfer is not None 

265 assert len(tx.outgoing_transfer.destinations) > 0 

266 

267 # include outputs with transactions 

268 ctx = TxContext() 

269 ctx.include_outputs = True 

270 tx_query = MoneroTxQuery() 

271 tx_query.include_outputs = True 

272 txs = WalletTxsUtils.get_and_test_txs(wallet, tx_query, ctx, True, TestUtils.REGTEST) 

273 found: bool = False 

274 for tx in txs: 

275 if len(tx.outputs) > 0: 

276 found = True 

277 else: 

278 # TODO: monero-wallet-rpc: return outputs for unconfirmed txs 

279 assert tx.is_outgoing or (tx.is_incoming and tx.is_confirmed is False) 

280 

281 assert found, "No outputs found in txs" 

282 

283 # get txs with input query 

284 # TODO no inputs returned to filter 

285 

286 # get txs with output query 

287 tx_query = MoneroTxQuery() 

288 tx_query.output_query = MoneroOutputQuery() 

289 tx_query.output_query.is_spent = False 

290 tx_query.output_query.account_index = 1 

291 tx_query.output_query.subaddress_index = 2 

292 txs = wallet.get_txs(tx_query) 

293 assert len(txs) > 0 

294 for tx in txs: 

295 assert len(tx.outputs) > 0 

296 found = False 

297 for output in tx.get_outputs_wallet(): 

298 if output.is_spent is False and output.account_index == 1 and output.subaddress_index == 2: 

299 found = True 

300 break 

301 

302 if not found: 

303 raise Exception("Tx does not contain specified output") 

304 

305 # get unlocked txs 

306 tx_query = MoneroTxQuery() 

307 tx_query.is_locked = False 

308 txs = wallet.get_txs(tx_query) 

309 assert len(txs) > 0 

310 for tx in txs: 

311 assert tx.is_locked is False 

312 

313 # get confirmed transactions sent from/to same wallet with a transfer with destinations 

314 

315 tx_query = MoneroTxQuery() 

316 tx_query.is_incoming = True 

317 tx_query.is_outgoing = True 

318 tx_query.include_outputs = True 

319 tx_query.is_confirmed = True 

320 tx_query.transfer_query = MoneroTransferQuery() 

321 tx_query.transfer_query.has_destinations = True 

322 

323 txs = wallet.get_txs(tx_query) 

324 assert len(txs) > 0, "Wallet has no incoming/outgoing txs to test; run send from/to tests" 

325 for tx in txs: 

326 assert tx.is_incoming is True 

327 assert tx.is_outgoing is True 

328 assert tx.is_confirmed is True 

329 assert len(tx.get_outputs_wallet()) > 0 

330 assert tx.outgoing_transfer is not None 

331 assert len(tx.outgoing_transfer.destinations) > 0 

332 

333 # Can get transactions by height 

334 @pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") 

335 def test_get_txs_by_height(self, wallet: MoneroWallet) -> None: 

336 # get all confirmed txs for testing 

337 query: MoneroTxQuery = MoneroTxQuery() 

338 query.is_confirmed = True 

339 txs: list[MoneroTxWallet] = wallet.get_txs(query) 

340 

341 # collect all tx heights 

342 tx_heights: list[int] = [] 

343 for tx in txs: 

344 tx_height: Optional[int] = tx.get_height() 

345 assert tx_height is not None 

346 tx_heights.append(tx_height) 

347 

348 # get height that most txs occur at 

349 height_counts: dict[int, int] = GenUtils.count_num_instances(tx_heights) 

350 assert len(height_counts) > 0, "Wallet has no confirmed txs; run send tests" 

351 height_modes: set[int] = GenUtils.get_modes(height_counts) 

352 mode_height: int = next(iter(height_modes)) 

353 

354 # fetch txs at mode height 

355 query = MoneroTxQuery() 

356 query.height = mode_height 

357 logger.debug(f"Getting mode txs by height; mode height {mode_height}") 

358 mode_txs: list[MoneroTxWallet] = wallet.get_txs(query) 

359 assert height_counts[mode_height] == len(mode_txs) 

360 for tx in mode_txs: 

361 assert mode_height == tx.get_height() 

362 

363 # fetch txs at mode height by range 

364 query = MoneroTxQuery() 

365 query.min_height = mode_height 

366 query.max_height = mode_height 

367 logger.debug(f"Getting mode txs by range; mode height {mode_height}") 

368 mode_txs_by_range: list[MoneroTxWallet] = wallet.get_txs(query) 

369 # TODO test txs order is failing 

370 TxWalletUtils.assert_list_txs_equals(mode_txs, mode_txs_by_range) 

371 

372 # fetch all txs by range 

373 query = MoneroTxQuery() 

374 query.min_height = txs[0].get_height() 

375 query.max_height = txs[-1].get_height() 

376 all_txs: list[MoneroTxWallet] = wallet.get_txs(query) 

377 # TODO test txs order is failing 

378 TxWalletUtils.assert_list_txs_equals(txs, all_txs) 

379 

380 # test some filtered by range 

381 try: 

382 query = MoneroTxQuery() 

383 query.is_confirmed = True 

384 txs = wallet.get_txs(query) 

385 assert len(txs) > 0, "No transactions; run send to multiple test" 

386 

387 # get and sort block heights in ascending order 

388 heights: list[int] = [] 

389 for tx in txs: 

390 assert tx.block is not None 

391 assert tx.block.height is not None 

392 heights.append(tx.block.height) 

393 

394 heights.sort() 

395 

396 # pick minimum and maximum heights for filtering 

397 min_height: int = -1 

398 max_height: int = -1 

399 if len(heights) == 1: 

400 min_height = 0 

401 max_height = heights[0] - 1 

402 else: 

403 min_height = heights[0] + 1 

404 max_height = heights[-1] - 1 

405 

406 # assert some transactions filtered 

407 unfiltered_count: int = len(txs) 

408 query = MoneroTxQuery() 

409 query.min_height = min_height 

410 query.max_height = max_height 

411 txs = WalletTxsUtils.get_and_test_txs(wallet, query, None, True, TestUtils.REGTEST) 

412 assert len(txs) < unfiltered_count 

413 for tx in txs: 

414 assert tx.block is not None 

415 assert tx.block.height is not None 

416 height: int = tx.block.height 

417 assert height >= min_height and height <= max_height 

418 

419 except Exception as e: 

420 logger.debug(str(e)) 

421 

422 # Can get transactions with payment id 

423 @pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False or TestUtils.LITE_MODE, reason="TEST_NON_RELAYS disabled or LITE_MODE enabled") 

424 def test_get_txs_with_payment_ids(self, wallet: MoneroWallet) -> None: 

425 # get random transactions with payment ids for testing 

426 tx_query: MoneroTxQuery = MoneroTxQuery() 

427 tx_query.has_payment_id = True 

428 random_txs: list[MoneroTxWallet] = WalletTxsUtils.get_random_transactions(wallet, tx_query, 2, 5) 

429 assert len(random_txs) > 0, "No txs with payment ids to test" 

430 for random_tx in random_txs: 

431 assert random_tx.payment_id is not None and len(random_tx.payment_id) > 0 

432 

433 # get transactions by payment id 

434 payment_ids: list[str] = [] 

435 for tx in random_txs: 

436 assert tx.payment_id is not None 

437 payment_ids.append(tx.payment_id) 

438 

439 assert len(payment_ids) > 1 

440 for payment_id in payment_ids: 

441 tx_query = MoneroTxQuery() 

442 tx_query.payment_id = payment_id 

443 txs: list[MoneroTxWallet] = WalletTxsUtils.get_and_test_txs(wallet, tx_query, None, None, TestUtils.REGTEST) 

444 assert len(txs) > 0 

445 first_payment_id: Optional[str] = txs[0].payment_id 

446 assert first_payment_id is not None 

447 MoneroUtils.validate_payment_id(first_payment_id) 

448 

449 # get transactions by payment hashes 

450 tx_query = MoneroTxQuery() 

451 tx_query.payment_ids = payment_ids 

452 txs: list[MoneroTxWallet] = WalletTxsUtils.get_and_test_txs(wallet, tx_query, None, None, TestUtils.REGTEST) 

453 for tx in txs: 

454 assert tx.payment_id is not None 

455 assert tx.payment_id in payment_ids 

456 

457 # Returns all known fields of txs regardless of filtering 

458 @pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") 

459 def test_get_txs_fields_with_filtering(self, wallet: MoneroWallet) -> None: 

460 # fetch wallet txs 

461 tx_query: MoneroTxQuery = MoneroTxQuery() 

462 tx_query.is_confirmed = True 

463 txs: list[MoneroTxWallet] = wallet.get_txs(tx_query) 

464 

465 for tx in txs: 

466 # find tx sent to same wallet with incoming transfer in different account than src account 

467 if tx.outgoing_transfer is None or len(tx.incoming_transfers) == 0: 

468 continue 

469 for transfer in tx.incoming_transfers: 

470 if transfer.account_index == tx.outgoing_transfer.account_index: 

471 continue 

472 

473 # fetch tx with filtering 

474 tx_query = MoneroTxQuery() 

475 tx_query.transfer_query = MoneroTransferQuery() 

476 tx_query.transfer_query.incoming = True 

477 tx_query.transfer_query.account_index = transfer.account_index 

478 filtered_txs: list[MoneroTxWallet] = wallet.get_txs(tx_query) 

479 

480 for filtered_tx in filtered_txs: 

481 assert filtered_tx.hash is not None 

482 if filtered_tx.hash == tx.hash: 

483 tx.merge(filtered_tx) 

484 # test is done 

485 return 

486 

487 raise Exception("Test requires tx sent from/to different accounts of same wallet but none found; run send tests") 

488 

489 # Validates inputs when getting transactions 

490 @pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False or TestUtils.LITE_MODE, reason="TEST_NON_RELAYS disabled or LITE_MODE enabled") 

491 def test_validate_inputs_get_txs(self, wallet: MoneroWallet) -> None: 

492 # fetch random txs for testing 

493 random_txs: list[MoneroTxWallet] = WalletTxsUtils.get_random_transactions(wallet, None, 3, 5) 

494 

495 # valid, invalid, and unknown tx hashes for tests 

496 tx_hash: str | None = random_txs[0].hash 

497 invalid_hash: str = "invalid_id" 

498 unknown_hash1: str = "6c4982f2499ece80e10b627083c4f9b992a00155e98bcba72a9588ccb91d0a61" 

499 unknown_hash2: str = "ff397104dd875882f5e7c66e4f852ee134f8cf45e21f0c40777c9188bc92e943" 

500 assert tx_hash is not None and len(tx_hash) > 0 

501 

502 # fetch unknown tx hash 

503 fetched_tx: MoneroTxWallet | None = wallet.get_tx(unknown_hash1) 

504 assert fetched_tx is None 

505 

506 # fetch unknown tx hash using query 

507 tx_query: MoneroTxQuery = MoneroTxQuery() 

508 tx_query.hash = unknown_hash1 

509 fetched_txs: list[MoneroTxWallet] = wallet.get_txs(tx_query) 

510 assert len(fetched_txs) == 0 

511 

512 # fetch unknown tx hash in list 

513 txs: list[MoneroTxWallet] = wallet.get_txs([tx_hash, unknown_hash1]) 

514 assert len(txs) == 1 

515 assert txs[0].hash == tx_hash 

516 

517 # fetch unknown tx hashes in list 

518 txs = wallet.get_txs([tx_hash, unknown_hash1, unknown_hash2]) 

519 assert len(txs) == 1 

520 assert txs[0].hash == tx_hash 

521 

522 # fetch invalid hash 

523 fetched_tx = wallet.get_tx(invalid_hash) 

524 assert fetched_tx is None 

525 

526 # fetch invalid hash list 

527 txs = wallet.get_txs([tx_hash, invalid_hash]) 

528 assert len(txs) == 1 

529 assert txs[0].hash == tx_hash 

530 

531 # fetch invalid hashes in list 

532 txs = wallet.get_txs([tx_hash, invalid_hash, "invalid_hash_2"]) 

533 assert len(txs) == 1 

534 assert txs[0].hash == tx_hash 

535 

536 # test collection of invalid hashes 

537 tx_query = MoneroTxQuery() 

538 tx_query.hashes = [tx_hash, invalid_hash, "invalid_hash_2"] 

539 txs = wallet.get_txs(tx_query) 

540 assert len(txs) == 1 

541 

542 # test txs 

543 for tx in txs: 

544 TxWalletUtils.test_tx_wallet(tx) 

545 

546 # Can get and set a transaction note 

547 @pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") 

548 def test_set_tx_note(self, wallet: MoneroWallet) -> None: 

549 txs: list[MoneroTxWallet] = WalletTxsUtils.get_random_transactions(wallet, None, 1, 5) 

550 

551 # set notes 

552 uuid: str = StringUtils.get_random_string() 

553 

554 for i, tx in enumerate(txs): 

555 tx_hash: str | None = tx.hash 

556 assert tx_hash is not None 

557 wallet.set_tx_note(tx_hash, f"{uuid}{i}") 

558 

559 # get notes 

560 for i, tx in enumerate(txs): 

561 tx_hash: str | None = tx.hash 

562 assert tx_hash is not None 

563 assert wallet.get_tx_note(tx_hash) == f"{uuid}{i}" 

564 

565 # Can get and set multiple transaction notes 

566 # TODO why does getting cached txs take 2 seconds when should already be cached? 

567 @pytest.mark.skipif(TestUtils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled") 

568 def test_set_tx_notes(self, wallet: MoneroWallet) -> None: 

569 # set tx notes 

570 uuid: str = StringUtils.get_random_string() 

571 txs: list[MoneroTxWallet] = wallet.get_txs() 

572 assert len(txs) >= 3, "Test requires 3 or more wallet transactions run send tests" 

573 tx_hashes: list[str] = [] 

574 tx_notes: list[str] = [] 

575 for i, tx_hash in enumerate(tx_hashes): 

576 assert tx_hash is not None 

577 tx_hashes.append(tx_hash) 

578 tx_notes.append(f"{uuid}{i}") 

579 

580 wallet.set_tx_notes(tx_hashes, tx_notes) 

581 

582 # get tx notes 

583 tx_notes: list[str] = wallet.get_tx_notes(tx_hashes) 

584 for i, tx_note in enumerate(tx_notes): 

585 assert f"{uuid}{i}" == tx_note 

586 

587 

588@pytest.mark.integration 

589class TestMoneroWalletFullTxs(FullWalletSupport, BaseTestMoneroWalletTxs): 

590 """Full wallet txs integration tests.""" 

591 

592 

593@pytest.mark.integration 

594class TestMoneroWalletRpcTxs(RpcWalletSupport, BaseTestMoneroWalletTxs): 

595 """Rpc wallet txs integration tests.""" 

596 

597 

598@pytest.mark.unit 

599class TestMoneroWalletKeysTxs(KeysWalletSupport, BaseTestMoneroWalletTxs): 

600 """Keys-only wallet txs unit tests.""" 

601 

602 @pytest.mark.not_supported 

603 @override 

604 def test_get_txs_wallet(self, wallet: MoneroWallet) -> None: 

605 return super().test_get_txs_wallet(wallet) 

606 

607 @pytest.mark.not_supported 

608 @override 

609 def test_get_txs_by_hash(self, wallet: MoneroWallet) -> None: 

610 return super().test_get_txs_by_hash(wallet) 

611 

612 @pytest.mark.not_supported 

613 @override 

614 def test_get_txs_with_query(self, wallet: MoneroWallet) -> None: 

615 return super().test_get_txs_with_query(wallet) 

616 

617 @pytest.mark.not_supported 

618 @override 

619 def test_validate_inputs_get_txs(self, wallet: MoneroWallet) -> None: 

620 return super().test_validate_inputs_get_txs(wallet) 

621 

622 @pytest.mark.not_supported 

623 @override 

624 def test_set_tx_note(self, wallet: MoneroWallet) -> None: 

625 return super().test_set_tx_note(wallet) 

626 

627 @pytest.mark.not_supported 

628 @override 

629 def test_set_tx_notes(self, wallet: MoneroWallet) -> None: 

630 return super().test_set_tx_notes(wallet) 

631 

632 @pytest.mark.not_supported 

633 @override 

634 def test_get_txs_by_height(self, wallet: MoneroWallet) -> None: 

635 return super().test_get_txs_by_height(wallet) 

636 

637 @pytest.mark.not_supported 

638 @override 

639 def test_get_txs_with_payment_ids(self, wallet: MoneroWallet) -> None: 

640 return super().test_get_txs_with_payment_ids(wallet) 

641 

642 @pytest.mark.not_supported 

643 @override 

644 def test_get_txs_fields_with_filtering(self, wallet: MoneroWallet) -> None: 

645 return super().test_get_txs_fields_with_filtering(wallet)