Skip to content

Commit 5edad5c

Browse files
committed
test: add -getinfo multiwallet functional tests
and improve the existing -getinfo -rpcwallet tests.
1 parent 903b6c1 commit 5edad5c

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

test/functional/interface_bitcoin_cli.py

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def run_test(self):
6767
if self.is_wallet_compiled():
6868
self.log.info("Test -getinfo and bitcoin-cli getwalletinfo return expected wallet info")
6969
assert_equal(cli_get_info['balance'], BALANCE)
70+
assert 'balances' not in cli_get_info.keys()
7071
wallet_info = self.nodes[0].getwalletinfo()
7172
assert_equal(cli_get_info['keypoolsize'], wallet_info['keypoolsize'])
7273
assert_equal(cli_get_info['unlocked_until'], wallet_info['unlocked_until'])
@@ -76,42 +77,60 @@ def run_test(self):
7677

7778
# Setup to test -getinfo and -rpcwallet= with multiple wallets.
7879
wallets = ['', 'Encrypted', 'secret']
79-
amounts = [Decimal('59.999928'), Decimal(9), Decimal(31)]
80+
amounts = [BALANCE + Decimal('9.999928'), Decimal(9), Decimal(31)]
8081
self.nodes[0].createwallet(wallet_name=wallets[1])
8182
self.nodes[0].createwallet(wallet_name=wallets[2])
8283
w1 = self.nodes[0].get_wallet_rpc(wallets[0])
8384
w2 = self.nodes[0].get_wallet_rpc(wallets[1])
8485
w3 = self.nodes[0].get_wallet_rpc(wallets[2])
8586
w1.walletpassphrase(password, self.rpc_timeout)
87+
w2.encryptwallet(password)
8688
w1.sendtoaddress(w2.getnewaddress(), amounts[1])
8789
w1.sendtoaddress(w3.getnewaddress(), amounts[2])
8890

8991
# Mine a block to confirm; adds a block reward (50 BTC) to the default wallet.
9092
self.nodes[0].generate(1)
9193

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-
9694
self.log.info("Test -getinfo with multiple wallets and -rpcwallet returns specified wallet balance")
9795
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()
9998
assert_equal(cli_get_info['balance'], amounts[i])
10099

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
103104

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.
105112
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")
106119
self.nodes[0].unloadwallet(wallets[2])
107120
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
115134
else:
116135
self.log.info("*** Wallet not compiled; cli getwalletinfo and -getinfo wallet tests skipped")
117136
self.nodes[0].generate(1) # maintain block parity with the wallet_compiled conditional branch

0 commit comments

Comments
 (0)