LCOV - code coverage report
Current view: top level - src/wallet/test - util.h (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 50.0 % 6 3
Test Date: 2026-04-27 06:58:15 Functions: 40.0 % 5 2
Branches: 50.0 % 2 1

             Branch data     Line data    Source code
       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>
      10                 :             : #include <wallet/scriptpubkeyman.h>
      11                 :             : #include <wallet/sqlite.h>
      12                 :             : 
      13                 :             : #include <memory>
      14                 :             : 
      15                 :             : class ArgsManager;
      16                 :             : class CChain;
      17                 :             : class CKey;
      18                 :             : enum class OutputType;
      19                 :             : namespace interfaces {
      20                 :             : class Chain;
      21                 :             : } // namespace interfaces
      22                 :             : 
      23                 :             : namespace wallet {
      24                 :             : class CWallet;
      25                 :             : class WalletDatabase;
      26                 :             : struct WalletContext;
      27                 :             : 
      28                 :             : static const DatabaseFormat DATABASE_FORMATS[] = {
      29                 :             :        DatabaseFormat::SQLITE,
      30                 :             : };
      31                 :             : 
      32                 :             : const std::string ADDRESS_BCRT1_UNSPENDABLE = "bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3xueyj";
      33                 :             : 
      34                 :             : std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, const CKey& key);
      35                 :             : 
      36                 :             : std::shared_ptr<CWallet> TestCreateWallet(WalletContext& context);
      37                 :             : std::shared_ptr<CWallet> TestCreateWallet(std::unique_ptr<WalletDatabase> database, WalletContext& context, uint64_t create_flags);
      38                 :             : std::shared_ptr<CWallet> TestLoadWallet(WalletContext& context);
      39                 :             : std::shared_ptr<CWallet> TestLoadWallet(std::unique_ptr<WalletDatabase> database, WalletContext& context);
      40                 :             : void TestUnloadWallet(std::shared_ptr<CWallet>&& wallet);
      41                 :             : 
      42                 :             : // Creates a copy of the provided database
      43                 :             : std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database);
      44                 :             : 
      45                 :             : /** Returns a new encoded destination from the wallet (hardcoded to BECH32) */
      46                 :             : std::string getnewaddress(CWallet& w);
      47                 :             : /** Returns a new destination, of an specific type, from the wallet */
      48                 :             : CTxDestination getNewDestination(CWallet& w, OutputType output_type);
      49                 :             : 
      50                 :             : using MockableData = std::map<SerializeData, SerializeData, std::less<>>;
      51                 :             : 
      52                 :             : 
      53                 :             : class MockableSQLiteBatch : public SQLiteBatch
      54                 :             : {
      55                 :             : public:
      56         [ +  - ]:       19431 :     using SQLiteBatch::SQLiteBatch;
      57                 :             :     using SQLiteBatch::WriteKey;
      58                 :             : };
      59                 :             : 
      60                 :             : /** A WalletDatabase whose contents and return values can be modified as needed for testing
      61                 :             :  **/
      62                 :             : class MockableSQLiteDatabase : public SQLiteDatabase
      63                 :             : {
      64                 :             : public:
      65                 :             :     MockableSQLiteDatabase();
      66                 :             : 
      67                 :           0 :     bool Backup(const std::string& strDest) const override { return true; }
      68                 :             : 
      69                 :       41872 :     std::string Filename() override { return "mockable"; }
      70                 :           0 :     std::vector<fs::path> Files() override { return {}; }
      71                 :           0 :     std::string Format() override { return "sqlite-mock"; }
      72                 :       19431 :     std::unique_ptr<DatabaseBatch> MakeBatch() override { return std::make_unique<MockableSQLiteBatch>(*this); }
      73                 :             : };
      74                 :             : 
      75                 :             : std::unique_ptr<WalletDatabase> CreateMockableWalletDatabase();
      76                 :             : MockableSQLiteDatabase& GetMockableDatabase(CWallet& wallet);
      77                 :             : 
      78                 :             : DescriptorScriptPubKeyMan* CreateDescriptor(CWallet& keystore, const std::string& desc_str, bool success);
      79                 :             : } // namespace wallet
      80                 :             : 
      81                 :             : #endif // BITCOIN_WALLET_TEST_UTIL_H
        

Generated by: LCOV version 2.0-1