Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_multiwallet.py
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
def data_dir(*p): return os.path.join(node.datadir, self.chain, *p) | def data_dir(*p): return os.path.join(node.datadir, self.chain, *p) | ||||
def wallet_dir(*p): return data_dir('wallets', *p) | def wallet_dir(*p): return data_dir('wallets', *p) | ||||
def wallet(name): return node.get_wallet_rpc(name) | def wallet(name): return node.get_wallet_rpc(name) | ||||
def wallet_file(name): | def wallet_file(name): | ||||
if os.path.isdir(wallet_dir(name)): | if os.path.isdir(wallet_dir(name)): | ||||
return wallet_dir(name, "wallet.dat") | return wallet_dir(name, self.wallet_data_filename) | ||||
return wallet_dir(name) | return wallet_dir(name) | ||||
assert_equal(self.nodes[0].listwalletdir(), | assert_equal(self.nodes[0].listwalletdir(), | ||||
{'wallets': [{'name': ''}]}) | {'wallets': [{'name': self.default_wallet_name}]}) | ||||
# check wallet.dat is created | # check wallet.dat is created | ||||
self.stop_nodes() | self.stop_nodes() | ||||
assert_equal(os.path.isfile(wallet_dir('wallet.dat')), True) | assert_equal(os.path.isfile(wallet_dir(self.default_wallet_name, | ||||
self.wallet_data_filename)), | |||||
True) | |||||
# create symlink to verify wallet directory path can be referenced | # create symlink to verify wallet directory path can be referenced | ||||
# through symlink | # through symlink | ||||
if os.name != 'nt': | if os.name != 'nt': | ||||
os.mkdir(wallet_dir('w7')) | os.mkdir(wallet_dir('w7')) | ||||
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("wallet.dat"), wallet_dir("w8")) | os.rename(wallet_dir(self.default_wallet_name, self.wallet_data_filename), | ||||
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.start_node(0, ["-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("wallet.dat"), empty_wallet) | os.rename(wallet_dir(self.default_wallet_name, self.wallet_data_filename), | ||||
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'), 'w7_symlink', 'w8', ''] | os.path.join(self.options.tmpdir, 'extern/w6'), | ||||
'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 = ['-wallet={}'.format(n) for n in wallet_names] | ||||
self.start_node(0, extra_args) | self.start_node(0, extra_args) | ||||
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), [ | assert_equal( | ||||
'', os.path.join('sub', 'w5'), 'w', 'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8']) | sorted(map(lambda w: w['name'], | ||||
self.nodes[0].listwalletdir()['wallets'])), | |||||
[self.default_wallet_name, os.path.join('sub', 'w5'), 'w', 'w1', | |||||
'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) | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.restart_node( | self.restart_node( | ||||
0, ['-walletdir=' + competing_wallet_dir, '-wallet=']) | 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'], self.nodes[0].listwalletdir()['wallets'])), [ | assert_equal(sorted(map(lambda w: w['name'], | ||||
'', os.path.join('sub', 'w5'), 'w', 'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8', 'w8_copy']) | self.nodes[0].listwalletdir()['wallets'])), | ||||
[self.default_wallet_name, 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 | ||||
node.generatetoaddress(nblocks=1, address=wallets[0].getnewaddress()) | 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() | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Fail to load duplicate wallets | # Fail to load duplicate wallets | ||||
path = os.path.join( | path = os.path.join( | ||||
self.options.tmpdir, | self.options.tmpdir, | ||||
"node0", | "node0", | ||||
"regtest", | "regtest", | ||||
"wallets", | "wallets", | ||||
"w1", | "w1", | ||||
"wallet.dat") | self.wallet_data_filename) | ||||
assert_raises_rpc_error( | assert_raises_rpc_error( | ||||
-4, | -4, | ||||
"Wallet file verification failed. Refusing to load database. Data file '{}' is already loaded.".format( | "Wallet file verification failed. Refusing to load database. Data file '{}' is already loaded.".format( | ||||
path), | path), | ||||
self.nodes[0].loadwallet, | self.nodes[0].loadwallet, | ||||
wallet_names[0]) | wallet_names[0]) | ||||
# Fail to load duplicate wallets by different ways (directory and | # Fail to load duplicate wallets by different ways (directory and | ||||
# filepath) | # filepath) | ||||
path = os.path.join( | path = os.path.join( | ||||
self.options.tmpdir, | self.options.tmpdir, | ||||
"node0", | "node0", | ||||
"regtest", | "regtest", | ||||
"wallets", | "wallets", | ||||
"wallet.dat") | self.wallet_data_filename) | ||||
assert_raises_rpc_error( | assert_raises_rpc_error( | ||||
-4, | -4, | ||||
"Wallet file verification failed. Refusing to load database. Data file '{}' is already loaded.".format( | "Wallet file verification failed. Refusing to load database. Data file '{}' is already loaded.".format( | ||||
path), | path), | ||||
self.nodes[0].loadwallet, | self.nodes[0].loadwallet, | ||||
'wallet.dat') | self.wallet_data_filename) | ||||
# Fail to load if one wallet is a copy of another | # Fail to load if one wallet is a copy of another | ||||
assert_raises_rpc_error(-4, "BerkeleyDatabase: Can't open database w8_copy (duplicates fileid", | assert_raises_rpc_error(-4, "BerkeleyDatabase: Can't open database w8_copy (duplicates fileid", | ||||
self.nodes[0].loadwallet, 'w8_copy') | self.nodes[0].loadwallet, 'w8_copy') | ||||
# Fail to load if one wallet is a copy of another. | # Fail to load if one wallet is a copy of another. | ||||
# Test this twice to make sure that we don't re-introduce | # Test this twice to make sure that we don't re-introduce | ||||
# https://github.com/bitcoin/bitcoin/issues/14304 | # https://github.com/bitcoin/bitcoin/issues/14304 | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
assert_raises_rpc_error(-32601, "Method not found (wallet method is disabled because no wallet is loaded)", | assert_raises_rpc_error(-32601, "Method not found (wallet method is disabled because no wallet is loaded)", | ||||
self.nodes[0].getwalletinfo) | self.nodes[0].getwalletinfo) | ||||
# Successfully load a previously unloaded wallet | # Successfully load a previously unloaded wallet | ||||
self.nodes[0].loadwallet('w1') | self.nodes[0].loadwallet('w1') | ||||
assert_equal(self.nodes[0].listwallets(), ['w1']) | assert_equal(self.nodes[0].listwallets(), ['w1']) | ||||
assert_equal(w1.getwalletinfo()['walletname'], 'w1') | assert_equal(w1.getwalletinfo()['walletname'], 'w1') | ||||
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), [ | assert_equal(sorted(map(lambda w: w['name'], | ||||
'', os.path.join('sub', 'w5'), 'w', 'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8', 'w8_copy', 'w9']) | self.nodes[0].listwalletdir()['wallets'])), | ||||
[self.default_wallet_name, os.path.join('sub', 'w5'), 'w', | |||||
'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8', 'w8_copy', | |||||
'w9']) | |||||
# Test backing up and restoring wallets | # Test backing up and restoring wallets | ||||
self.log.info("Test wallet backup") | self.log.info("Test wallet backup") | ||||
self.restart_node(0, ['-nowallet']) | self.restart_node(0, ['-nowallet']) | ||||
for wallet_name in wallet_names: | for wallet_name in wallet_names: | ||||
self.nodes[0].loadwallet(wallet_name) | self.nodes[0].loadwallet(wallet_name) | ||||
for wallet_name in wallet_names: | for wallet_name in wallet_names: | ||||
rpc = self.nodes[0].get_wallet_rpc(wallet_name) | rpc = self.nodes[0].get_wallet_rpc(wallet_name) | ||||
Show All 24 Lines |