2 # Copyright (c) 2017 The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
7 Verify that a bitcoind node can load multiple wallet files
9 from test_framework
.test_framework
import BitcoinTestFramework
10 from test_framework
.util
import assert_equal
, assert_raises_jsonrpc
12 class MultiWalletTest(BitcoinTestFramework
):
16 self
.setup_clean_chain
= True
18 self
.extra_args
= [['-wallet=w1', '-wallet=w2', '-wallet=w3']]
23 # should not initialize if there are duplicate wallets
24 self
.assert_start_raises_init_error(0, self
.options
.tmpdir
, ['-wallet=w1', '-wallet=w1'], 'Duplicate -wallet filename')
26 self
.nodes
[0] = self
.start_node(0, self
.options
.tmpdir
, self
.extra_args
[0])
28 w1
= self
.nodes
[0] / "wallet/w1"
31 # accessing invalid wallet fails
32 assert_raises_jsonrpc(-18, "Requested wallet does not exist or is not loaded", (self
.nodes
[0] / "wallet/bad").getwalletinfo
)
34 # accessing wallet RPC without using wallet endpoint fails
35 assert_raises_jsonrpc(-19, "Wallet file not specified", self
.nodes
[0].getwalletinfo
)
37 # check w1 wallet balance
38 w1_info
= w1
.getwalletinfo()
39 assert_equal(w1_info
['immature_balance'], 50)
40 w1_name
= w1_info
['walletname']
41 assert_equal(w1_name
, "w1")
43 # check w1 wallet balance
44 w2
= self
.nodes
[0] / "wallet/w2"
45 w2_info
= w2
.getwalletinfo()
46 assert_equal(w2_info
['immature_balance'], 0)
47 w2_name
= w2_info
['walletname']
48 assert_equal(w2_name
, "w2")
50 w3
= self
.nodes
[0] / "wallet/w3"
51 w3_name
= w3
.getwalletinfo()['walletname']
52 assert_equal(w3_name
, "w3")
54 assert_equal({"w1", "w2", "w3"}, {w1_name
, w2_name
, w3_name
})
57 assert_equal(w1
.getbalance(), 100)
58 assert_equal(w2
.getbalance(), 0)
59 assert_equal(w3
.getbalance(), 0)
61 w1
.sendtoaddress(w2
.getnewaddress(), 1)
62 w1
.sendtoaddress(w3
.getnewaddress(), 2)
64 assert_equal(w2
.getbalance(), 1)
65 assert_equal(w3
.getbalance(), 2)
67 if __name__
== '__main__':
68 MultiWalletTest().main()