mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-03 17:54:19 +02:00
test: wallet: Constructing a DSPKM that can't TopUp() throws.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user