Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_multiwallet.py
Show First 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
"Error: -upgradewallet is only allowed with a single wallet file") | "Error: -upgradewallet is only allowed with a single wallet file") | ||||
# if wallets/ doesn't exist, datadir should be the default wallet dir | # if wallets/ doesn't exist, datadir should be the default wallet dir | ||||
wallet_dir2 = data_dir('walletdir') | wallet_dir2 = data_dir('walletdir') | ||||
os.rename(wallet_dir(), wallet_dir2) | os.rename(wallet_dir(), wallet_dir2) | ||||
self.start_node(0, ['-wallet=w4', '-wallet=w5']) | self.start_node(0, ['-wallet=w4', '-wallet=w5']) | ||||
assert_equal(set(node.listwallets()), {"w4", "w5"}) | assert_equal(set(node.listwallets()), {"w4", "w5"}) | ||||
w5 = wallet("w5") | w5 = wallet("w5") | ||||
w5.generate(1) | node.generatetoaddress(nblocks=1, address=w5.getnewaddress()) | ||||
# now if wallets/ exists again, but the rootdir is specified as the | # now if wallets/ exists again, but the rootdir is specified as the | ||||
# walletdir, w4 and w5 should still be loaded | # walletdir, w4 and w5 should still be loaded | ||||
os.rename(wallet_dir2, wallet_dir()) | os.rename(wallet_dir2, wallet_dir()) | ||||
self.restart_node(0, ['-wallet=w4', '-wallet=w5', | self.restart_node(0, ['-wallet=w4', '-wallet=w5', | ||||
'-walletdir=' + data_dir()]) | '-walletdir=' + data_dir()]) | ||||
assert_equal(set(node.listwallets()), {"w4", "w5"}) | assert_equal(set(node.listwallets()), {"w4", "w5"}) | ||||
w5 = wallet("w5") | w5 = wallet("w5") | ||||
Show All 12 Lines | def run_test(self): | ||||
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), [ | assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), [ | ||||
'', os.path.join('sub', 'w5'), 'w', 'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8', 'w8_copy']) | '', os.path.join('sub', 'w5'), 'w', 'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8', 'w8_copy']) | ||||
wallets = [wallet(w) for w in wallet_names] | wallets = [wallet(w) for w in wallet_names] | ||||
wallet_bad = wallet("bad") | wallet_bad = wallet("bad") | ||||
# check wallet names and balances | # check wallet names and balances | ||||
wallets[0].generate(1) | node.generatetoaddress(nblocks=1, address=wallets[0].getnewaddress()) | ||||
for wallet_name, wallet in zip(wallet_names, wallets): | for wallet_name, wallet in zip(wallet_names, wallets): | ||||
info = wallet.getwalletinfo() | info = wallet.getwalletinfo() | ||||
assert_equal(info['immature_balance'], | assert_equal(info['immature_balance'], | ||||
50 if wallet is wallets[0] else 0) | 50 if wallet is wallets[0] else 0) | ||||
assert_equal(info['walletname'], wallet_name) | assert_equal(info['walletname'], wallet_name) | ||||
# accessing invalid wallet fails | # accessing invalid wallet fails | ||||
assert_raises_rpc_error(-18, "Requested wallet does not exist or is not loaded", | assert_raises_rpc_error(-18, "Requested wallet does not exist or is not loaded", | ||||
wallet_bad.getwalletinfo) | wallet_bad.getwalletinfo) | ||||
# accessing wallet RPC without using wallet endpoint fails | # accessing wallet RPC without using wallet endpoint fails | ||||
assert_raises_rpc_error(-19, "Wallet file not specified (must request wallet RPC through /wallet/<filename> uri-path).", | assert_raises_rpc_error(-19, "Wallet file not specified (must request wallet RPC through /wallet/<filename> uri-path).", | ||||
node.getwalletinfo) | node.getwalletinfo) | ||||
w1, w2, w3, w4, *_ = wallets | w1, w2, w3, w4, *_ = wallets | ||||
w1.generate(101) | node.generatetoaddress(nblocks=101, address=w1.getnewaddress()) | ||||
assert_equal(w1.getbalance(), 100) | assert_equal(w1.getbalance(), 100) | ||||
assert_equal(w2.getbalance(), 0) | assert_equal(w2.getbalance(), 0) | ||||
assert_equal(w3.getbalance(), 0) | assert_equal(w3.getbalance(), 0) | ||||
assert_equal(w4.getbalance(), 0) | assert_equal(w4.getbalance(), 0) | ||||
w1.sendtoaddress(w2.getnewaddress(), 1) | w1.sendtoaddress(w2.getnewaddress(), 1) | ||||
w1.sendtoaddress(w3.getnewaddress(), 2) | w1.sendtoaddress(w3.getnewaddress(), 2) | ||||
w1.sendtoaddress(w4.getnewaddress(), 3) | w1.sendtoaddress(w4.getnewaddress(), 3) | ||||
w1.generate(1) | node.generatetoaddress(nblocks=1, address=w1.getnewaddress()) | ||||
assert_equal(w2.getbalance(), 1) | assert_equal(w2.getbalance(), 1) | ||||
assert_equal(w3.getbalance(), 2) | assert_equal(w3.getbalance(), 2) | ||||
assert_equal(w4.getbalance(), 3) | assert_equal(w4.getbalance(), 3) | ||||
batch = w1.batch([w1.getblockchaininfo.get_request(), | batch = w1.batch([w1.getblockchaininfo.get_request(), | ||||
w1.getwalletinfo.get_request()]) | w1.getwalletinfo.get_request()]) | ||||
assert_equal(batch[0]["result"]["chain"], "regtest") | assert_equal(batch[0]["result"]["chain"], "regtest") | ||||
assert_equal(batch[1]["result"]["walletname"], "w1") | assert_equal(batch[1]["result"]["walletname"], "w1") | ||||
▲ Show 20 Lines • Show All 162 Lines • Show Last 20 Lines |