Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
db_tests.cpp
Go to the documentation of this file.
1// Copyright (c) 2018 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <wallet/bdb.h>
6
7#include <util/fs.h>
8
9#include <test/util/setup_common.h>
10
11#include <boost/test/unit_test.hpp>
12
13#include <fstream>
14#include <memory>
15#include <string>
16
17BOOST_FIXTURE_TEST_SUITE(db_tests, BasicTestingSetup)
18
20 std::string test_name = "test_name.dat";
21 const fs::path datadir = gArgs.GetDataDirNet();
22 fs::path file_path = datadir / test_name;
23 std::ofstream f{file_path};
24 f.close();
25
26 std::string filename;
27 std::shared_ptr<BerkeleyEnvironment> env =
28 GetWalletEnv(file_path, filename);
29 BOOST_CHECK(filename == test_name);
30 BOOST_CHECK(env->Directory() == datadir);
31}
32
34 std::string expected_name = "wallet.dat";
35 const fs::path datadir = gArgs.GetDataDirNet();
36
37 std::string filename;
38 std::shared_ptr<BerkeleyEnvironment> env = GetWalletEnv(datadir, filename);
39 BOOST_CHECK(filename == expected_name);
40 BOOST_CHECK(env->Directory() == datadir);
41}
42
44 fs::path datadir = gArgs.GetDataDirNet() / "1";
46 std::string filename;
47
48 std::shared_ptr<BerkeleyEnvironment> env_1 =
49 GetWalletEnv(datadir, filename);
50 std::shared_ptr<BerkeleyEnvironment> env_2 =
51 GetWalletEnv(datadir, filename);
52 std::shared_ptr<BerkeleyEnvironment> env_3 =
53 GetWalletEnv(datadir_2, filename);
54
57}
58
60 fs::path datadir = gArgs.GetDataDirNet() / "1";
62 std::string filename;
63
64 std::shared_ptr<BerkeleyEnvironment> env_1_a =
65 GetWalletEnv(datadir, filename);
66 std::shared_ptr<BerkeleyEnvironment> env_2_a =
67 GetWalletEnv(datadir_2, filename);
68 env_1_a.reset();
69
70 std::shared_ptr<BerkeleyEnvironment> env_1_b =
71 GetWalletEnv(datadir, filename);
72 std::shared_ptr<BerkeleyEnvironment> env_2_b =
73 GetWalletEnv(datadir_2, filename);
74
77}
78
ArgsManager gArgs
Definition args.cpp:38
std::shared_ptr< BerkeleyEnvironment > GetWalletEnv(const fs::path &wallet_path, std::string &database_filename)
Get BerkeleyEnvironment and database filename given a wallet path.
Definition bdb.cpp:83
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
Definition args.h:215
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition fs.h:30
#define BOOST_CHECK(expr)
Definition object.cpp:17
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
BOOST_AUTO_TEST_CASE(getwalletenv_file)
Definition db_tests.cpp:19