Skip to content

Commit 5cc32ee

Browse files
committed
test: Test for balance update due to untracked output becoming spendable
1 parent 8222341 commit 5cc32ee

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/functional/wallet_balance.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test the wallet balance RPC methods."""
66
from decimal import Decimal
7+
import time
78

89
from test_framework.address import ADDRESS_BCRT1_UNSPENDABLE as ADDRESS_WATCHONLY
910
from test_framework.blocktools import COINBASE_MATURITY
11+
from test_framework.descriptors import descsum_create
1012
from test_framework.test_framework import BitcoinTestFramework
1113
from test_framework.util import (
1214
assert_equal,
1315
assert_is_hash_string,
1416
assert_raises_rpc_error,
1517
)
18+
from test_framework.wallet_util import get_generate_key
1619

1720

1821
def create_transactions(node, address, amt, fees):
@@ -279,5 +282,30 @@ def test_balances(*, fee_node_1=0):
279282
assert_equal(tx_info['lastprocessedblock']['height'], prev_height)
280283
assert_equal(tx_info['lastprocessedblock']['hash'], prev_hash)
281284

285+
self.log.info("Test that the balance is updated by an import that makes an untracked output in an existing tx \"mine\"")
286+
default = self.nodes[0].get_wallet_rpc(self.default_wallet_name)
287+
self.nodes[0].createwallet("importupdate")
288+
wallet = self.nodes[0].get_wallet_rpc("importupdate")
289+
290+
import_key1 = get_generate_key()
291+
import_key2 = get_generate_key()
292+
wallet.importdescriptors([{"desc": descsum_create(f"wpkh({import_key1.privkey})"), "timestamp": "now"}])
293+
294+
amount = 15
295+
default.send([{import_key1.p2wpkh_addr: amount},{import_key2.p2wpkh_addr: amount}])
296+
self.generate(self.nodes[0], 1)
297+
# Mock the time forward by 1 day so that "now" will exclude the block we just mined
298+
self.nodes[0].setmocktime(int(time.time()) + 86400)
299+
# Mine 11 blocks to move the MTP past the block we just mined
300+
self.generate(self.nodes[0], 11, sync_fun=self.no_op)
301+
302+
balances = wallet.getbalances()
303+
assert_equal(balances["mine"]["trusted"], amount)
304+
305+
# Don't rescan to make sure that the import updates the wallet txos
306+
wallet.importdescriptors([{"desc": descsum_create(f"wpkh({import_key2.privkey})"), "timestamp": "now"}])
307+
balances = wallet.getbalances()
308+
assert_equal(balances["mine"]["trusted"], amount * 2)
309+
282310
if __name__ == '__main__':
283311
WalletTest(__file__).main()

0 commit comments

Comments
 (0)