From b5a5fb25eae9476c9a6009451ed67c6a8b519f64 Mon Sep 17 00:00:00 2001 From: merge-script Date: Tue, 21 Sep 2021 09:22:30 +0200 Subject: [PATCH] Merge bitcoin/bitcoin#23017: test: Replace MiniWallet scan_blocks with rescan_utxos fa7e3f1fc114056967963a4ad4863a56e406c57e test: Replace MiniWallet scan_blocks with rescan_utxos (MarcoFalke) Pull request description: This avoids having to fiddle with the `start` and `num` parameters and instead use the `scantxoutset` RPC functionality via `rescan_utxos`. ACKs for top commit: Shubhankar-Gambhir: ACK fa7e3f1, all tests were succesfull theStack: re-ACK fa7e3f1fc114056967963a4ad4863a56e406c57e Tree-SHA512: 6f47d2acac9f180b2b0f8f04797e74ecb1fc180f6b164c67813a3a1f97acea54baed74e5e0a3512e3babf76b105c09e1ba4cad818c83c7cb2beb7377b4c96954 --- test/functional/mempool_spend_coinbase.py | 8 ++++---- test/functional/rpc_blockchain.py | 2 +- test/functional/test_framework/wallet.py | 7 ------- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/test/functional/mempool_spend_coinbase.py b/test/functional/mempool_spend_coinbase.py index b900aa0b9c14ea..a8c37886aa4139 100755 --- a/test/functional/mempool_spend_coinbase.py +++ b/test/functional/mempool_spend_coinbase.py @@ -28,14 +28,14 @@ def run_test(self): chain_height = 198 self.nodes[0].invalidateblock(self.nodes[0].getblockhash(chain_height + 1)) assert_equal(chain_height, self.nodes[0].getblockcount()) + wallet.rescan_utxos() # Coinbase at height chain_height-100+1 ok in mempool, should # get mined. Coinbase at height chain_height-100+2 is # too immature to spend. - wallet.scan_blocks(start=chain_height - 100 + 1, num=1) - utxo_mature = wallet.get_utxo() - wallet.scan_blocks(start=chain_height - 100 + 2, num=1) - utxo_immature = wallet.get_utxo() + coinbase_txid = lambda h: self.nodes[0].getblock(self.nodes[0].getblockhash(h))['tx'][0] + utxo_mature = wallet.get_utxo(txid=coinbase_txid(chain_height - 100 + 1)) + utxo_immature = wallet.get_utxo(txid=coinbase_txid(chain_height - 100 + 2)) spend_mature_id = wallet.send_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_mature)["txid"] diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py index b2db3e7b89eb52..7da5308addd917 100755 --- a/test/functional/rpc_blockchain.py +++ b/test/functional/rpc_blockchain.py @@ -420,7 +420,7 @@ def _test_getblock(self): node = self.nodes[0] miniwallet = MiniWallet(node) - miniwallet.scan_blocks(num=5) + miniwallet.rescan_utxos() fee_per_byte = Decimal('0.00000010') fee_per_kb = 1000 * fee_per_byte diff --git a/test/functional/test_framework/wallet.py b/test/functional/test_framework/wallet.py index 829e05ebe4c7ca..b5dcd6b980aeb0 100644 --- a/test/functional/test_framework/wallet.py +++ b/test/functional/test_framework/wallet.py @@ -74,13 +74,6 @@ def __init__(self, test_node, *, mode=MiniWalletMode.ADDRESS_OP_TRUE): self._address = ADDRESS_BCRT1_P2SH_OP_TRUE self._scriptPubKey = hex_str_to_bytes(self._test_node.validateaddress(self._address)['scriptPubKey']) - def scan_blocks(self, *, start=1, num): - """Scan the blocks for self._address outputs and add them to self._utxos""" - for i in range(start, start + num): - block = self._test_node.getblock(blockhash=self._test_node.getblockhash(i), verbosity=2) - for tx in block['tx']: - self.scan_tx(tx) - def scan_tx(self, tx): """Scan the tx for self._scriptPubKey outputs and add them to self._utxos""" for out in tx['vout']: