Skip to content

Commit

Permalink
Merge bitcoin#23017: test: Replace MiniWallet scan_blocks with rescan…
Browse files Browse the repository at this point in the history
…_utxos

fa7e3f1 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 fa7e3f1

Tree-SHA512: 6f47d2acac9f180b2b0f8f04797e74ecb1fc180f6b164c67813a3a1f97acea54baed74e5e0a3512e3babf76b105c09e1ba4cad818c83c7cb2beb7377b4c96954
  • Loading branch information
merge-script authored and vijaydasmp committed Sep 6, 2024
1 parent f222f79 commit c9bf502
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
8 changes: 4 additions & 4 deletions test/functional/mempool_spend_coinbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion test/functional/rpc_blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions test/functional/test_framework/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,6 @@ def rescan_utxos(self):
for utxo in res['unspents']:
self._utxos.append({'txid': utxo['txid'], 'vout': utxo['vout'], 'value': utxo['amount'], 'height': utxo['height']})

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']:
Expand Down

0 comments on commit c9bf502

Please sign in to comment.