Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_multiwallet.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2017 The Bitcoin Core developers | # Copyright (c) 2017 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test multiwallet. | """Test multiwallet. | ||||
Verify that a bitcoind node can load multiple wallet files | Verify that a bitcoind node can load multiple wallet files | ||||
""" | """ | ||||
import os | import os | ||||
import re | |||||
import shutil | import shutil | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.test_node import ErrorMatch | |||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
) | ) | ||||
class MultiWalletTest(BitcoinTestFramework): | class MultiWalletTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
assert_equal(os.path.isfile( | assert_equal(os.path.isfile( | ||||
wallet_dir(wallet_name, "wallet.dat")), True) | wallet_dir(wallet_name, "wallet.dat")), True) | ||||
else: | else: | ||||
assert_equal(os.path.isfile(wallet_dir(wallet_name)), True) | assert_equal(os.path.isfile(wallet_dir(wallet_name)), True) | ||||
# should not initialize if wallet path can't be created | # should not initialize if wallet path can't be created | ||||
exp_stderr = "boost::filesystem::create_directory: (The system cannot find the path specified|Not a directory):" | exp_stderr = "boost::filesystem::create_directory: (The system cannot find the path specified|Not a directory):" | ||||
self.nodes[0].assert_start_raises_init_error( | self.nodes[0].assert_start_raises_init_error( | ||||
['-wallet=wallet.dat/bad'], exp_stderr, partial_match=True) | ['-wallet=wallet.dat/bad'], exp_stderr, match=ErrorMatch.PARTIAL_REGEX) | ||||
self.nodes[0].assert_start_raises_init_error( | self.nodes[0].assert_start_raises_init_error( | ||||
['-walletdir=wallets'], 'Error: Specified -walletdir "wallets" does not exist') | ['-walletdir=wallets'], 'Error: Specified -walletdir "wallets" does not exist') | ||||
self.nodes[0].assert_start_raises_init_error( | self.nodes[0].assert_start_raises_init_error( | ||||
['-walletdir=wallets'], 'Error: Specified -walletdir "wallets" is a relative path', cwd=data_dir()) | ['-walletdir=wallets'], 'Error: Specified -walletdir "wallets" is a relative path', cwd=data_dir()) | ||||
self.nodes[0].assert_start_raises_init_error( | self.nodes[0].assert_start_raises_init_error( | ||||
['-walletdir=debug.log'], 'Error: Specified -walletdir "debug.log" is not a directory', cwd=data_dir()) | ['-walletdir=debug.log'], 'Error: Specified -walletdir "debug.log" is not a directory', cwd=data_dir()) | ||||
# should not initialize if there are duplicate wallets | # should not initialize if there are duplicate wallets | ||||
self.nodes[0].assert_start_raises_init_error( | self.nodes[0].assert_start_raises_init_error( | ||||
['-wallet=w1', '-wallet=w1'], 'Error: Error loading wallet w1. Duplicate -wallet filename specified.') | ['-wallet=w1', '-wallet=w1'], 'Error: Error loading wallet w1. Duplicate -wallet filename specified.') | ||||
# should not initialize if one wallet is a copy of another | # should not initialize if one wallet is a copy of another | ||||
shutil.copyfile(wallet_dir('w8'), wallet_dir('w8_copy')) | shutil.copyfile(wallet_dir('w8'), wallet_dir('w8_copy')) | ||||
exp_stderr = r"BerkeleyBatch: Can't open database w8_copy \(duplicates fileid \w+ from w8\)" | exp_stderr = r"BerkeleyBatch: Can't open database w8_copy \(duplicates fileid \w+ from w8\)" | ||||
self.nodes[0].assert_start_raises_init_error( | self.nodes[0].assert_start_raises_init_error( | ||||
['-wallet=w8', '-wallet=w8_copy'], exp_stderr, partial_match=True) | ['-wallet=w8', '-wallet=w8_copy'], exp_stderr, match=ErrorMatch.PARTIAL_REGEX) | ||||
# should not initialize if wallet file is a symlink | # should not initialize if wallet file is a symlink | ||||
os.symlink('w8', wallet_dir('w8_symlink')) | os.symlink('w8', wallet_dir('w8_symlink')) | ||||
self.nodes[0].assert_start_raises_init_error( | self.nodes[0].assert_start_raises_init_error( | ||||
['-wallet=w8_symlink'], r'Error: Invalid -wallet path \'w8_symlink\'\. .*') | ['-wallet=w8_symlink'], r'Error: Invalid -wallet path \'w8_symlink\'\. .*', match=ErrorMatch.FULL_REGEX) | ||||
# should not initialize if the specified walletdir does not exist | # should not initialize if the specified walletdir does not exist | ||||
self.nodes[0].assert_start_raises_init_error( | self.nodes[0].assert_start_raises_init_error( | ||||
['-walletdir=bad'], 'Error: Specified -walletdir "bad" does not exist') | ['-walletdir=bad'], 'Error: Specified -walletdir "bad" does not exist') | ||||
# should not initialize if the specified walletdir is not a directory | # should not initialize if the specified walletdir is not a directory | ||||
not_a_dir = wallet_dir('notadir') | not_a_dir = wallet_dir('notadir') | ||||
open(not_a_dir, 'a', encoding="utf8").close() | open(not_a_dir, 'a', encoding="utf8").close() | ||||
self.nodes[0].assert_start_raises_init_error( | self.nodes[0].assert_start_raises_init_error( | ||||
['-walletdir=' + not_a_dir], 'Error: Specified -walletdir "' + re.escape(not_a_dir) + '" is not a directory') | ['-walletdir=' + not_a_dir], 'Error: Specified -walletdir "' + not_a_dir + '" is not a directory') | ||||
# 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) | w5.generate(1) | ||||
# now if wallets/ exists again, but the rootdir is specified as the walletdir, w4 and w5 should still be loaded | # now if wallets/ exists again, but the rootdir is specified as the 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") | ||||
w5_info = w5.getwalletinfo() | w5_info = w5.getwalletinfo() | ||||
assert_equal(w5_info['immature_balance'], 50) | assert_equal(w5_info['immature_balance'], 50) | ||||
competing_wallet_dir = os.path.join( | competing_wallet_dir = os.path.join( | ||||
self.options.tmpdir, 'competing_walletdir') | self.options.tmpdir, 'competing_walletdir') | ||||
os.mkdir(competing_wallet_dir) | os.mkdir(competing_wallet_dir) | ||||
self.restart_node(0, ['-walletdir=' + competing_wallet_dir]) | self.restart_node(0, ['-walletdir=' + competing_wallet_dir]) | ||||
exp_stderr = r"Error: Error initializing wallet database environment \"\S+competing_walletdir\"!" | exp_stderr = r"Error: Error initializing wallet database environment \"\S+competing_walletdir\"!" | ||||
self.nodes[1].assert_start_raises_init_error( | self.nodes[1].assert_start_raises_init_error( | ||||
['-walletdir=' + competing_wallet_dir], exp_stderr, partial_match=True) | ['-walletdir=' + competing_wallet_dir], exp_stderr, match=ErrorMatch.PARTIAL_REGEX) | ||||
self.restart_node(0, extra_args) | self.restart_node(0, extra_args) | ||||
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) | wallets[0].generate(1) | ||||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |