// Copyright (c) 2021-present The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_WALLET_TEST_UTIL_H #define BITCOIN_WALLET_TEST_UTIL_H #include #include #include #include #include class ArgsManager; class CChain; class CKey; enum class OutputType; namespace interfaces { class Chain; } // namespace interfaces namespace wallet { class CWallet; class WalletDatabase; struct WalletContext; static const DatabaseFormat DATABASE_FORMATS[] = { DatabaseFormat::SQLITE, }; const std::string ADDRESS_BCRT1_UNSPENDABLE = "bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3xueyj"; std::unique_ptr CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, const CKey& key); std::shared_ptr TestCreateWallet(WalletContext& context); std::shared_ptr TestCreateWallet(std::unique_ptr database, WalletContext& context, uint64_t create_flags); std::shared_ptr TestLoadWallet(WalletContext& context); std::shared_ptr TestLoadWallet(std::unique_ptr database, WalletContext& context); void TestUnloadWallet(std::shared_ptr&& wallet); /** Returns a new encoded destination from the wallet (hardcoded to BECH32) */ std::string getnewaddress(CWallet& w); /** Returns a new destination, of an specific type, from the wallet */ CTxDestination getNewDestination(CWallet& w, OutputType output_type); using MockableData = std::map>; class MockableSQLiteBatch : public SQLiteBatch { public: using SQLiteBatch::SQLiteBatch; using SQLiteBatch::WriteKey; }; /** A WalletDatabase whose contents and return values can be modified as needed for testing **/ class MockableSQLiteDatabase : public InMemoryWalletDatabase { public: MockableSQLiteDatabase(); bool Backup(const std::string& strDest) const override { return true; } std::string Filename() override { return "mockable"; } std::string Format() override { return "sqlite-mock"; } std::unique_ptr MakeBatch() override { return std::make_unique(*this); } }; std::unique_ptr CreateMockableWalletDatabase(); MockableSQLiteDatabase& GetMockableDatabase(CWallet& wallet); DescriptorScriptPubKeyMan* CreateDescriptor(CWallet& keystore, const std::string& desc_str, bool success); } // namespace wallet #endif // BITCOIN_WALLET_TEST_UTIL_H