forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscriptpubkeyman_tests.cpp
More file actions
54 lines (45 loc) · 2.27 KB
/
Copy pathscriptpubkeyman_tests.cpp
File metadata and controls
54 lines (45 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2020-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <key.h>
#include <key_io.h>
#include <test/util/common.h>
#include <test/util/setup_common.h>
#include <script/solver.h>
#include <wallet/scriptpubkeyman.h>
#include <wallet/wallet.h>
#include <wallet/test/util.h>
#include <boost/test/unit_test.hpp>
namespace wallet {
BOOST_FIXTURE_TEST_SUITE(scriptpubkeyman_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(DescriptorScriptPubKeyManTests)
{
std::unique_ptr<interfaces::Chain>& chain = m_node.chain;
CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
auto key_scriptpath = GenerateRandomKey();
// Verify that a SigningProvider for a pubkey is only returned if its corresponding private key is available
auto key_internal = GenerateRandomKey();
std::string desc_str = "tr(" + EncodeSecret(key_internal) + ",pk(" + HexStr(key_scriptpath.GetPubKey()) + "))";
auto spk_man1 = CreateDescriptor(keystore, desc_str, true);
BOOST_CHECK(spk_man1 != nullptr);
auto signprov_keypath_spendable = spk_man1->GetSigningProvider(key_internal.GetPubKey());
BOOST_CHECK(signprov_keypath_spendable != nullptr);
desc_str = "tr(" + HexStr(XOnlyPubKey::NUMS_H) + ",pk(" + HexStr(key_scriptpath.GetPubKey()) + "))";
auto spk_man2 = CreateDescriptor(keystore, desc_str, true);
BOOST_CHECK(spk_man2 != nullptr);
auto signprov_keypath_nums_h = spk_man2->GetSigningProvider(XOnlyPubKey::NUMS_H.GetEvenCorrespondingCPubKey());
BOOST_CHECK(signprov_keypath_nums_h == nullptr);
}
BOOST_AUTO_TEST_CASE(desc_spkm_topup_fail)
{
// Attempting to construct a DescriptorSPKM that cannot be topped up (hardened derivation without private keys)
// should throw even though it is valid and can be parsed
CExtKey extkey;
extkey.SetSeed(std::array<std::byte, 32>{});
CWallet keystore(m_node.chain.get(), "", CreateMockableWalletDatabase());
BOOST_CHECK_EXCEPTION(
CreateDescriptor(keystore, "wpkh(" + EncodeExtPubKey(extkey.Neuter()) + "/*h)", /*success=*/true),
std::runtime_error, HasReason("Could not top up scriptPubKeys"));
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace wallet