Skip to content
Permalink
Browse files

Refactor to GetWalletDir

  • Loading branch information...
PierreRochard committed Sep 6, 2018
1 parent 2c25e69 commit 5a28a99d2887be85d02cb9a9a062f6bde96f56a2
@@ -101,7 +101,7 @@ BITCOIN_TESTS += \
wallet/test/wallet_tests.cpp \
wallet/test/wallet_crypto_tests.cpp \
wallet/test/coinselector_tests.cpp \
wallet/test/db_tests.cpp
wallet/test/walletutil_tests.cpp

BITCOIN_TEST_SUITE += \
wallet/test/wallet_test_fixture.cpp \
@@ -71,13 +71,8 @@ BerkeleyEnvironment* GetWalletEnv(const fs::path& wallet_path, std::string& data
env_directory = wallet_path;
database_filename = "wallet.dat";
}
// Ensure that the directory does not end with a trailing separator to avoid
// creating two Berkeley environments in the same directory
while ((env_directory.string().back() == '/') || (env_directory.string().back() == '\\'))
env_directory = env_directory.remove_trailing_separator();

LOCK(cs_db);
// Note: An unused temporary BerkeleyEnvironment object may be created inside the
// Note: An ununsed temporary BerkeleyEnvironment object may be created inside the
// emplace function if the key already exists. This is a little inefficient,
// but not a big concern since the map will be changed in the future to hold
// pointers instead of objects, anyway.

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,28 @@
// Copyright (c) 2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <boost/test/unit_test.hpp>

#include <test/test_bitcoin.h>
#include <wallet/walletutil.h>


BOOST_FIXTURE_TEST_SUITE(walletutil_tests, TestingSetup)

/** If a user passes in a path with a trailing separator as the walletdir, multiple BerkeleyEnvironments
* may be created in the same directory which can lead to data corruption.
*/
BOOST_AUTO_TEST_CASE(get_wallet_dir_trailing_separators)
{
fs::path expected_wallet_dir = SetDataDir("get_wallet_dir");
std::string trailing_separators;
for (int i = 0; i < 4; ++i) {
trailing_separators += fs::path::preferred_separator;
gArgs.ForceSetArg("-walletdir", (expected_wallet_dir / trailing_separators).string());
fs::path wallet_dir = GetWalletDir();
BOOST_CHECK(wallet_dir == expected_wallet_dir);
}
}

BOOST_AUTO_TEST_SUITE_END()
@@ -23,5 +23,11 @@ fs::path GetWalletDir()
}
}

// Ensure that the directory does not end with a trailing separator to avoid
// creating two Berkeley environments in the same directory
while (fs::detail::is_directory_separator(path.string().back())) {
path.remove_trailing_separator();
}

return path;
}

0 comments on commit 5a28a99

Please sign in to comment.
You can’t perform that action at this time.