Skip to content

Commit fa464e8

Browse files
author
MarcoFalke
committed
test: Add wallet_balance test for watchonly
1 parent c83442e commit fa464e8

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

test/functional/wallet_balance.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#!/usr/bin/env python3
2-
# Copyright (c) 2018 The Bitcoin Core developers
2+
# Copyright (c) 2018-2019 The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test the wallet balance RPC methods."""
66
from decimal import Decimal
77

8+
from test_framework.address import ADDRESS_BCRT1_UNSPENDABLE as ADDRESS_WATCHONLY
89
from test_framework.test_framework import BitcoinTestFramework
910
from test_framework.util import (
1011
assert_equal,
1112
assert_raises_rpc_error,
1213
)
1314

14-
RANDOM_COINBASE_ADDRESS = 'mneYUmWYsuk7kySiURxCi3AGxrAqZxLgPZ'
1515

1616
def create_transactions(node, address, amt, fees):
1717
# Create and sign raw transactions from node to address for amt.
@@ -46,16 +46,17 @@ def skip_test_if_missing_module(self):
4646
self.skip_if_no_wallet()
4747

4848
def run_test(self):
49+
self.nodes[0].importaddress(ADDRESS_WATCHONLY)
4950
# Check that nodes don't own any UTXOs
5051
assert_equal(len(self.nodes[0].listunspent()), 0)
5152
assert_equal(len(self.nodes[1].listunspent()), 0)
5253

53-
self.log.info("Mining one block for each node")
54+
self.log.info("Mining blocks ...")
5455

5556
self.nodes[0].generate(1)
5657
self.sync_all()
5758
self.nodes[1].generate(1)
58-
self.nodes[1].generatetoaddress(100, RANDOM_COINBASE_ADDRESS)
59+
self.nodes[1].generatetoaddress(101, ADDRESS_WATCHONLY)
5960
self.sync_all()
6061

6162
assert_equal(self.nodes[0].getbalance(), 50)
@@ -64,8 +65,10 @@ def run_test(self):
6465
self.log.info("Test getbalance with different arguments")
6566
assert_equal(self.nodes[0].getbalance("*"), 50)
6667
assert_equal(self.nodes[0].getbalance("*", 1), 50)
67-
assert_equal(self.nodes[0].getbalance("*", 1, True), 50)
68+
assert_equal(self.nodes[0].getbalance("*", 1, True), 100)
6869
assert_equal(self.nodes[0].getbalance(minconf=1), 50)
70+
assert_equal(self.nodes[0].getbalance(minconf=0, include_watchonly=True), 100)
71+
assert_equal(self.nodes[1].getbalance(minconf=0, include_watchonly=True), 50)
6972

7073
# Send 40 BTC from 0 to 1 and 60 BTC from 1 to 0.
7174
txs = create_transactions(self.nodes[0], self.nodes[1].getnewaddress(), 40, [Decimal('0.01')])
@@ -108,7 +111,7 @@ def run_test(self):
108111
assert_equal(self.nodes[1].getwalletinfo()["unconfirmed_balance"], Decimal('0')) # Doesn't include output of node 0's send since it was spent
109112
assert_equal(self.nodes[1].getunconfirmedbalance(), Decimal('0'))
110113

111-
self.nodes[1].generatetoaddress(1, RANDOM_COINBASE_ADDRESS)
114+
self.nodes[1].generatetoaddress(1, ADDRESS_WATCHONLY)
112115
self.sync_all()
113116

114117
# balances are correct after the transactions are confirmed
@@ -118,7 +121,7 @@ def run_test(self):
118121
# Send total balance away from node 1
119122
txs = create_transactions(self.nodes[1], self.nodes[0].getnewaddress(), Decimal('29.97'), [Decimal('0.01')])
120123
self.nodes[1].sendrawtransaction(txs[0]['hex'])
121-
self.nodes[1].generatetoaddress(2, RANDOM_COINBASE_ADDRESS)
124+
self.nodes[1].generatetoaddress(2, ADDRESS_WATCHONLY)
122125
self.sync_all()
123126

124127
# getbalance with a minconf incorrectly excludes coins that have been spent more recently than the minconf blocks ago

0 commit comments

Comments
 (0)