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++) {
53 std::unique_ptr<interfaces::Chain>& chain =
m_node.
chain;
62 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
66 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
68 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
71 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
72 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
74 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
80 std::string desc_str =
"pk(" +
EncodeSecret(keys[0]) +
")";
85 result = spk_manager->IsMine(scriptPubKey);
93 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
97 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
99 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
102 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
103 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
105 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
111 std::string desc_str =
"pk(" +
EncodeSecret(uncompressedKey) +
")";
116 result = spk_manager->IsMine(scriptPubKey);
124 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
128 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
130 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
133 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
134 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
136 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
142 std::string desc_str =
"pkh(" +
EncodeSecret(keys[0]) +
")";
147 result = spk_manager->IsMine(scriptPubKey);
155 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
159 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
161 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
164 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
165 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
167 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
173 std::string desc_str =
"pkh(" +
EncodeSecret(uncompressedKey) +
")";
178 result = spk_manager->IsMine(scriptPubKey);
186 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
192 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
194 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
197 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemScript));
198 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
200 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
203 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
204 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
206 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
212 std::string desc_str =
"sh(pkh(" +
EncodeSecret(keys[0]) +
"))";
218 result = spk_manager->IsMine(scriptPubKey);
226 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
232 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemscript));
233 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemscript_inner));
234 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
235 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
236 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
238 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
244 std::string desc_str =
"sh(sh(" +
EncodeSecret(keys[0]) +
"))";
254 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
260 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessscript));
261 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemscript));
262 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
263 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
264 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
266 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
272 std::string desc_str =
"wsh(sh(" +
EncodeSecret(keys[0]) +
"))";
282 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
287 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessscript));
288 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
289 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
290 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
292 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
298 std::string desc_str =
"wsh(wpkh(" +
EncodeSecret(keys[0]) +
"))";
308 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
314 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessscript_inner));
315 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessscript));
316 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
317 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
318 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
320 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
326 std::string desc_str =
"wsh(wsh(" +
EncodeSecret(keys[0]) +
"))";
336 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
337 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
342 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
343 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
345 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
351 std::string desc_str =
"wpkh(" +
EncodeSecret(keys[0]) +
")";
356 result = spk_manager->IsMine(scriptPubKey);
364 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
365 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
370 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
372 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
375 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
376 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
378 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
384 std::string desc_str =
"wpkh(" +
EncodeSecret(uncompressedKey) +
")";
394 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
399 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
401 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
404 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
406 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
408 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
411 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
413 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
415 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
418 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
420 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
422 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
433 result = spk_manager->IsMine(scriptPubKey);
441 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
442 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
443 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
449 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
451 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
454 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemScript));
455 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
457 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
470 result = spk_manager->IsMine(scriptPubKey);
478 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
479 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
480 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
486 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
488 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
491 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessScript));
492 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
494 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
497 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
498 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
500 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
513 result = spk_manager->IsMine(scriptPubKey);
521 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
522 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
523 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
529 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
531 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
534 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessScript));
535 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
537 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
540 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
541 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
543 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
560 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
567 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
569 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
572 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemScript));
573 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessScript));
574 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
576 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
579 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
580 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
581 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
583 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
597 result = spk_manager->IsMine(scriptPubKey);
605 std::string desc_str =
"combo(" +
EncodeSecret(keys[0]) +
")";
620 result = spk_manager->IsMine(scriptPubKey);
625 result = spk_manager->IsMine(scriptPubKey);
631 result = spk_manager->IsMine(scriptPubKey);
641 result = spk_manager->IsMine(scriptPubKey);
649 std::string desc_str =
"tr(" +
EncodeSecret(keys[0]) +
")";
659 result = spk_manager->IsMine(scriptPubKey);
667 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
668 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
670 scriptPubKey.
clear();
673 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
675 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
682 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
683 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
685 scriptPubKey.
clear();
688 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
690 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
697 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
698 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
700 scriptPubKey.
clear();
703 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
705 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
712 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
713 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
715 scriptPubKey.
clear();
718 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
720 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.
void SetupLegacyScriptPubKeyMan()
Make a LegacyScriptPubKeyMan 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...
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)
bool error(const char *fmt, const Args &... args)
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)