Skip to content

Commit

Permalink
[wallet] Specify wallet name in wallet loading errors
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Jun 2, 2021
1 parent 900bbfa commit 8bd979f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2126,20 +2126,20 @@ bool CWallet::Verify()

for (const std::string& walletFile : gArgs.GetArgs("-wallet")) {
if (fs::path(walletFile).filename() != walletFile) {
return UIError(strprintf(_("%s parameter must only specify a filename (not a path)"), "-wallet"));
return UIError(strprintf(_("Error loading wallet %s. %s parameter must only specify a filename (not a path)."), walletFile, "-wallet"));
}
if (SanitizeString(walletFile, SAFE_CHARS_FILENAME) != walletFile) {
return UIError(strprintf(_("Invalid characters in %s filename"), "-wallet"));
return UIError(strprintf(_("Error loading wallet %s. Invalid characters in %s filename."), walletFile, "-wallet"));
}

fs::path wallet_path = fs::absolute(walletFile, GetDataDir());

if (fs::exists(wallet_path) && (!fs::is_regular_file(wallet_path) || fs::is_symlink(wallet_path))) {
return UIError(_("Invalid -wallet file"));
return UIError(strprintf(_("Error loading wallet %s. %s filename must be a regular file."), walletFile, "-wallet"));
}

if (!wallet_paths.insert(wallet_path).second) {
return UIError(strprintf(_("Duplicate %s filename"), "-wallet"));
return UIError(strprintf(_("Error loading wallet %s. Duplicate %s filename specified."), walletFile, "-wallet"));
}

std::string strError;
Expand Down
16 changes: 7 additions & 9 deletions test/functional/wallet_multiwallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,23 @@ def run_test(self):
#self.assert_start_raises_init_error(0, ['-walletdir=debug.log'], 'Error: Specified -walletdir "debug.log" is not a directory', cwd=data_dir())

# should not initialize if there are duplicate wallets
self.assert_start_raises_init_error(0, ['-wallet=w1', '-wallet=w1'], 'Duplicate -wallet filename')
self.assert_start_raises_init_error(0, ['-wallet=w1', '-wallet=w1'], 'Error loading wallet w1. Duplicate -wallet filename specified.')

# should not initialize if wallet file is a directory
# !TODO: backport bitcoin#11476 + bitcoin#11970
os.mkdir(os.path.join(self.options.tmpdir, 'node0', 'regtest', 'w11'))
self.assert_start_raises_init_error(0, ['-wallet=w11'], 'Invalid -wallet file')
#os.mkdir(wallet_dir('w11'))
#self.assert_start_raises_init_error(0, ['-wallet=w11'], 'Error loading wallet w11. -wallet filename must be a regular file.')
self.assert_start_raises_init_error(0, ['-wallet=w11'], 'Error loading wallet w11. -wallet filename must be a regular file.')

# should not initialize if one wallet is a copy of another
# shutil.copyfile(wallet_dir('w2'), wallet_dir('w22'))
# self.assert_start_raises_init_error(0, ['-wallet=w2', '-wallet=w22'], 'duplicates fileid')
# !TODO: backport bitcoin#11476 + bitcoin#11970
#should not initialize if one wallet is a copy of another
#shutil.copyfile(wallet_dir('w2'), wallet_dir('w22'))
#self.assert_start_raises_init_error(0, ['-wallet=w2', '-wallet=w22'], 'duplicates fileid')

# should not initialize if wallet file is a symlink
os.symlink(os.path.join(self.options.tmpdir, 'node0', 'regtest', 'w1'),
os.path.join(self.options.tmpdir, 'node0', 'regtest', 'w12'))
self.assert_start_raises_init_error(0, ['-wallet=w12'], 'Invalid -wallet file')
# os.symlink(wallet_dir('w1'), wallet_dir('w12'))
# self.assert_start_raises_init_error(0, ['-wallet=w12'], 'Error loading wallet w12. -wallet filename must be a regular file.')
self.assert_start_raises_init_error(0, ['-wallet=w12'], 'Error loading wallet w12. -wallet filename must be a regular file.')

self.log.info("Do not allow -zapwallettxes with multiwallet")
self.assert_start_raises_init_error(0, ['-zapwallettxes', '-wallet=w1', '-wallet=w2'], "Error: -zapwallettxes is only allowed with a single wallet file")
Expand Down

0 comments on commit 8bd979f

Please sign in to comment.