Bitcoin Core
28.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
src
wallet
test
scriptpubkeyman_tests.cpp
Go to the documentation of this file.
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 <
test/util/setup_common.h
>
7
#include <
script/solver.h
>
8
#include <
wallet/scriptpubkeyman.h
>
9
#include <
wallet/wallet.h
>
10
#include <
wallet/test/util.h
>
11
12
#include <boost/test/unit_test.hpp>
13
14
namespace
wallet
{
15
BOOST_FIXTURE_TEST_SUITE(scriptpubkeyman_tests,
BasicTestingSetup
)
16
17
// Test LegacyScriptPubKeyMan::CanProvide behavior, making sure it returns true
18
// for recognized scripts even when keys may not be available for signing.
19
BOOST_AUTO_TEST_CASE
(CanProvide)
20
{
21
// Set up wallet and keyman variables.
22
CWallet
wallet
(
m_node
.
chain
.get(),
""
, CreateMockableWalletDatabase());
23
LegacyScriptPubKeyMan
& keyman = *
wallet
.GetOrCreateLegacyScriptPubKeyMan();
24
25
// Make a 1 of 2 multisig script
26
std::vector<CKey> keys(2);
27
std::vector<CPubKey> pubkeys;
28
for
(
CKey
& key : keys) {
29
key.MakeNewKey(
true
);
30
pubkeys.emplace_back(key.GetPubKey());
31
}
32
CScript
multisig_script =
GetScriptForMultisig
(1, pubkeys);
33
CScript
p2sh_script =
GetScriptForDestination
(
ScriptHash
(multisig_script));
34
SignatureData
data;
35
36
// Verify the p2sh(multisig) script is not recognized until the multisig
37
// script is added to the keystore to make it solvable
38
BOOST_CHECK
(!keyman.
CanProvide
(p2sh_script, data));
39
keyman.
AddCScript
(multisig_script);
40
BOOST_CHECK
(keyman.
CanProvide
(p2sh_script, data));
41
}
42
43
BOOST_AUTO_TEST_SUITE_END
()
44
}
// namespace wallet
GetScriptForDestination
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition
addresstype.cpp:166
m_node
node::NodeContext m_node
Definition
bitcoin-gui.cpp:37
CKey
An encapsulated private key.
Definition
key.h:35
CScript
Serialized script, used inside transaction inputs and outputs.
Definition
script.h:414
wallet::CWallet
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition
wallet.h:300
wallet::LegacyScriptPubKeyMan
Definition
scriptpubkeyman.h:375
wallet::LegacyScriptPubKeyMan::CanProvide
bool CanProvide(const CScript &script, SignatureData &sigdata) override
Whether this ScriptPubKeyMan can provide a SigningProvider (via GetSolvingProvider) that,...
Definition
scriptpubkeyman.cpp:594
wallet::LegacyScriptPubKeyMan::AddCScript
bool AddCScript(const CScript &redeemScript) override
Definition
scriptpubkeyman.cpp:1571
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
key.h
wallet
Definition
wallet_balance.cpp:18
wallet::BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(bnb_search_test)
Definition
coinselector_tests.cpp:191
BOOST_CHECK
#define BOOST_CHECK(expr)
Definition
object.cpp:17
scriptpubkeyman.h
setup_common.h
GetScriptForMultisig
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
Generate a multisig script.
Definition
solver.cpp:218
solver.h
BasicTestingSetup
Basic testing setup.
Definition
setup_common.h:64
ScriptHash
Definition
addresstype.h:59
SignatureData
Definition
sign.h:68
node::NodeContext::chain
std::unique_ptr< interfaces::Chain > chain
Definition
context.h:73
util.h
wallet.h
Generated on Thu Oct 3 2024 09:20:15 for Bitcoin Core by
1.12.0