Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
wallet
test
scriptpubkeyman_tests.cpp
Go to the documentation of this file.
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
{
21
std::unique_ptr<interfaces::Chain>& chain = m_node.chain;
22
23
CWallet
keystore(chain.get(),
""
,
CreateMockableWalletDatabase
());
24
auto
key_scriptpath =
GenerateRandomKey
();
25
26
// Verify that a SigningProvider for a pubkey is only returned if its corresponding private key is available
27
auto
key_internal =
GenerateRandomKey
();
28
std::string desc_str =
"tr("
+
EncodeSecret
(key_internal) +
",pk("
+
HexStr
(key_scriptpath.GetPubKey()) +
"))"
;
29
auto
spk_man1 =
CreateDescriptor
(keystore, desc_str,
true
);
30
BOOST_CHECK
(spk_man1 !=
nullptr
);
31
auto
signprov_keypath_spendable = spk_man1->GetSigningProvider(key_internal.GetPubKey());
32
BOOST_CHECK
(signprov_keypath_spendable !=
nullptr
);
33
34
desc_str =
"tr("
+
HexStr
(
XOnlyPubKey::NUMS_H
) +
",pk("
+
HexStr
(key_scriptpath.GetPubKey()) +
"))"
;
35
auto
spk_man2 =
CreateDescriptor
(keystore, desc_str,
true
);
36
BOOST_CHECK
(spk_man2 !=
nullptr
);
37
auto
signprov_keypath_nums_h = spk_man2->GetSigningProvider(
XOnlyPubKey::NUMS_H
.GetEvenCorrespondingCPubKey());
38
BOOST_CHECK
(signprov_keypath_nums_h ==
nullptr
);
39
}
40
41
BOOST_AUTO_TEST_CASE
(desc_spkm_topup_fail)
42
{
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
CExtKey
extkey;
46
extkey.
SetSeed
(std::array<std::byte, 32>{});
47
CWallet
keystore(m_node.chain.get(),
""
,
CreateMockableWalletDatabase
());
48
BOOST_CHECK_EXCEPTION
(
49
CreateDescriptor
(keystore,
"wpkh("
+
EncodeExtPubKey
(extkey.
Neuter
()) +
"/*h)"
,
/*success=*/
true
),
50
std::runtime_error,
HasReason
(
"Could not top up scriptPubKeys"
));
51
}
52
53
BOOST_AUTO_TEST_SUITE_END
()
54
}
// namespace wallet
HasReason
BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
Definition
common.h:19
XOnlyPubKey::NUMS_H
static const XOnlyPubKey NUMS_H
Nothing Up My Sleeve point H Used as an internal key for provably disabling the key path spend see BI...
Definition
pubkey.h:195
wallet::CWallet
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition
wallet.h:310
BOOST_FIXTURE_TEST_SUITE
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
HexStr
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
Definition
hex_base.cpp:30
BOOST_CHECK_EXCEPTION
BOOST_CHECK_EXCEPTION(req.LoadBody(reader), std::runtime_error, HasReason{"Cannot parse Content-Length value"})
GenerateRandomKey
CKey GenerateRandomKey(bool compressed) noexcept
Definition
key.cpp:354
key.h
EncodeSecret
std::string EncodeSecret(const CKey &key)
Definition
key_io.cpp:232
EncodeExtPubKey
std::string EncodeExtPubKey(const CExtPubKey &key)
Definition
key_io.cpp:258
key_io.h
wallet
Definition
coin_selection.cpp:31
wallet::CreateDescriptor
wallet::DescriptorScriptPubKeyMan * CreateDescriptor(CWallet &keystore, const std::string &desc_str, const bool success)
Definition
util.cpp:125
wallet::CreateMockableWalletDatabase
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase()
Definition
util.cpp:120
wallet::BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(bnb_test)
Definition
coinselection_tests.cpp:141
BOOST_CHECK
#define BOOST_CHECK(expr)
Definition
object.cpp:16
scriptpubkeyman.h
setup_common.h
solver.h
CExtKey
Definition
key.h:232
CExtKey::Neuter
CExtPubKey Neuter() const
Definition
key.cpp:394
CExtKey::SetSeed
void SetSeed(std::span< const std::byte > seed)
Definition
key.cpp:381
common.h
util.h
wallet.h
Generated on
for Bitcoin Core by
1.18.0