Bitcoin Core 31.99.0
P2P Digital Currency
util.h
Go to the documentation of this file.
1// Copyright (c) 2021-present 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#ifndef BITCOIN_WALLET_TEST_UTIL_H
6#define BITCOIN_WALLET_TEST_UTIL_H
7
8#include <addresstype.h>
9#include <wallet/db.h>
11#include <wallet/sqlite.h>
12
13#include <memory>
14
15class ArgsManager;
16class CChain;
17class CKey;
18enum class OutputType;
19namespace interfaces {
20class Chain;
21} // namespace interfaces
22
23namespace wallet {
24class CWallet;
25class WalletDatabase;
26struct WalletContext;
27
30};
31
32const std::string ADDRESS_BCRT1_UNSPENDABLE = "bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3xueyj";
33
34std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, const CKey& key);
35
36std::shared_ptr<CWallet> TestCreateWallet(WalletContext& context);
37std::shared_ptr<CWallet> TestCreateWallet(std::unique_ptr<WalletDatabase> database, WalletContext& context, uint64_t create_flags);
38std::shared_ptr<CWallet> TestLoadWallet(WalletContext& context);
39std::shared_ptr<CWallet> TestLoadWallet(std::unique_ptr<WalletDatabase> database, WalletContext& context);
40void TestUnloadWallet(std::shared_ptr<CWallet>&& wallet);
41
42// Creates a copy of the provided database
43std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database);
44
46std::string getnewaddress(CWallet& w);
49
50using MockableData = std::map<SerializeData, SerializeData, std::less<>>;
51
52
54{
55public:
58};
59
63{
64public:
66
67 bool Backup(const std::string& strDest) const override { return true; }
68
69 std::string Filename() override { return "mockable"; }
70 std::vector<fs::path> Files() override { return {}; }
71 std::string Format() override { return "sqlite-mock"; }
72 std::unique_ptr<DatabaseBatch> MakeBatch() override { return std::make_unique<MockableSQLiteBatch>(*this); }
73};
74
75std::unique_ptr<WalletDatabase> CreateMockableWalletDatabase();
77
78DescriptorScriptPubKeyMan* CreateDescriptor(CWallet& keystore, const std::string& desc_str, bool success);
79} // namespace wallet
80
81#endif // BITCOIN_WALLET_TEST_UTIL_H
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
Definition: addresstype.h:143
An in-memory indexed chain of blocks.
Definition: chain.h:380
An encapsulated private key.
Definition: key.h:36
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Definition: chain.h:118
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:309
A WalletDatabase whose contents and return values can be modified as needed for testing.
Definition: util.h:63
std::string Filename() override
Return path to main database file for logs and error messages.
Definition: util.h:69
std::vector< fs::path > Files() override
Return paths to all database created files.
Definition: util.h:70
bool Backup(const std::string &strDest) const override
Back up the entire database to a file.
Definition: util.h:67
std::unique_ptr< DatabaseBatch > MakeBatch() override
Make a SQLiteBatch connected to this database.
Definition: util.h:72
std::string Format() override
Definition: util.h:71
RAII class that provides access to a WalletDatabase.
Definition: sqlite.h:52
SQLiteBatch(SQLiteDatabase &database)
Definition: sqlite.cpp:402
bool WriteKey(DataStream &&key, DataStream &&value, bool overwrite=true) override
Definition: sqlite.cpp:486
An instance of this class represents one SQLite3 database.
Definition: sqlite.h:104
An instance of this class represents one database.
Definition: db.h:130
wallet::DescriptorScriptPubKeyMan * CreateDescriptor(CWallet &keystore, const std::string &desc_str, const bool success)
Definition: util.cpp:149
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase()
Definition: util.cpp:144
const std::string ADDRESS_BCRT1_UNSPENDABLE
Definition: util.h:32
DatabaseFormat
Definition: db.h:167
static const DatabaseFormat DATABASE_FORMATS[]
Definition: util.h:28
MockableSQLiteDatabase & GetMockableDatabase(CWallet &wallet)
std::unique_ptr< CWallet > CreateSyncedWallet(interfaces::Chain &chain, CChain &cchain, const CKey &key)
Definition: util.cpp:22
void TestUnloadWallet(std::shared_ptr< CWallet > &&wallet)
Definition: util.cpp:100
std::unique_ptr< WalletDatabase > DuplicateMockDatabase(WalletDatabase &database)
Definition: util.cpp:108
std::shared_ptr< CWallet > TestLoadWallet(std::unique_ptr< WalletDatabase > database, WalletContext &context)
Definition: util.cpp:77
std::shared_ptr< CWallet > TestCreateWallet(std::unique_ptr< WalletDatabase > database, WalletContext &context, uint64_t create_flags)
Definition: util.cpp:52
std::map< SerializeData, SerializeData, std::less<> > MockableData
Definition: util.h:50
RPCMethod getnewaddress()
Definition: addresses.cpp:21
CTxDestination getNewDestination(CWallet &w, OutputType output_type)
Returns a new destination, of an specific type, from the wallet.
Definition: util.cpp:135
OutputType
Definition: outputtype.h:18
WalletContext struct containing references to state shared between CWallet instances,...
Definition: context.h:36