From fc0caaf4aa3d4b26a8673cca48df1a4f0b964a59 Mon Sep 17 00:00:00 2001 From: Miles Liu Date: Thu, 15 Dec 2022 22:50:51 +0800 Subject: [PATCH] test: Add "include mempool" flag to MiniWallet rescan_utxos --- test/functional/test_framework/wallet.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/functional/test_framework/wallet.py b/test/functional/test_framework/wallet.py index 2b4aa2bf5c3..5dacf9d8d2c 100644 --- a/test/functional/test_framework/wallet.py +++ b/test/functional/test_framework/wallet.py @@ -119,7 +119,7 @@ class MiniWallet: def get_balance(self): return sum(u['value'] for u in self._utxos) - def rescan_utxos(self): + def rescan_utxos(self, *, include_mempool=True): """Drop all utxos and rescan the utxo set""" self._utxos = [] res = self._test_node.scantxoutset(action="start", scanobjects=[self.get_descriptor()]) @@ -132,6 +132,12 @@ class MiniWallet: height=utxo["height"], coinbase=utxo["coinbase"], confirmations=res["height"] - utxo["height"] + 1)) + if include_mempool: + mempool = self._test_node.getrawmempool(verbose=True) + # Sort tx by ancestor count. See BlockAssembler::SortForBlock in src/node/miner.cpp + sorted_mempool = sorted(mempool.items(), key=lambda item: (item[1]["ancestorcount"], int(item[0], 16))) + for txid, _ in sorted_mempool: + self.scan_tx(self._test_node.getrawtransaction(txid=txid, verbose=True)) def scan_tx(self, tx): """Scan the tx and adjust the internal list of owned utxos"""