Bitcoin Core  22.0.0
P2P Digital Currency
init_test_fixture.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018-2020 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 <fs.h>
6 #include <univalue.h>
7 #include <util/check.h>
8 #include <util/system.h>
9 
11 
12 InitWalletDirTestingSetup::InitWalletDirTestingSetup(const std::string& chainName) : BasicTestingSetup(chainName)
13 {
15 
16  std::string sep;
17  sep += fs::path::preferred_separator;
18 
20  m_cwd = fs::current_path();
21 
22  m_walletdir_path_cases["default"] = m_datadir / "wallets";
23  m_walletdir_path_cases["custom"] = m_datadir / "my_wallets";
24  m_walletdir_path_cases["nonexistent"] = m_datadir / "path_does_not_exist";
25  m_walletdir_path_cases["file"] = m_datadir / "not_a_directory.dat";
26  m_walletdir_path_cases["trailing"] = m_datadir / "wallets" / sep;
27  m_walletdir_path_cases["trailing2"] = m_datadir / "wallets" / sep / sep;
28 
29  fs::current_path(m_datadir);
30  m_walletdir_path_cases["relative"] = "wallets";
31 
32  fs::create_directories(m_walletdir_path_cases["default"]);
33  fs::create_directories(m_walletdir_path_cases["custom"]);
34  fs::create_directories(m_walletdir_path_cases["relative"]);
35 #if BOOST_VERSION >= 107700
36  std::ofstream f(BOOST_FILESYSTEM_C_STR(m_walletdir_path_cases["file"]));
37 #else
38  std::ofstream f(m_walletdir_path_cases["file"].BOOST_FILESYSTEM_C_STR);
39 #endif // BOOST_VERSION >= 107700
40  f.close();
41 }
42 
44 {
45  gArgs.LockSettings([&](util::Settings& settings) {
46  settings.forced_settings.erase("walletdir");
47  });
48  fs::current_path(m_cwd);
49 }
50 
51 void InitWalletDirTestingSetup::SetWalletDir(const fs::path& walletdir_path)
52 {
53  gArgs.ForceSetArg("-walletdir", walletdir_path.string());
54 }
Stored settings.
Definition: settings.h:31
InitWalletDirTestingSetup(const std::string &chainName=CBaseChainParams::MAIN)
std::unique_ptr< interfaces::WalletClient > m_wallet_client
std::unique_ptr< interfaces::Chain > chain
Definition: context.h:50
NodeContext & m_node
void ForceSetArg(const std::string &strArg, const std::string &strValue)
Definition: system.cpp:622
fs::ofstream ofstream
Definition: fs.h:102
void SetWalletDir(const fs::path &walletdir_path)
std::map< std::string, fs::path > m_walletdir_path_cases
std::unique_ptr< WalletClient > MakeWalletClient(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet client.
Definition: interfaces.cpp:582
ArgsManager * args
Definition: context.h:49
ArgsManager gArgs
Definition: system.cpp:84
std::map< std::string, SettingsValue > forced_settings
Map of setting name to forced setting value.
Definition: settings.h:33
void LockSettings(Fn &&fn)
Access settings with lock held.
Definition: system.h:431
#define Assert(val)
Identity function.
Definition: check.h:57
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
Definition: system.h:282