Bitcoin Core  22.99.0
P2P Digital Currency
init_test_fixture.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018-2021 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 namespace wallet {
14 {
16 
17  std::string sep;
18  sep += fs::path::preferred_separator;
19 
21  m_cwd = fs::current_path();
22 
23  m_walletdir_path_cases["default"] = m_datadir / "wallets";
24  m_walletdir_path_cases["custom"] = m_datadir / "my_wallets";
25  m_walletdir_path_cases["nonexistent"] = m_datadir / "path_does_not_exist";
26  m_walletdir_path_cases["file"] = m_datadir / "not_a_directory.dat";
27  m_walletdir_path_cases["trailing"] = m_datadir / "wallets" / sep;
28  m_walletdir_path_cases["trailing2"] = m_datadir / "wallets" / sep / sep;
29 
30  fs::current_path(m_datadir);
31  m_walletdir_path_cases["relative"] = "wallets";
32 
33  fs::create_directories(m_walletdir_path_cases["default"]);
34  fs::create_directories(m_walletdir_path_cases["custom"]);
35  fs::create_directories(m_walletdir_path_cases["relative"]);
37  f.close();
38 }
39 
41 {
42  gArgs.LockSettings([&](util::Settings& settings) {
43  settings.forced_settings.erase("walletdir");
44  });
45  fs::current_path(m_cwd);
46 }
47 
49 {
50  gArgs.ForceSetArg("-walletdir", fs::PathToString(walletdir_path));
51 }
52 } // namespace wallet
BasicTestingSetup::m_node
node::NodeContext m_node
Definition: setup_common.h:85
check.h
util::Settings
Stored settings.
Definition: settings.h:31
fs.h
ArgsManager::GetDataDirNet
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
Definition: system.h:288
util::Settings::forced_settings
std::map< std::string, SettingsValue > forced_settings
Map of setting name to forced setting value.
Definition: settings.h:33
wallet
Definition: node.h:38
fs::PathToString
static std::string PathToString(const path &path)
Convert path object to byte string.
Definition: fs.h:120
wallet::InitWalletDirTestingSetup::m_walletdir_path_cases
std::map< std::string, fs::path > m_walletdir_path_cases
Definition: init_test_fixture.h:22
Assert
#define Assert(val)
Identity function.
Definition: check.h:57
wallet::InitWalletDirTestingSetup::m_cwd
fs::path m_cwd
Definition: init_test_fixture.h:21
fsbridge::ofstream
fs::ofstream ofstream
Definition: fs.h:235
wallet::InitWalletDirTestingSetup::~InitWalletDirTestingSetup
~InitWalletDirTestingSetup()
Definition: init_test_fixture.cpp:40
fs::path
Path class wrapper to prepare application code for transition from boost::filesystem library to std::...
Definition: fs.h:33
univalue.h
ArgsManager::ForceSetArg
void ForceSetArg(const std::string &strArg, const std::string &strValue)
Definition: system.cpp:619
BasicTestingSetup
Basic testing setup.
Definition: setup_common.h:83
gArgs
ArgsManager gArgs
Definition: system.cpp:80
wallet::InitWalletDirTestingSetup::m_wallet_loader
std::unique_ptr< interfaces::WalletLoader > m_wallet_loader
Definition: init_test_fixture.h:23
node::NodeContext::args
ArgsManager * args
Definition: context.h:50
system.h
ArgsManager::LockSettings
void LockSettings(Fn &&fn)
Access settings with lock held.
Definition: system.h:437
interfaces::MakeWalletLoader
std::unique_ptr< WalletLoader > MakeWalletLoader(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet loader.
Definition: dummywallet.cpp:61
wallet::InitWalletDirTestingSetup::m_datadir
fs::path m_datadir
Definition: init_test_fixture.h:20
wallet::InitWalletDirTestingSetup::InitWalletDirTestingSetup
InitWalletDirTestingSetup(const std::string &chainName=CBaseChainParams::MAIN)
Definition: init_test_fixture.cpp:13
node::NodeContext::chain
std::unique_ptr< interfaces::Chain > chain
Definition: context.h:51
wallet::InitWalletDirTestingSetup::SetWalletDir
void SetWalletDir(const fs::path &walletdir_path)
Definition: init_test_fixture.cpp:48
init_test_fixture.h