16 #include <boost/test/unit_test.hpp> 28 std::unique_ptr<Descriptor> parsed_desc =
Parse(desc_str, keys, error,
false);
30 if (!success)
return nullptr;
32 const int64_t range_start = 0, range_end = 1, next_index = 0, timestamp = 1;
34 WalletDescriptor w_desc(std::move(parsed_desc), timestamp, range_start, range_end, next_index);
36 LOCK(keystore.cs_wallet);
38 return Assert(keystore.AddWalletDescriptor(w_desc, keys,
"",
false));
45 for (
int i = 0; i < 2; i++) {
52 std::unique_ptr<interfaces::Chain>& chain =
m_node.
chain;
61 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
65 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
67 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
70 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
71 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
73 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
79 std::string desc_str =
"pk(" +
EncodeSecret(keys[0]) +
")";
84 result = spk_manager->IsMine(scriptPubKey);
92 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
96 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
98 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
101 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
102 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
104 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
110 std::string desc_str =
"pk(" +
EncodeSecret(uncompressedKey) +
")";
115 result = spk_manager->IsMine(scriptPubKey);
123 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
127 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
129 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
132 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
133 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
135 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
141 std::string desc_str =
"pkh(" +
EncodeSecret(keys[0]) +
")";
146 result = spk_manager->IsMine(scriptPubKey);
154 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
158 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
160 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
163 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
164 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
166 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
172 std::string desc_str =
"pkh(" +
EncodeSecret(uncompressedKey) +
")";
177 result = spk_manager->IsMine(scriptPubKey);
185 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
191 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
193 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
196 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemScript));
197 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
199 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
202 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
203 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
205 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
211 std::string desc_str =
"sh(pkh(" +
EncodeSecret(keys[0]) +
"))";
217 result = spk_manager->IsMine(scriptPubKey);
225 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
231 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemscript));
232 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemscript_inner));
233 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
234 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
235 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
237 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
243 std::string desc_str =
"sh(sh(" +
EncodeSecret(keys[0]) +
"))";
253 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
259 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessscript));
260 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemscript));
261 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
262 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
263 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
265 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
271 std::string desc_str =
"wsh(sh(" +
EncodeSecret(keys[0]) +
"))";
281 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
286 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessscript));
287 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
288 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
289 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
291 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
297 std::string desc_str =
"wsh(wpkh(" +
EncodeSecret(keys[0]) +
"))";
307 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
313 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessscript_inner));
314 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessscript));
315 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
316 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
317 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
319 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
325 std::string desc_str =
"wsh(wsh(" +
EncodeSecret(keys[0]) +
"))";
335 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
336 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
341 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
342 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
344 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
350 std::string desc_str =
"wpkh(" +
EncodeSecret(keys[0]) +
")";
355 result = spk_manager->IsMine(scriptPubKey);
363 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
364 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
369 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
371 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
374 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
375 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
377 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
383 std::string desc_str =
"wpkh(" +
EncodeSecret(uncompressedKey) +
")";
393 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
398 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
400 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
403 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
405 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
407 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
410 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
412 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
414 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
417 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
419 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
421 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
432 result = spk_manager->IsMine(scriptPubKey);
440 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
441 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
442 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
448 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
450 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
453 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemScript));
454 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
456 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
469 result = spk_manager->IsMine(scriptPubKey);
477 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
478 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
479 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
485 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
487 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
490 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessScript));
491 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
493 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
496 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
497 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
499 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
512 result = spk_manager->IsMine(scriptPubKey);
520 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
521 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
522 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
528 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
530 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
533 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessScript));
534 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
536 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
539 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
540 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
542 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
559 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
566 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
568 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
571 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemScript));
572 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessScript));
573 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
575 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
578 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
579 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
580 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
582 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
596 result = spk_manager->IsMine(scriptPubKey);
604 std::string desc_str =
"combo(" +
EncodeSecret(keys[0]) +
")";
619 result = spk_manager->IsMine(scriptPubKey);
624 result = spk_manager->IsMine(scriptPubKey);
630 result = spk_manager->IsMine(scriptPubKey);
640 result = spk_manager->IsMine(scriptPubKey);
648 std::string desc_str =
"tr(" +
EncodeSecret(keys[0]) +
")";
658 result = spk_manager->IsMine(scriptPubKey);
666 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
667 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
669 scriptPubKey.
clear();
672 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
674 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
681 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
682 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
684 scriptPubKey.
clear();
687 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
689 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
696 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
697 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
699 scriptPubKey.
clear();
702 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
704 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
711 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
712 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
714 scriptPubKey.
clear();
717 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
719 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
Generate a multisig script.
std::unique_ptr< interfaces::Chain > chain
static UniValue Parse(std::string_view raw)
Parse string to UniValue or throw runtime_error if string contains invalid JSON.
wallet::ScriptPubKeyMan * CreateDescriptor(CWallet &keystore, const std::string &desc_str, const bool success)
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
CPubKey GetPubKey() const
Compute the public key from a private key.
CKey GenerateRandomKey(bool compressed) noexcept
void SetupLegacyScriptPubKeyMan()
Make a Legacy(Data)SPKM and set it for all types, internal, and external.
BOOST_AUTO_TEST_SUITE_END()
TaprootBuilder & Finalize(const XOnlyPubKey &internal_key)
Finalize the construction.
An encapsulated public key.
isminetype
IsMine() return codes, which depend on ScriptPubKeyMan implementation.
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
Indicate that this wallet supports DescriptorScriptPubKeyMan.
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
is a home for public enum and struct type definitions that are used by internally by wallet code...
bool IsFullyValid() const
Determine if this pubkey is fully valid.
Descriptor with some wallet metadata.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Utility class to construct Taproot outputs from internal key and script tree.
std::vector< unsigned char > ToByteVector(const T &in)
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase(MockableData records)
#define BOOST_CHECK_EQUAL(v1, v2)
Serialized script, used inside transaction inputs and outputs.
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
Generate a P2PK script for the given pubkey.
An encapsulated private key.
BOOST_AUTO_TEST_CASE(bnb_search_test)
std::string EncodeSecret(const CKey &key)
#define Assert(val)
Identity function.
#define BOOST_CHECK(expr)