@@ -67,6 +67,7 @@ def run_test(self):
67
67
if self .is_wallet_compiled ():
68
68
self .log .info ("Test -getinfo and bitcoin-cli getwalletinfo return expected wallet info" )
69
69
assert_equal (cli_get_info ['balance' ], BALANCE )
70
+ assert 'balances' not in cli_get_info .keys ()
70
71
wallet_info = self .nodes [0 ].getwalletinfo ()
71
72
assert_equal (cli_get_info ['keypoolsize' ], wallet_info ['keypoolsize' ])
72
73
assert_equal (cli_get_info ['unlocked_until' ], wallet_info ['unlocked_until' ])
@@ -76,42 +77,60 @@ def run_test(self):
76
77
77
78
# Setup to test -getinfo and -rpcwallet= with multiple wallets.
78
79
wallets = ['' , 'Encrypted' , 'secret' ]
79
- amounts = [Decimal ('59 .999928' ), Decimal (9 ), Decimal (31 )]
80
+ amounts = [BALANCE + Decimal ('9 .999928' ), Decimal (9 ), Decimal (31 )]
80
81
self .nodes [0 ].createwallet (wallet_name = wallets [1 ])
81
82
self .nodes [0 ].createwallet (wallet_name = wallets [2 ])
82
83
w1 = self .nodes [0 ].get_wallet_rpc (wallets [0 ])
83
84
w2 = self .nodes [0 ].get_wallet_rpc (wallets [1 ])
84
85
w3 = self .nodes [0 ].get_wallet_rpc (wallets [2 ])
85
86
w1 .walletpassphrase (password , self .rpc_timeout )
87
+ w2 .encryptwallet (password )
86
88
w1 .sendtoaddress (w2 .getnewaddress (), amounts [1 ])
87
89
w1 .sendtoaddress (w3 .getnewaddress (), amounts [2 ])
88
90
89
91
# Mine a block to confirm; adds a block reward (50 BTC) to the default wallet.
90
92
self .nodes [0 ].generate (1 )
91
93
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
94
self .log .info ("Test -getinfo with multiple wallets and -rpcwallet returns specified wallet balance" )
97
95
for i in range (len (wallets )):
98
- cli_get_info = self .nodes [0 ].cli ('-getinfo' ).send_cli ('-rpcwallet={}' .format (wallets [i ]))
96
+ cli_get_info = self .nodes [0 ].cli ('-getinfo' , '-rpcwallet={}' .format (wallets [i ])).send_cli ()
97
+ assert 'balances' not in cli_get_info .keys ()
99
98
assert_equal (cli_get_info ['balance' ], amounts [i ])
100
99
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 ()
100
+ self .log .info ("Test -getinfo with multiple wallets and -rpcwallet=non-existing-wallet returns no balances" )
101
+ cli_get_info_keys = self .nodes [0 ].cli ('-getinfo' , '-rpcwallet=does-not-exist' ).send_cli ().keys ()
102
+ assert 'balance' not in cli_get_info_keys
103
+ assert 'balances' not in cli_get_info_keys
103
104
104
- self .log .info ("Test -getinfo after unloading all wallets except a non-default one returns its balance" )
105
+ self .log .info ("Test -getinfo with multiple wallets returns all loaded wallet names and balances" )
106
+ assert_equal (set (self .nodes [0 ].listwallets ()), set (wallets ))
107
+ cli_get_info = self .nodes [0 ].cli ('-getinfo' ).send_cli ()
108
+ assert 'balance' not in cli_get_info .keys ()
109
+ assert_equal (cli_get_info ['balances' ], {k : v for k , v in zip (wallets , amounts )})
110
+
111
+ # Unload the default wallet and re-verify.
105
112
self .nodes [0 ].unloadwallet (wallets [0 ])
113
+ assert wallets [0 ] not in self .nodes [0 ].listwallets ()
114
+ cli_get_info = self .nodes [0 ].cli ('-getinfo' ).send_cli ()
115
+ assert 'balance' not in cli_get_info .keys ()
116
+ assert_equal (cli_get_info ['balances' ], {k : v for k , v in zip (wallets [1 :], amounts [1 :])})
117
+
118
+ self .log .info ("Test -getinfo after unloading all wallets except a non-default one returns its balance" )
106
119
self .nodes [0 ].unloadwallet (wallets [2 ])
107
120
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 ()
121
+ cli_get_info = self .nodes [0 ].cli ('-getinfo' ).send_cli ()
122
+ assert 'balances' not in cli_get_info .keys ()
123
+ assert_equal (cli_get_info ['balance' ], amounts [1 ])
124
+
125
+ self .log .info ("Test -getinfo with -rpcwallet=remaining-non-default-wallet returns only its balance" )
126
+ cli_get_info = self .nodes [0 ].cli ('-getinfo' , '-rpcwallet={}' .format (wallets [1 ])).send_cli ()
127
+ assert 'balances' not in cli_get_info .keys ()
128
+ assert_equal (cli_get_info ['balance' ], amounts [1 ])
129
+
130
+ self .log .info ("Test -getinfo with -rpcwallet=unloaded wallet returns no balances" )
131
+ cli_get_info = self .nodes [0 ].cli ('-getinfo' , '-rpcwallet={}' .format (wallets [2 ])).send_cli ()
132
+ assert 'balance' not in cli_get_info_keys
133
+ assert 'balances' not in cli_get_info_keys
115
134
else :
116
135
self .log .info ("*** Wallet not compiled; cli getwalletinfo and -getinfo wallet tests skipped" )
117
136
self .nodes [0 ].generate (1 ) # maintain block parity with the wallet_compiled conditional branch
0 commit comments