Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2021-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_WALLET_TEST_UTIL_H6#define BITCOIN_WALLET_TEST_UTIL_H8#include <addresstype.h>9#include <wallet/db.h>10#include <wallet/scriptpubkeyman.h>11#include <wallet/sqlite.h>13#include <memory>15class ArgsManager;16class CChain;17class CKey;18enum class OutputType;19namespace interfaces {20class Chain;21} // namespace interfaces23namespace wallet {24class CWallet;25class WalletDatabase;26struct WalletContext;28inline constexpr DatabaseFormat DATABASE_FORMATS[] = {29DatabaseFormat::SQLITE,30};32inline const std::string ADDRESS_BCRT1_UNSPENDABLE = "bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3xueyj";34std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, const CKey& key);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);42/** Returns a new encoded destination from the wallet (hardcoded to BECH32) */43std::string getnewaddress(CWallet& w);44/** Returns a new destination, of an specific type, from the wallet */45CTxDestination getNewDestination(CWallet& w, OutputType output_type);47using MockableData = std::map<SerializeData, SerializeData, std::less<>>;50class MockableSQLiteBatch : public SQLiteBatch51{52public:53using SQLiteBatch::SQLiteBatch;54using SQLiteBatch::WriteKey;55};57/** A WalletDatabase whose contents and return values can be modified as needed for testing58**/59class MockableSQLiteDatabase : public InMemoryWalletDatabase60{61public:62MockableSQLiteDatabase();64bool Backup(const std::string& strDest) const override { return true; }66std::string Filename() override { return "mockable"; }67std::string Format() override { return "sqlite-mock"; }68std::unique_ptr<DatabaseBatch> MakeBatch() override { return std::make_unique<MockableSQLiteBatch>(*this); }69};71std::unique_ptr<WalletDatabase> CreateMockableWalletDatabase();72MockableSQLiteDatabase& GetMockableDatabase(CWallet& wallet);74DescriptorScriptPubKeyMan* CreateDescriptor(CWallet& keystore, const std::string& desc_str, bool success);75} // namespace wallet77#endif // BITCOIN_WALLET_TEST_UTIL_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.