1
1
#!/usr/bin/env python3
2
- # Copyright (c) 2018 The Bitcoin Core developers
2
+ # Copyright (c) 2018-2019 The Bitcoin Core developers
3
3
# Distributed under the MIT software license, see the accompanying
4
4
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
"""Test the wallet balance RPC methods."""
6
6
from decimal import Decimal
7
7
8
+ from test_framework .address import ADDRESS_BCRT1_UNSPENDABLE as ADDRESS_WATCHONLY
8
9
from test_framework .test_framework import BitcoinTestFramework
9
10
from test_framework .util import (
10
11
assert_equal ,
11
12
assert_raises_rpc_error ,
12
13
)
13
14
14
- RANDOM_COINBASE_ADDRESS = 'mneYUmWYsuk7kySiURxCi3AGxrAqZxLgPZ'
15
15
16
16
def create_transactions (node , address , amt , fees ):
17
17
# Create and sign raw transactions from node to address for amt.
@@ -46,16 +46,17 @@ def skip_test_if_missing_module(self):
46
46
self .skip_if_no_wallet ()
47
47
48
48
def run_test (self ):
49
+ self .nodes [0 ].importaddress (ADDRESS_WATCHONLY )
49
50
# Check that nodes don't own any UTXOs
50
51
assert_equal (len (self .nodes [0 ].listunspent ()), 0 )
51
52
assert_equal (len (self .nodes [1 ].listunspent ()), 0 )
52
53
53
- self .log .info ("Mining one block for each node " )
54
+ self .log .info ("Mining blocks ... " )
54
55
55
56
self .nodes [0 ].generate (1 )
56
57
self .sync_all ()
57
58
self .nodes [1 ].generate (1 )
58
- self .nodes [1 ].generatetoaddress (100 , RANDOM_COINBASE_ADDRESS )
59
+ self .nodes [1 ].generatetoaddress (101 , ADDRESS_WATCHONLY )
59
60
self .sync_all ()
60
61
61
62
assert_equal (self .nodes [0 ].getbalance (), 50 )
@@ -64,8 +65,10 @@ def run_test(self):
64
65
self .log .info ("Test getbalance with different arguments" )
65
66
assert_equal (self .nodes [0 ].getbalance ("*" ), 50 )
66
67
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 )
68
69
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 )
69
72
70
73
# Send 40 BTC from 0 to 1 and 60 BTC from 1 to 0.
71
74
txs = create_transactions (self .nodes [0 ], self .nodes [1 ].getnewaddress (), 40 , [Decimal ('0.01' )])
@@ -108,7 +111,7 @@ def run_test(self):
108
111
assert_equal (self .nodes [1 ].getwalletinfo ()["unconfirmed_balance" ], Decimal ('0' )) # Doesn't include output of node 0's send since it was spent
109
112
assert_equal (self .nodes [1 ].getunconfirmedbalance (), Decimal ('0' ))
110
113
111
- self .nodes [1 ].generatetoaddress (1 , RANDOM_COINBASE_ADDRESS )
114
+ self .nodes [1 ].generatetoaddress (1 , ADDRESS_WATCHONLY )
112
115
self .sync_all ()
113
116
114
117
# balances are correct after the transactions are confirmed
@@ -118,7 +121,7 @@ def run_test(self):
118
121
# Send total balance away from node 1
119
122
txs = create_transactions (self .nodes [1 ], self .nodes [0 ].getnewaddress (), Decimal ('29.97' ), [Decimal ('0.01' )])
120
123
self .nodes [1 ].sendrawtransaction (txs [0 ]['hex' ])
121
- self .nodes [1 ].generatetoaddress (2 , RANDOM_COINBASE_ADDRESS )
124
+ self .nodes [1 ].generatetoaddress (2 , ADDRESS_WATCHONLY )
122
125
self .sync_all ()
123
126
124
127
# getbalance with a minconf incorrectly excludes coins that have been spent more recently than the minconf blocks ago
0 commit comments