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 bitcoin-cli"""
6
+ from decimal import Decimal
6
7
from test_framework .test_framework import BitcoinTestFramework
7
8
from test_framework .util import assert_equal , assert_raises_process_error , get_auth_cookie
8
9
@@ -72,8 +73,48 @@ def run_test(self):
72
73
assert_equal (cli_get_info ['paytxfee' ], wallet_info ['paytxfee' ])
73
74
assert_equal (cli_get_info ['relayfee' ], network_info ['relayfee' ])
74
75
assert_equal (self .nodes [0 ].cli .getwalletinfo (), wallet_info )
76
+
77
+ # Setup to test -getinfo and -rpcwallet= with multiple wallets.
78
+ wallets = ['' , 'Encrypted' , 'secret' ]
79
+ amounts = [Decimal ('59.999928' ), Decimal (9 ), Decimal (31 )]
80
+ self .nodes [0 ].createwallet (wallet_name = wallets [1 ])
81
+ self .nodes [0 ].createwallet (wallet_name = wallets [2 ])
82
+ w1 = self .nodes [0 ].get_wallet_rpc (wallets [0 ])
83
+ w2 = self .nodes [0 ].get_wallet_rpc (wallets [1 ])
84
+ w3 = self .nodes [0 ].get_wallet_rpc (wallets [2 ])
85
+ w1 .walletpassphrase (password , self .rpc_timeout )
86
+ w1 .sendtoaddress (w2 .getnewaddress (), amounts [1 ])
87
+ w1 .sendtoaddress (w3 .getnewaddress (), amounts [2 ])
88
+
89
+ # Mine a block to confirm; adds a block reward (50 BTC) to the default wallet.
90
+ self .nodes [0 ].generate (1 )
91
+
92
+ self .log .info ("Test -getinfo with multiple wallets loaded returns no balance" )
93
+ assert_equal (set (self .nodes [0 ].listwallets ()), set (wallets ))
94
+ assert 'balance' not in self .nodes [0 ].cli ('-getinfo' ).send_cli ().keys ()
95
+
96
+ self .log .info ("Test -getinfo with multiple wallets and -rpcwallet returns specified wallet balance" )
97
+ for i in range (len (wallets )):
98
+ cli_get_info = self .nodes [0 ].cli ('-getinfo' ).send_cli ('-rpcwallet={}' .format (wallets [i ]))
99
+ assert_equal (cli_get_info ['balance' ], amounts [i ])
100
+
101
+ self .log .info ("Test -getinfo with multiple wallets and -rpcwallet=non-existing-wallet returns no balance" )
102
+ assert 'balance' not in self .nodes [0 ].cli ('-getinfo' ).send_cli ('-rpcwallet=does-not-exist' ).keys ()
103
+
104
+ self .log .info ("Test -getinfo after unloading all wallets except a non-default one returns its balance" )
105
+ self .nodes [0 ].unloadwallet (wallets [0 ])
106
+ self .nodes [0 ].unloadwallet (wallets [2 ])
107
+ assert_equal (self .nodes [0 ].listwallets (), [wallets [1 ]])
108
+ assert_equal (self .nodes [0 ].cli ('-getinfo' ).send_cli ()['balance' ], amounts [1 ])
109
+
110
+ self .log .info ("Test -getinfo -rpcwallet=remaining-non-default-wallet returns its balance" )
111
+ assert_equal (self .nodes [0 ].cli ('-getinfo' ).send_cli ('-rpcwallet={}' .format (wallets [1 ]))['balance' ], amounts [1 ])
112
+
113
+ self .log .info ("Test -getinfo with -rpcwallet=unloaded wallet returns no balance" )
114
+ assert 'balance' not in self .nodes [0 ].cli ('-getinfo' ).send_cli ('-rpcwallet={}' .format (wallets [2 ])).keys ()
75
115
else :
76
116
self .log .info ("*** Wallet not compiled; cli getwalletinfo and -getinfo wallet tests skipped" )
117
+ self .nodes [0 ].generate (1 ) # maintain block parity with the wallet_compiled conditional branch
77
118
78
119
self .log .info ("Test -version with node stopped" )
79
120
self .stop_node (0 )
@@ -85,7 +126,7 @@ def run_test(self):
85
126
self .nodes [0 ].wait_for_cookie_credentials () # ensure cookie file is available to avoid race condition
86
127
blocks = self .nodes [0 ].cli ('-rpcwait' ).send_cli ('getblockcount' )
87
128
self .nodes [0 ].wait_for_rpc_connection ()
88
- assert_equal (blocks , BLOCKS )
129
+ assert_equal (blocks , BLOCKS + 1 )
89
130
90
131
91
132
if __name__ == '__main__' :
0 commit comments