Bitcoin ABC 0.30.5
P2P Digital Currency
init_test_fixture.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
6
7#include <chainparams.h>
8#include <common/system.h>
9#include <univalue.h>
10#include <util/check.h>
11#include <util/fs.h>
12
13#include <fstream>
14#include <string>
15
17 const std::string &chainName)
18 : BasicTestingSetup(chainName) {
20
21 std::string sep;
22 sep += fs::path::preferred_separator;
23
25 m_cwd = fs::current_path();
26
27 m_walletdir_path_cases["default"] = m_datadir / "wallets";
28 m_walletdir_path_cases["custom"] = m_datadir / "my_wallets";
29 m_walletdir_path_cases["nonexistent"] = m_datadir / "path_does_not_exist";
30 m_walletdir_path_cases["file"] = m_datadir / "not_a_directory.dat";
31 m_walletdir_path_cases["trailing"] = m_datadir / ("wallets" + sep);
32 m_walletdir_path_cases["trailing2"] = m_datadir / ("wallets" + sep + sep);
33
34 fs::current_path(m_datadir);
35 m_walletdir_path_cases["relative"] = "wallets";
36
40 std::ofstream f{m_walletdir_path_cases["file"]};
41 f.close();
42}
43
45 gArgs.LockSettings([&](util::Settings &settings) {
46 settings.forced_settings.erase("walletdir");
47 });
48 fs::current_path(m_cwd);
49}
50
52 gArgs.ForceSetArg("-walletdir", fs::PathToString(walletdir_path));
53}
ArgsManager gArgs
Definition: args.cpp:38
#define Assert(val)
Identity function.
Definition: check.h:84
void ForceSetArg(const std::string &strArg, const std::string &strValue)
Definition: args.cpp:597
fs::path GetDataDirNet() const
Get data directory path with appended network identifier.
Definition: args.h:215
void LockSettings(Fn &&fn)
Access settings with lock held.
Definition: args.h:398
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:30
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:179
static std::string PathToString(const path &path)
Convert path object to byte string.
Definition: fs.h:142
std::unique_ptr< WalletClient > MakeWalletClient(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet client.
Definition: interfaces.cpp:581
NodeContext & m_node
Definition: interfaces.cpp:785
std::unique_ptr< interfaces::WalletClient > m_wallet_client
InitWalletDirTestingSetup(const std::string &chainName=CBaseChainParams::MAIN)
std::map< std::string, fs::path > m_walletdir_path_cases
void SetWalletDir(const fs::path &walletdir_path)
Stored settings.
Definition: settings.h:31
std::map< std::string, SettingsValue > forced_settings
Map of setting name to forced setting value.
Definition: settings.h:33