16 #include <boost/test/unit_test.hpp> 27 for (
int i = 0; i < 2; i++) {
34 std::unique_ptr<interfaces::Chain>& chain =
m_node.
chain;
43 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
47 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
49 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
52 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
53 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
55 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
61 std::string desc_str =
"pk(" +
EncodeSecret(keys[0]) +
")";
66 result = spk_manager->IsMine(scriptPubKey);
74 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
78 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
80 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
83 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
84 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
86 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
92 std::string desc_str =
"pk(" +
EncodeSecret(uncompressedKey) +
")";
97 result = spk_manager->IsMine(scriptPubKey);
105 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
109 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
111 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
114 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
115 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
117 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
123 std::string desc_str =
"pkh(" +
EncodeSecret(keys[0]) +
")";
128 result = spk_manager->IsMine(scriptPubKey);
136 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
140 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
142 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
145 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
146 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
148 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
154 std::string desc_str =
"pkh(" +
EncodeSecret(uncompressedKey) +
")";
159 result = spk_manager->IsMine(scriptPubKey);
167 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
173 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
175 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
178 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemScript));
179 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
181 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
184 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
185 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
187 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
193 std::string desc_str =
"sh(pkh(" +
EncodeSecret(keys[0]) +
"))";
199 result = spk_manager->IsMine(scriptPubKey);
207 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
213 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemscript));
214 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemscript_inner));
215 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
216 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
217 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
219 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
225 std::string desc_str =
"sh(sh(" +
EncodeSecret(keys[0]) +
"))";
235 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
241 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessscript));
242 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemscript));
243 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
244 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
245 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
247 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
253 std::string desc_str =
"wsh(sh(" +
EncodeSecret(keys[0]) +
"))";
263 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
268 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessscript));
269 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
270 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
271 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
273 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
279 std::string desc_str =
"wsh(wpkh(" +
EncodeSecret(keys[0]) +
"))";
289 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
295 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessscript_inner));
296 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessscript));
297 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
298 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
299 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
301 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
307 std::string desc_str =
"wsh(wsh(" +
EncodeSecret(keys[0]) +
"))";
317 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
318 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
323 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
324 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
326 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
332 std::string desc_str =
"wpkh(" +
EncodeSecret(keys[0]) +
")";
337 result = spk_manager->IsMine(scriptPubKey);
345 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
346 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
351 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
353 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
356 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
357 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
359 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
365 std::string desc_str =
"wpkh(" +
EncodeSecret(uncompressedKey) +
")";
375 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
380 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
382 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
385 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
387 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
389 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
392 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
394 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
396 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
399 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
401 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
403 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
414 result = spk_manager->IsMine(scriptPubKey);
422 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
423 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
424 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
430 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
432 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
435 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemScript));
436 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
438 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
451 result = spk_manager->IsMine(scriptPubKey);
459 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
460 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
461 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
467 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
469 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
472 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessScript));
473 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
475 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
478 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
479 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
481 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
494 result = spk_manager->IsMine(scriptPubKey);
502 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
503 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
504 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
510 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
512 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
515 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessScript));
516 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
518 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
521 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
522 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
524 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
541 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
548 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
550 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
553 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemScript));
554 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(witnessScript));
555 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
557 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
560 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
561 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
562 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
564 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
578 result = spk_manager->IsMine(scriptPubKey);
586 std::string desc_str =
"combo(" +
EncodeSecret(keys[0]) +
")";
601 result = spk_manager->IsMine(scriptPubKey);
606 result = spk_manager->IsMine(scriptPubKey);
612 result = spk_manager->IsMine(scriptPubKey);
622 result = spk_manager->IsMine(scriptPubKey);
630 std::string desc_str =
"tr(" +
EncodeSecret(keys[0]) +
")";
640 result = spk_manager->IsMine(scriptPubKey);
648 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
649 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
651 scriptPubKey.
clear();
654 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
656 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
663 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
664 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
666 scriptPubKey.
clear();
667 scriptPubKey <<
OP_0 <<
"aabb"_hex;
669 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
671 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
678 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
679 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
681 scriptPubKey.
clear();
682 scriptPubKey <<
OP_16 <<
"aabb"_hex;
684 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
686 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 0);
693 LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
694 BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
696 scriptPubKey.
clear();
699 result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
701 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
wallet::ScriptPubKeyMan * CreateDescriptor(CWallet &keystore, const std::string &desc_str, const bool success)
BOOST_AUTO_TEST_CASE(ismine_standard)
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_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
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.
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
""_hex is a compile-time user-defined literal returning a std::array<std::byte>, equivalent to ParseH...
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.
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.
std::string EncodeSecret(const CKey &key)
#define Assert(val)
Identity function.
#define BOOST_CHECK(expr)