Branch data Line data Source code
1 : : // Copyright (c) 2020-2021 The Bitcoin Core developers
2 : : // Distributed under the MIT software license, see the accompanying
3 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 : :
5 : : #include <key.h>
6 : : #include <key_io.h>
7 : : #include <test/util/setup_common.h>
8 : : #include <script/solver.h>
9 : : #include <wallet/scriptpubkeyman.h>
10 : : #include <wallet/wallet.h>
11 : : #include <wallet/test/util.h>
12 : :
13 : : #include <boost/test/unit_test.hpp>
14 : :
15 : : namespace wallet {
16 : : BOOST_FIXTURE_TEST_SUITE(scriptpubkeyman_tests, BasicTestingSetup)
17 : :
18 [ + - + - : 7 : BOOST_AUTO_TEST_CASE(DescriptorScriptPubKeyManTests)
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- ]
19 : : {
20 : 1 : std::unique_ptr<interfaces::Chain>& chain = m_node.chain;
21 : :
22 [ + - + - : 2 : CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
+ - ]
23 : 1 : auto key_scriptpath = GenerateRandomKey();
24 : :
25 : : // Verify that a SigningProvider for a pubkey is only returned if its corresponding private key is available
26 : 1 : auto key_internal = GenerateRandomKey();
27 [ + - + - : 3 : std::string desc_str = "tr(" + EncodeSecret(key_internal) + ",pk(" + HexStr(key_scriptpath.GetPubKey()) + "))";
+ - + - +
- ]
28 [ + - + - ]: 1 : auto spk_man1 = dynamic_cast<DescriptorScriptPubKeyMan*>(CreateDescriptor(keystore, desc_str, true));
29 [ + - + - : 2 : BOOST_CHECK(spk_man1 != nullptr);
+ - ]
30 [ + - + - ]: 1 : auto signprov_keypath_spendable = spk_man1->GetSigningProvider(key_internal.GetPubKey());
31 [ + - + - : 2 : BOOST_CHECK(signprov_keypath_spendable != nullptr);
+ - ]
32 : :
33 [ + - + - : 3 : desc_str = "tr(" + HexStr(XOnlyPubKey::NUMS_H) + ",pk(" + HexStr(key_scriptpath.GetPubKey()) + "))";
+ - + - +
- ]
34 [ + - + - ]: 1 : auto spk_man2 = dynamic_cast<DescriptorScriptPubKeyMan*>(CreateDescriptor(keystore, desc_str, true));
35 [ + - + - : 2 : BOOST_CHECK(spk_man2 != nullptr);
+ - ]
36 [ + - + - ]: 1 : auto signprov_keypath_nums_h = spk_man2->GetSigningProvider(XOnlyPubKey::NUMS_H.GetEvenCorrespondingCPubKey());
37 [ + - + - : 2 : BOOST_CHECK(signprov_keypath_nums_h == nullptr);
- + ]
38 [ + - ]: 2 : }
39 : :
40 : : BOOST_AUTO_TEST_SUITE_END()
41 : : } // namespace wallet
|