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) 2022-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or https://www.opensource.org/licenses/mit-license.php.5#include <wallet/test/util.h>6#include <wallet/wallet.h>7#include <test/util/common.h>8#include <test/util/logging.h>9#include <test/util/setup_common.h>11#include <boost/test/unit_test.hpp>13namespace wallet {15BOOST_AUTO_TEST_SUITE(walletload_tests)17class DummyDescriptor final : public Descriptor {18private:19std::string desc;20public:21explicit DummyDescriptor(const std::string& descriptor) : desc(descriptor) {};22~DummyDescriptor() = default;24std::string ToString(bool compat_format) const override { return desc; }25std::string ToCanonicalString() const override { return desc; }26std::optional<OutputType> GetOutputType() const override { return OutputType::UNKNOWN; }28bool IsRange() const override { return true; }29bool IsSolvable() const override { return false; }30bool IsSingleType() const override { return true; }31bool HavePrivateKeys(const SigningProvider&) const override { return false; }32bool ToPrivateString(const SigningProvider& provider, std::string& out) const override { return false; }33bool ToNormalizedString(const SigningProvider& provider, std::string& out, const DescriptorCache* cache = nullptr) const override { return false; }34bool Expand(int pos, const SigningProvider& provider, std::vector<CScript>& output_scripts, FlatSigningProvider& out, DescriptorCache* write_cache = nullptr) const override { return false; };35bool ExpandFromCache(int pos, const DescriptorCache& read_cache, std::vector<CScript>& output_scripts, FlatSigningProvider& out) const override { return false; }36void ExpandPrivate(int pos, const SigningProvider& provider, FlatSigningProvider& out) const override {}37std::optional<int64_t> ScriptSize() const override { return {}; }38std::optional<int64_t> MaxSatisfactionWeight(bool) const override { return {}; }39std::optional<int64_t> MaxSatisfactionElems() const override { return {}; }40void GetPubKeys(std::set<CPubKey>& pubkeys, std::set<CExtPubKey>& ext_pubs) const override {}41bool HasScripts() const override { return true; }42std::vector<std::string> Warnings() const override { return {}; }43uint32_t GetMaxKeyExpr() const override { return 0; }44size_t GetKeyCount() const override { return 0; }45bool CanSelfExpand() const final { return false; }46};48BOOST_FIXTURE_TEST_CASE(wallet_load_descriptors, TestingSetup)49{50bilingual_str _error;51std::vector<bilingual_str> _warnings;52std::unique_ptr<WalletDatabase> database = CreateMockableWalletDatabase();53{54// Write unknown active descriptor55WalletBatch batch(*database);56std::string unknown_desc = "trx(tpubD6NzVbkrYhZ4Y4S7m6Y5s9GD8FqEMBy56AGphZXuagajudVZEnYyBahZMgHNCTJc2at82YX6s8JiL1Lohu5A3v1Ur76qguNH4QVQ7qYrBQx/86'/1'/0'/0/*)#8pn8tzdt";57WalletDescriptor wallet_descriptor(std::make_shared<DummyDescriptor>(unknown_desc), 0, 0, 0, 0);58BOOST_CHECK(batch.WriteDescriptor(uint256(), wallet_descriptor));59BOOST_CHECK(batch.WriteActiveScriptPubKeyMan(static_cast<uint8_t>(OutputType::UNKNOWN), uint256(), false));60}62{63// Now try to load the wallet and verify the error.64const std::shared_ptr<CWallet> wallet(new CWallet(m_node.chain.get(), "", std::move(database)));65BOOST_CHECK_EQUAL(wallet->PopulateWalletFromDB(_error, _warnings), DBErrors::UNKNOWN_DESCRIPTOR);66}68// Test 269// Now write a valid descriptor with a different ID which must be accepted70database = CreateMockableWalletDatabase();72{73// Write valid descriptor with arbitrary ID74WalletBatch batch(*database);75std::string desc = "wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)#cjjspncu";76WalletDescriptor wallet_descriptor(std::make_shared<DummyDescriptor>(desc), 0, 0, 0, 0);77BOOST_CHECK(batch.WriteDescriptor(uint256::ONE, wallet_descriptor));78}80{81// Now try to load the wallet and verify the result.82const std::shared_ptr<CWallet> wallet(new CWallet(m_node.chain.get(), "", std::move(database)));83BOOST_CHECK_EQUAL(wallet->PopulateWalletFromDB(_error, _warnings), DBErrors::LOAD_OK);84}85}87BOOST_AUTO_TEST_SUITE_END()88} // namespace wallet
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.