test: wallet: Constructing a DSPKM that can't TopUp() throws.

This commit is contained in:
David Gumberg
2026-04-23 15:17:32 -07:00
committed by Ava Chow
parent 32946e0291
commit 451fdd26a4
2 changed files with 17 additions and 3 deletions

View File

@@ -168,14 +168,12 @@ static const std::unordered_set<OutputType> LEGACY_OUTPUT_TYPES {
using KeyMap = std::map<CKeyID, CKey>;
using CryptedKeyMap = std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char>>>;
using ScriptPubKeyMap = std::map<CScript, int32_t>; // Map of scripts to descriptor range index
using PubKeyMap = std::map<CPubKey, int32_t>; // Map of pubkeys involved in scripts to descriptor range index
// Manages the data for a LegacyScriptPubKeyMan.
// This is the minimum necessary to load a legacy wallet so that it can be migrated.
class LegacyDataSPKM : public ScriptPubKeyMan, public FillableSigningProvider
{
protected:
private:
using WatchOnlySet = std::set<CScript>;
using WatchKeyMap = std::map<CKeyID, CPubKey>;
@@ -277,6 +275,9 @@ class DescriptorScriptPubKeyMan : public ScriptPubKeyMan
{
friend class LegacyDataSPKM;
private:
using ScriptPubKeyMap = std::map<CScript, int32_t>; // Map of scripts to descriptor range index
using PubKeyMap = std::map<CPubKey, int32_t>; // Map of pubkeys involved in scripts to descriptor range index
ScriptPubKeyMap m_map_script_pub_keys GUARDED_BY(cs_desc_man);
PubKeyMap m_map_pubkeys GUARDED_BY(cs_desc_man);
int32_t m_max_cached_index = -1;

View File

@@ -4,6 +4,7 @@
#include <key.h>
#include <key_io.h>
#include <test/util/common.h>
#include <test/util/setup_common.h>
#include <script/solver.h>
#include <wallet/scriptpubkeyman.h>
@@ -37,5 +38,17 @@ BOOST_AUTO_TEST_CASE(DescriptorScriptPubKeyManTests)
BOOST_CHECK(signprov_keypath_nums_h == nullptr);
}
BOOST_AUTO_TEST_CASE(desc_spkm_topup_fail)
{
// Attempting to construct a DescriptorSPKM that cannot be topped up (hardened derivation without private keys)
// should throw even though it is valid and can be parsed
CExtKey extkey;
extkey.SetSeed(std::array<std::byte, 32>{});
CWallet keystore(m_node.chain.get(), "", CreateMockableWalletDatabase());
BOOST_CHECK_EXCEPTION(
CreateDescriptor(keystore, "wpkh(" + EncodeExtPubKey(extkey.Neuter()) + "/*h)", /*success=*/true),
std::runtime_error, HasReason("Could not top up scriptPubKeys"));
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace wallet