Skip to content

Commit a14dbff

Browse files
ryanofskyjnewbery
authored andcommitted
Allow multiwallet.py to be used with --usecli
Add test coverage for bitcoin-cli multiwallet calls.
1 parent f6ade9c commit a14dbff

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

test/functional/multiwallet.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,69 +17,75 @@ def set_test_params(self):
1717
self.setup_clean_chain = True
1818
self.num_nodes = 1
1919
self.extra_args = [['-wallet=w1', '-wallet=w2', '-wallet=w3', '-wallet=w']]
20+
self.supports_cli = True
2021

2122
def run_test(self):
22-
assert_equal(set(self.nodes[0].listwallets()), {"w1", "w2", "w3", "w"})
23+
node = self.nodes[0]
24+
25+
data_dir = lambda *p: os.path.join(node.datadir, 'regtest', *p)
26+
wallet_dir = lambda *p: data_dir('wallets', *p)
27+
wallet = lambda name: node.get_wallet_rpc(name)
28+
29+
assert_equal(set(node.listwallets()), {"w1", "w2", "w3", "w"})
2330

2431
self.stop_node(0)
2532

2633
# should not initialize if there are duplicate wallets
2734
self.assert_start_raises_init_error(0, ['-wallet=w1', '-wallet=w1'], 'Error loading wallet w1. Duplicate -wallet filename specified.')
2835

2936
# should not initialize if wallet file is a directory
30-
wallet_dir = os.path.join(self.options.tmpdir, 'node0', 'regtest', 'wallets')
31-
os.mkdir(os.path.join(wallet_dir, 'w11'))
37+
os.mkdir(wallet_dir('w11'))
3238
self.assert_start_raises_init_error(0, ['-wallet=w11'], 'Error loading wallet w11. -wallet filename must be a regular file.')
3339

3440
# should not initialize if one wallet is a copy of another
35-
shutil.copyfile(os.path.join(wallet_dir, 'w2'), os.path.join(wallet_dir, 'w22'))
41+
shutil.copyfile(wallet_dir('w2'), wallet_dir('w22'))
3642
self.assert_start_raises_init_error(0, ['-wallet=w2', '-wallet=w22'], 'duplicates fileid')
3743

3844
# should not initialize if wallet file is a symlink
39-
os.symlink(os.path.join(wallet_dir, 'w1'), os.path.join(wallet_dir, 'w12'))
45+
os.symlink(wallet_dir('w1'), wallet_dir('w12'))
4046
self.assert_start_raises_init_error(0, ['-wallet=w12'], 'Error loading wallet w12. -wallet filename must be a regular file.')
4147

4248
# should not initialize if the specified walletdir does not exist
4349
self.assert_start_raises_init_error(0, ['-walletdir=bad'], 'Error: Specified -walletdir "bad" does not exist')
4450
# should not initialize if the specified walletdir is not a directory
45-
not_a_dir = os.path.join(wallet_dir, 'notadir')
51+
not_a_dir = wallet_dir('notadir')
4652
open(not_a_dir, 'a').close()
47-
self.assert_start_raises_init_error(0, ['-walletdir='+not_a_dir], 'Error: Specified -walletdir "' + not_a_dir + '" is not a directory')
53+
self.assert_start_raises_init_error(0, ['-walletdir=' + not_a_dir], 'Error: Specified -walletdir "' + not_a_dir + '" is not a directory')
4854

4955
# if wallets/ doesn't exist, datadir should be the default wallet dir
50-
wallet_dir2 = os.path.join(self.options.tmpdir, 'node0', 'regtest', 'walletdir')
51-
os.rename(wallet_dir, wallet_dir2)
56+
wallet_dir2 = data_dir('walletdir')
57+
os.rename(wallet_dir(), wallet_dir2)
5258
self.start_node(0, ['-wallet=w4', '-wallet=w5'])
53-
assert_equal(set(self.nodes[0].listwallets()), {"w4", "w5"})
54-
w5 = self.nodes[0].get_wallet_rpc("w5")
59+
assert_equal(set(node.listwallets()), {"w4", "w5"})
60+
w5 = wallet("w5")
5561
w5.generate(1)
5662
self.stop_node(0)
5763

5864
# now if wallets/ exists again, but the rootdir is specified as the walletdir, w4 and w5 should still be loaded
59-
os.rename(wallet_dir2, wallet_dir)
60-
self.start_node(0, ['-wallet=w4', '-wallet=w5', '-walletdir=' + os.path.join(self.options.tmpdir, 'node0', 'regtest')])
61-
assert_equal(set(self.nodes[0].listwallets()), {"w4", "w5"})
62-
w5 = self.nodes[0].get_wallet_rpc("w5")
65+
os.rename(wallet_dir2, wallet_dir())
66+
self.start_node(0, ['-wallet=w4', '-wallet=w5', '-walletdir=' + data_dir()])
67+
assert_equal(set(node.listwallets()), {"w4", "w5"})
68+
w5 = wallet("w5")
6369
w5_info = w5.getwalletinfo()
6470
assert_equal(w5_info['immature_balance'], 50)
6571

6672
self.stop_node(0)
6773

6874
self.start_node(0, self.extra_args[0])
6975

70-
w1 = self.nodes[0].get_wallet_rpc("w1")
71-
w2 = self.nodes[0].get_wallet_rpc("w2")
72-
w3 = self.nodes[0].get_wallet_rpc("w3")
73-
w4 = self.nodes[0].get_wallet_rpc("w")
74-
wallet_bad = self.nodes[0].get_wallet_rpc("bad")
76+
w1 = wallet("w1")
77+
w2 = wallet("w2")
78+
w3 = wallet("w3")
79+
w4 = wallet("w")
80+
wallet_bad = wallet("bad")
7581

7682
w1.generate(1)
7783

7884
# accessing invalid wallet fails
7985
assert_raises_rpc_error(-18, "Requested wallet does not exist or is not loaded", wallet_bad.getwalletinfo)
8086

8187
# accessing wallet RPC without using wallet endpoint fails
82-
assert_raises_rpc_error(-19, "Wallet file not specified", self.nodes[0].getwalletinfo)
88+
assert_raises_rpc_error(-19, "Wallet file not specified", node.getwalletinfo)
8389

8490
# check w1 wallet balance
8591
w1_info = w1.getwalletinfo()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
'mempool_reorg.py',
9393
'mempool_persist.py',
9494
'multiwallet.py',
95+
'multiwallet.py --usecli',
9596
'httpbasics.py',
9697
'multi_rpc.py',
9798
'proxy_test.py',

0 commit comments

Comments
 (0)