|
3 | 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
4 | 4 |
|
5 | 5 | #include <key.h>
|
| 6 | +#include <key_io.h> |
6 | 7 | #include <test/util/setup_common.h>
|
7 | 8 | #include <script/solver.h>
|
8 | 9 | #include <wallet/scriptpubkeyman.h>
|
@@ -40,5 +41,27 @@ BOOST_AUTO_TEST_CASE(CanProvide)
|
40 | 41 | BOOST_CHECK(keyman.CanProvide(p2sh_script, data));
|
41 | 42 | }
|
42 | 43 |
|
| 44 | +BOOST_AUTO_TEST_CASE(DescriptorScriptPubKeyManTests) |
| 45 | +{ |
| 46 | + std::unique_ptr<interfaces::Chain>& chain = m_node.chain; |
| 47 | + |
| 48 | + CWallet keystore(chain.get(), "", CreateMockableWalletDatabase()); |
| 49 | + auto key_scriptpath = GenerateRandomKey(); |
| 50 | + |
| 51 | + // Verify that a SigningProvider for a pubkey is only returned if its corresponding private key is available |
| 52 | + auto key_internal = GenerateRandomKey(); |
| 53 | + std::string desc_str = "tr(" + EncodeSecret(key_internal) + ",pk(" + HexStr(key_scriptpath.GetPubKey()) + "))"; |
| 54 | + auto spk_man1 = dynamic_cast<DescriptorScriptPubKeyMan*>(CreateDescriptor(keystore, desc_str, true)); |
| 55 | + BOOST_CHECK(spk_man1 != nullptr); |
| 56 | + auto signprov_keypath_spendable = spk_man1->GetSigningProvider(key_internal.GetPubKey()); |
| 57 | + BOOST_CHECK(signprov_keypath_spendable != nullptr); |
| 58 | + |
| 59 | + desc_str = "tr(" + HexStr(XOnlyPubKey::NUMS_H) + ",pk(" + HexStr(key_scriptpath.GetPubKey()) + "))"; |
| 60 | + auto spk_man2 = dynamic_cast<DescriptorScriptPubKeyMan*>(CreateDescriptor(keystore, desc_str, true)); |
| 61 | + BOOST_CHECK(spk_man2 != nullptr); |
| 62 | + auto signprov_keypath_nums_h = spk_man2->GetSigningProvider(XOnlyPubKey::NUMS_H.GetEvenCorrespondingCPubKey()); |
| 63 | + BOOST_CHECK(signprov_keypath_nums_h == nullptr); |
| 64 | +} |
| 65 | + |
43 | 66 | BOOST_AUTO_TEST_SUITE_END()
|
44 | 67 | } // namespace wallet
|
0 commit comments