Bitcoin Core
24.99.0
P2P Digital Currency
src
wallet
test
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 <
fs.h
>
6
#include <
univalue.h
>
7
#include <
util/check.h
>
8
#include <
util/system.h
>
9
10
#include <fstream>
11
#include <string>
12
13
#include <
wallet/test/init_test_fixture.h
>
14
15
namespace
wallet
{
16
InitWalletDirTestingSetup::InitWalletDirTestingSetup
(
const
std::string& chainName) :
BasicTestingSetup
(chainName)
17
{
18
m_wallet_loader
=
MakeWalletLoader
(*
m_node
.
chain
,
m_args
);
19
20
const
auto
sep = fs::path::preferred_separator;
21
22
m_datadir
=
m_args
.
GetDataDirNet
();
23
m_cwd
= fs::current_path();
24
25
m_walletdir_path_cases
[
"default"
] =
m_datadir
/
"wallets"
;
26
m_walletdir_path_cases
[
"custom"
] =
m_datadir
/
"my_wallets"
;
27
m_walletdir_path_cases
[
"nonexistent"
] =
m_datadir
/
"path_does_not_exist"
;
28
m_walletdir_path_cases
[
"file"
] =
m_datadir
/
"not_a_directory.dat"
;
29
m_walletdir_path_cases
[
"trailing"
] = (
m_datadir
/
"wallets"
) + sep;
30
m_walletdir_path_cases
[
"trailing2"
] = (
m_datadir
/
"wallets"
) + sep + sep;
31
32
fs::current_path(
m_datadir
);
33
m_walletdir_path_cases
[
"relative"
] =
"wallets"
;
34
35
fs::create_directories
(
m_walletdir_path_cases
[
"default"
]);
36
fs::create_directories
(
m_walletdir_path_cases
[
"custom"
]);
37
fs::create_directories
(
m_walletdir_path_cases
[
"relative"
]);
38
std::ofstream f{
m_walletdir_path_cases
[
"file"
]};
39
f.close();
40
}
41
42
InitWalletDirTestingSetup::~InitWalletDirTestingSetup
()
43
{
44
fs::current_path(
m_cwd
);
45
}
46
47
void
InitWalletDirTestingSetup::SetWalletDir
(
const
fs::path
& walletdir_path)
48
{
49
m_args
.
ForceSetArg
(
"-walletdir"
,
fs::PathToString
(walletdir_path));
50
}
51
}
// namespace wallet
check.h
ArgsManager::ForceSetArg
void ForceSetArg(const std::string &strArg, const std::string &strValue)
Definition:
system.cpp:654
ArgsManager::GetDataDirNet
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
Definition:
system.h:289
fs::path
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition:
fs.h:31
fs.h
init_test_fixture.h
fs::create_directories
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:188
fs::PathToString
static std::string PathToString(const path &path)
Convert path object to a byte string.
Definition:
fs.h:150
interfaces::MakeWalletLoader
std::unique_ptr< WalletLoader > MakeWalletLoader(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet loader.
Definition:
dummywallet.cpp:62
wallet
Definition:
node.h:39
BasicTestingSetup
Basic testing setup.
Definition:
setup_common.h:79
BasicTestingSetup::m_args
ArgsManager m_args
Definition:
setup_common.h:86
BasicTestingSetup::m_node
node::NodeContext m_node
Definition:
setup_common.h:80
node::NodeContext::chain
std::unique_ptr< interfaces::Chain > chain
Definition:
context.h:57
wallet::InitWalletDirTestingSetup::~InitWalletDirTestingSetup
~InitWalletDirTestingSetup()
Definition:
init_test_fixture.cpp:42
wallet::InitWalletDirTestingSetup::m_walletdir_path_cases
std::map< std::string, fs::path > m_walletdir_path_cases
Definition:
init_test_fixture.h:22
wallet::InitWalletDirTestingSetup::m_wallet_loader
std::unique_ptr< interfaces::WalletLoader > m_wallet_loader
Definition:
init_test_fixture.h:23
wallet::InitWalletDirTestingSetup::m_datadir
fs::path m_datadir
Definition:
init_test_fixture.h:20
wallet::InitWalletDirTestingSetup::m_cwd
fs::path m_cwd
Definition:
init_test_fixture.h:21
wallet::InitWalletDirTestingSetup::InitWalletDirTestingSetup
InitWalletDirTestingSetup(const std::string &chainName=CBaseChainParams::MAIN)
Definition:
init_test_fixture.cpp:16
wallet::InitWalletDirTestingSetup::SetWalletDir
void SetWalletDir(const fs::path &walletdir_path)
Definition:
init_test_fixture.cpp:47
system.h
univalue.h
Generated on Tue Mar 28 2023 02:44:28 for Bitcoin Core by
1.9.1