Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_multiwallet.py
Show All 37 Lines | for _ in range(10): | ||||
got_loading_error = True | got_loading_error = True | ||||
return | return | ||||
class MultiWalletTest(BitcoinTestFramework): | class MultiWalletTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
self.extra_args = [["-wallet="], ["-wallet="]] | |||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
self.skip_if_no_wallet() | self.skip_if_no_wallet() | ||||
def add_options(self, parser): | def add_options(self, parser): | ||||
parser.add_argument( | parser.add_argument( | ||||
'--data_wallets_dir', | '--data_wallets_dir', | ||||
default=os.path.join( | default=os.path.join( | ||||
Show All 33 Lines | def run_test(self): | ||||
os.symlink('w7', wallet_dir('w7_symlink')) | os.symlink('w7', wallet_dir('w7_symlink')) | ||||
# rename wallet.dat to make sure plain wallet file paths (as opposed to | # rename wallet.dat to make sure plain wallet file paths (as opposed to | ||||
# directory paths) can be loaded | # directory paths) can be loaded | ||||
os.rename(wallet_dir(self.default_wallet_name, self.wallet_data_filename), | os.rename(wallet_dir(self.default_wallet_name, self.wallet_data_filename), | ||||
wallet_dir("w8")) | wallet_dir("w8")) | ||||
# create another dummy wallet for use in testing backups later | # create another dummy wallet for use in testing backups later | ||||
self.start_node(0, ["-wallet=" + self.default_wallet_name]) | self.start_node( | ||||
0, ["-nowallet", "-wallet=" + self.default_wallet_name]) | |||||
self.stop_nodes() | self.stop_nodes() | ||||
empty_wallet = os.path.join(self.options.tmpdir, 'empty.dat') | empty_wallet = os.path.join(self.options.tmpdir, 'empty.dat') | ||||
os.rename(wallet_dir(self.default_wallet_name, self.wallet_data_filename), | os.rename(wallet_dir(self.default_wallet_name, self.wallet_data_filename), | ||||
empty_wallet) | empty_wallet) | ||||
# restart node with a mix of wallet names: | # restart node with a mix of wallet names: | ||||
# w1, w2, w3 - to verify new wallets created when non-existing paths specified | # w1, w2, w3 - to verify new wallets created when non-existing paths specified | ||||
# w - to verify wallet name matching works when one wallet path is prefix of another | # w - to verify wallet name matching works when one wallet path is prefix of another | ||||
# sub/w5 - to verify relative wallet path is created correctly | # sub/w5 - to verify relative wallet path is created correctly | ||||
# extern/w6 - to verify absolute wallet path is created correctly | # extern/w6 - to verify absolute wallet path is created correctly | ||||
# w7_symlink - to verify symlinked wallet path is initialized correctly | # w7_symlink - to verify symlinked wallet path is initialized correctly | ||||
# w8 - to verify existing wallet file is loaded correctly | # w8 - to verify existing wallet file is loaded correctly | ||||
# '' - to verify default wallet file is created correctly | # '' - to verify default wallet file is created correctly | ||||
wallet_names = ['w1', 'w2', 'w3', 'w', 'sub/w5', | wallet_names = ['w1', 'w2', 'w3', 'w', 'sub/w5', | ||||
os.path.join(self.options.tmpdir, 'extern/w6'), | os.path.join(self.options.tmpdir, 'extern/w6'), | ||||
'w7_symlink', 'w8', self.default_wallet_name] | 'w7_symlink', 'w8', self.default_wallet_name] | ||||
if os.name == 'nt': | if os.name == 'nt': | ||||
wallet_names.remove('w7_symlink') | wallet_names.remove('w7_symlink') | ||||
extra_args = ['-wallet={}'.format(n) for n in wallet_names] | extra_args = ['-nowallet'] + \ | ||||
['-wallet={}'.format(n) for n in wallet_names] | |||||
self.start_node(0, extra_args) | self.start_node(0, extra_args) | ||||
assert_equal( | assert_equal( | ||||
sorted(map(lambda w: w['name'], | sorted(map(lambda w: w['name'], | ||||
self.nodes[0].listwalletdir()['wallets'])), | self.nodes[0].listwalletdir()['wallets'])), | ||||
[self.default_wallet_name, os.path.join('sub', 'w5'), 'w', 'w1', | [self.default_wallet_name, os.path.join('sub', 'w5'), 'w', 'w1', | ||||
'w2', 'w3', 'w7', 'w7_symlink', 'w8']) | 'w2', 'w3', 'w7', 'w7_symlink', 'w8']) | ||||
assert_equal(set(node.listwallets()), set(wallet_names)) | assert_equal(set(node.listwallets()), set(wallet_names)) | ||||
# check that all requested wallets were created | # check that all requested wallets were created | ||||
self.stop_node(0) | self.stop_node(0) | ||||
for wallet_name in wallet_names: | for wallet_name in wallet_names: | ||||
assert_equal(os.path.isfile(wallet_file(wallet_name)), True) | assert_equal(os.path.isfile(wallet_file(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:" | exp_stderr = "boost::filesystem::create_directory:" | ||||
self.nodes[0].assert_start_raises_init_error( | self.nodes[0].assert_start_raises_init_error( | ||||
['-wallet=wallet.dat/bad'], exp_stderr, match=ErrorMatch.PARTIAL_REGEX) | ['-wallet=w8/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()) | ||||
Show All 20 Lines | def run_test(self): | ||||
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 "' + 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, ['-nowallet', '-wallet=w4', '-wallet=w5']) | ||||
assert_equal(set(node.listwallets()), {"w4", "w5"}) | assert_equal(set(node.listwallets()), {"w4", "w5"}) | ||||
w5 = wallet("w5") | w5 = wallet("w5") | ||||
node.generatetoaddress(nblocks=1, address=w5.getnewaddress()) | 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, ['-nowallet', '-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'], 50000000) | assert_equal(w5_info['immature_balance'], 50000000) | ||||
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( | self.restart_node(0, ['-walletdir=' + competing_wallet_dir]) | ||||
0, ['-walletdir=' + competing_wallet_dir, '-wallet=']) | |||||
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, match=ErrorMatch.PARTIAL_REGEX) | ['-walletdir=' + competing_wallet_dir], exp_stderr, match=ErrorMatch.PARTIAL_REGEX) | ||||
self.restart_node(0, extra_args) | self.restart_node(0, extra_args) | ||||
assert_equal(sorted(map(lambda w: w['name'], | assert_equal(sorted(map(lambda w: w['name'], | ||||
self.nodes[0].listwalletdir()['wallets'])), | self.nodes[0].listwalletdir()['wallets'])), | ||||
▲ Show 20 Lines • Show All 261 Lines • Show Last 20 Lines |