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) 2020-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#include <key.h>6#include <key_io.h>7#include <test/util/common.h>8#include <test/util/setup_common.h>9#include <script/solver.h>10#include <wallet/scriptpubkeyman.h>11#include <wallet/wallet.h>12#include <wallet/test/util.h>14#include <boost/test/unit_test.hpp>16namespace wallet {17BOOST_FIXTURE_TEST_SUITE(scriptpubkeyman_tests, BasicTestingSetup)19BOOST_AUTO_TEST_CASE(DescriptorScriptPubKeyManTests)20{21std::unique_ptr<interfaces::Chain>& chain = m_node.chain;23CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());24auto key_scriptpath = GenerateRandomKey();26// Verify that a SigningProvider for a pubkey is only returned if its corresponding private key is available27auto key_internal = GenerateRandomKey();28std::string desc_str = "tr(" + EncodeSecret(key_internal) + ",pk(" + HexStr(key_scriptpath.GetPubKey()) + "))";29auto spk_man1 = CreateDescriptor(keystore, desc_str, true);30BOOST_CHECK(spk_man1 != nullptr);31auto signprov_keypath_spendable = spk_man1->GetSigningProvider(key_internal.GetPubKey());32BOOST_CHECK(signprov_keypath_spendable != nullptr);34desc_str = "tr(" + HexStr(XOnlyPubKey::NUMS_H) + ",pk(" + HexStr(key_scriptpath.GetPubKey()) + "))";35auto spk_man2 = CreateDescriptor(keystore, desc_str, true);36BOOST_CHECK(spk_man2 != nullptr);37auto signprov_keypath_nums_h = spk_man2->GetSigningProvider(XOnlyPubKey::NUMS_H.GetEvenCorrespondingCPubKey());38BOOST_CHECK(signprov_keypath_nums_h == nullptr);39}41BOOST_AUTO_TEST_CASE(desc_spkm_topup_fail)42{43// Attempting to construct a DescriptorSPKM that cannot be topped up (hardened derivation without private keys)44// should throw even though it is valid and can be parsed45CExtKey extkey;46extkey.SetSeed(std::array<std::byte, 32>{});47CWallet keystore(m_node.chain.get(), "", CreateMockableWalletDatabase());48BOOST_CHECK_EXCEPTION(49CreateDescriptor(keystore, "wpkh(" + EncodeExtPubKey(extkey.Neuter()) + "/*h)", /*success=*/true),50std::runtime_error, HasReason("Could not top up scriptPubKeys"));51}53BOOST_AUTO_TEST_SUITE_END()54} // 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.