5#ifndef BITCOIN_WALLET_TEST_UTIL_H
6#define BITCOIN_WALLET_TEST_UTIL_H
51using MockableData = std::map<SerializeData, SerializeData, std::less<>>;
68 bool Backup(
const std::string& strDest)
const override {
return true; }
70 std::string
Filename()
override {
return "mockable"; }
71 std::string
Format()
override {
return "sqlite-mock"; }
72 std::unique_ptr<DatabaseBatch>
MakeBatch()
override {
return std::make_unique<MockableSQLiteBatch>(*
this); }
79 void FailNextWrite(std::string record_type,
size_t match_skip_count = 0)
81 m_fail_write = {std::move(record_type), match_skip_count};
89 if (
auto cursor{batch->GetNewPrefixCursor(
DataStream() << record_type)}) {
100 std::unique_ptr<DatabaseBatch>
MakeBatch()
override {
return std::make_unique<Batch>(*
this); }
110 if (!failure)
return false;
111 std::string record_type;
113 if (failure->record_type != record_type)
return false;
114 if (failure->match_skip_count > 0) {
115 --failure->match_skip_count;
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
An in-memory indexed chain of blocks.
An encapsulated private key.
Double ended buffer combining vector and stream-like interfaces.
const_iterator begin() const
const_iterator end() const
Minimal stream for reading from an existing byte array by std::span.
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
A SQLite wallet database that can fail selected operations for testing.
void FailNextWrite(std::string record_type, size_t match_skip_count=0)
std::unique_ptr< DatabaseBatch > MakeBatch() override
Make a SQLiteBatch connected to this database.
std::optional< Failure > m_fail_write
std::optional< Failure > m_fail_erase
bool HasRecordType(const std::string &record_type)
static bool ShouldFail(std::optional< Failure > &failure, const DataStream &key)
std::optional< SerializeData > GetRecordValue(const std::string &record_type)
void FailNextErase(std::string record_type)
An in-memory SQLiteDatabase.
A WalletDatabase whose contents and return values can be modified as needed for testing.
std::string Filename() override
Return path to main database file for logs and error messages.
bool Backup(const std::string &strDest) const override
Back up the entire database to a file.
std::unique_ptr< DatabaseBatch > MakeBatch() override
Make a SQLiteBatch connected to this database.
std::string Format() override
RAII class that provides access to a WalletDatabase.
bool TxnCommit() override
SQLiteBatch(SQLiteDatabase &database)
bool EraseKey(DataStream &&key) override
bool WriteKey(DataStream &&key, DataStream &&value, bool overwrite=true) override
wallet::DescriptorScriptPubKeyMan * CreateDescriptor(CWallet &keystore, const std::string &desc_str, const bool success)
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase()
const std::string ADDRESS_BCRT1_UNSPENDABLE
MockableSQLiteDatabase & GetMockableDatabase(CWallet &wallet)
std::unique_ptr< CWallet > CreateSyncedWallet(interfaces::Chain &chain, CChain &cchain, const CKey &key)
void TestUnloadWallet(std::shared_ptr< CWallet > &&wallet)
constexpr DatabaseFormat DATABASE_FORMATS[]
std::shared_ptr< CWallet > TestLoadWallet(std::unique_ptr< WalletDatabase > database, WalletContext &context)
std::shared_ptr< CWallet > TestCreateWallet(std::unique_ptr< WalletDatabase > database, WalletContext &context, uint64_t create_flags)
std::map< SerializeData, SerializeData, std::less<> > MockableData
RPCMethod getnewaddress()
CTxDestination getNewDestination(CWallet &w, OutputType output_type)
Returns a new destination, of an specific type, from the wallet.
auto MakeByteSpan(const V &v) noexcept
bool WriteKey(DataStream &&key, DataStream &&value, bool overwrite=true) override
Batch(FaultInjectingDatabase &database)
FaultInjectingDatabase & m_owner
bool EraseKey(DataStream &&key) override
bool TxnCommit() override
WalletContext struct containing references to state shared between CWallet instances,...
std::vector< std::byte, zero_after_free_allocator< std::byte > > SerializeData
Byte-vector that clears its contents before deletion.