diff options
author | Pierre Rochard <pierre@rochard.org> | 2018-09-14 21:10:20 -0400 |
---|---|---|
committer | João Barbosa <joao.paulo.barbosa@gmail.com> | 2019-03-12 23:25:49 +0000 |
commit | f20513bd71d0530ad9285b9558e3a02733250a63 (patch) | |
tree | 6296496ce57495f43d45344782ce9cb01be8267a /src/wallet | |
parent | 85c6263ddbde7189bbb52317dd3ad9202b5ebf40 (diff) |
Tests: add unit tests for GetWalletEnv
Github-Pull: #11911
Rebased-From: 88b1d95
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/test/db_tests.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/wallet/test/db_tests.cpp b/src/wallet/test/db_tests.cpp new file mode 100644 index 0000000000..2a64749379 --- /dev/null +++ b/src/wallet/test/db_tests.cpp @@ -0,0 +1,72 @@ +// 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 <memory> + +#include <boost/test/unit_test.hpp> + +#include <fs.h> +#include <test/test_bitcoin.h> +#include <wallet/db.h> + + +BOOST_FIXTURE_TEST_SUITE(db_tests, BasicTestingSetup) + +BOOST_AUTO_TEST_CASE(getwalletenv_file) +{ + std::string test_name = "test_name.dat"; + fs::path datadir = SetDataDir("tempdir"); + fs::path file_path = datadir / test_name; + std::ofstream f(file_path.BOOST_FILESYSTEM_C_STR); + f.close(); + + std::string filename; + std::shared_ptr<BerkeleyEnvironment> env = GetWalletEnv(file_path, filename); + BOOST_CHECK(filename == test_name); + BOOST_CHECK(env->Directory() == datadir); +} + +BOOST_AUTO_TEST_CASE(getwalletenv_directory) +{ + std::string expected_name = "wallet.dat"; + fs::path datadir = SetDataDir("tempdir"); + + std::string filename; + std::shared_ptr<BerkeleyEnvironment> env = GetWalletEnv(datadir, filename); + BOOST_CHECK(filename == expected_name); + BOOST_CHECK(env->Directory() == datadir); +} + +BOOST_AUTO_TEST_CASE(getwalletenv_g_dbenvs_multiple) +{ + fs::path datadir = SetDataDir("tempdir"); + fs::path datadir_2 = SetDataDir("tempdir_2"); + std::string filename; + + std::shared_ptr<BerkeleyEnvironment> env_1 = GetWalletEnv(datadir, filename); + std::shared_ptr<BerkeleyEnvironment> env_2 = GetWalletEnv(datadir, filename); + std::shared_ptr<BerkeleyEnvironment> env_3 = GetWalletEnv(datadir_2, filename); + + BOOST_CHECK(env_1 == env_2); + BOOST_CHECK(env_2 != env_3); +} + +BOOST_AUTO_TEST_CASE(getwalletenv_g_dbenvs_free_instance) +{ + fs::path datadir = SetDataDir("tempdir"); + fs::path datadir_2 = SetDataDir("tempdir_2"); + std::string filename; + + std::shared_ptr <BerkeleyEnvironment> env_1_a = GetWalletEnv(datadir, filename); + std::shared_ptr <BerkeleyEnvironment> env_2_a = GetWalletEnv(datadir_2, filename); + env_1_a.reset(); + + std::shared_ptr<BerkeleyEnvironment> env_1_b = GetWalletEnv(datadir, filename); + std::shared_ptr<BerkeleyEnvironment> env_2_b = GetWalletEnv(datadir_2, filename); + + BOOST_CHECK(env_1_a != env_1_b); + BOOST_CHECK(env_2_a == env_2_b); +} + +BOOST_AUTO_TEST_SUITE_END() |