Coverage Report

Created: 2026-05-30 09:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/tmp/bitcoin/src/wallet/test/scriptpubkeyman_tests.cpp
Line
Count
Source
1
// Copyright (c) 2020-present 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/common.h>
8
#include <test/util/setup_common.h>
9
#include <script/solver.h>
10
#include <wallet/scriptpubkeyman.h>
11
#include <wallet/wallet.h>
12
#include <wallet/test/util.h>
13
14
#include <boost/test/unit_test.hpp>
15
16
namespace wallet {
17
BOOST_FIXTURE_TEST_SUITE(scriptpubkeyman_tests, BasicTestingSetup)
18
19
BOOST_AUTO_TEST_CASE(DescriptorScriptPubKeyManTests)
20
1
{
21
1
    std::unique_ptr<interfaces::Chain>& chain = m_node.chain;
22
23
1
    CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
24
1
    auto key_scriptpath = GenerateRandomKey();
25
26
    // Verify that a SigningProvider for a pubkey is only returned if its corresponding private key is available
27
1
    auto key_internal = GenerateRandomKey();
28
1
    std::string desc_str = "tr(" + EncodeSecret(key_internal) + ",pk(" + HexStr(key_scriptpath.GetPubKey()) + "))";
29
1
    auto spk_man1 = CreateDescriptor(keystore, desc_str, true);
30
1
    BOOST_CHECK(spk_man1 != nullptr);
31
1
    auto signprov_keypath_spendable = spk_man1->GetSigningProvider(key_internal.GetPubKey());
32
1
    BOOST_CHECK(signprov_keypath_spendable != nullptr);
33
34
1
    desc_str = "tr(" + HexStr(XOnlyPubKey::NUMS_H) + ",pk(" + HexStr(key_scriptpath.GetPubKey()) + "))";
35
1
    auto spk_man2 = CreateDescriptor(keystore, desc_str, true);
36
1
    BOOST_CHECK(spk_man2 != nullptr);
37
1
    auto signprov_keypath_nums_h = spk_man2->GetSigningProvider(XOnlyPubKey::NUMS_H.GetEvenCorrespondingCPubKey());
38
1
    BOOST_CHECK(signprov_keypath_nums_h == nullptr);
39
1
}
40
41
BOOST_AUTO_TEST_CASE(desc_spkm_topup_fail)
42
1
{
43
    // Attempting to construct a DescriptorSPKM that cannot be topped up (hardened derivation without private keys)
44
    // should throw even though it is valid and can be parsed
45
1
    CExtKey extkey;
46
1
    extkey.SetSeed(std::array<std::byte, 32>{});
47
1
    CWallet keystore(m_node.chain.get(), "", CreateMockableWalletDatabase());
48
    BOOST_CHECK_EXCEPTION(
49
1
        CreateDescriptor(keystore, "wpkh(" + EncodeExtPubKey(extkey.Neuter()) + "/*h)", /*success=*/true),
50
1
        std::runtime_error, HasReason("Could not top up scriptPubKeys"));
51
1
}
52
53
BOOST_AUTO_TEST_SUITE_END()
54
} // namespace wallet