Bitcoin Core  27.99.0
P2P Digital Currency
init_test_fixture.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018-2022 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 <common/args.h>
6 #include <univalue.h>
7 #include <util/chaintype.h>
8 #include <util/check.h>
9 #include <util/fs.h>
10 
11 #include <fstream>
12 #include <string>
13 
15 
16 namespace wallet {
18 {
20 
21  const auto sep = fs::path::preferred_separator;
22 
24  m_cwd = fs::current_path();
25 
26  m_walletdir_path_cases["default"] = m_datadir / "wallets";
27  m_walletdir_path_cases["custom"] = m_datadir / "my_wallets";
28  m_walletdir_path_cases["nonexistent"] = m_datadir / "path_does_not_exist";
29  m_walletdir_path_cases["file"] = m_datadir / "not_a_directory.dat";
30  m_walletdir_path_cases["trailing"] = (m_datadir / "wallets") + sep;
31  m_walletdir_path_cases["trailing2"] = (m_datadir / "wallets") + sep + sep;
32 
33  fs::current_path(m_datadir);
34  m_walletdir_path_cases["relative"] = "wallets";
35 
39  std::ofstream f{m_walletdir_path_cases["file"]};
40  f.close();
41 }
42 
44 {
45  fs::current_path(m_cwd);
46 }
47 
49 {
50  m_args.ForceSetArg("-walletdir", fs::PathToString(walletdir_path));
51 }
52 } // namespace wallet
ChainType
Definition: chaintype.h:11
void ForceSetArg(const std::string &strArg, const std::string &strValue)
Definition: args.cpp:544
fs::path GetDataDirNet() const
Get data directory path with appended network identifier.
Definition: args.h:232
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:33
static bool create_directories(const std::filesystem::path &p)
Create directory (and if necessary its parents), unless the leaf directory already exists or is a sym...
Definition: fs.h:190
static std::string PathToString(const path &path)
Convert path object to a byte string.
Definition: fs.h:151
std::unique_ptr< WalletLoader > MakeWalletLoader(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet loader.
Definition: dummywallet.cpp:64
Basic testing setup.
Definition: setup_common.h:54
ArgsManager m_args
Definition: setup_common.h:64
node::NodeContext m_node
Definition: setup_common.h:56
std::unique_ptr< interfaces::Chain > chain
Definition: context.h:72
std::map< std::string, fs::path > m_walletdir_path_cases
std::unique_ptr< interfaces::WalletLoader > m_wallet_loader
InitWalletDirTestingSetup(const ChainType chain_type=ChainType::MAIN)
void SetWalletDir(const fs::path &walletdir_path)