Bitcoin Core  22.99.0
P2P Digital Currency
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 <script/standard.h>
9 #include <wallet/wallet.h>
10 
11 #include <boost/test/unit_test.hpp>
12 
13 namespace wallet {
14 BOOST_FIXTURE_TEST_SUITE(scriptpubkeyman_tests, BasicTestingSetup)
15 
16 // Test LegacyScriptPubKeyMan::CanProvide behavior, making sure it returns true
17 // for recognized scripts even when keys may not be available for signing.
19 {
20  // Set up wallet and keyman variables.
21  CWallet wallet(m_node.chain.get(), "", m_args, CreateDummyWalletDatabase());
22  LegacyScriptPubKeyMan& keyman = *wallet.GetOrCreateLegacyScriptPubKeyMan();
23 
24  // Make a 1 of 2 multisig script
25  std::vector<CKey> keys(2);
26  std::vector<CPubKey> pubkeys;
27  for (CKey& key : keys) {
28  key.MakeNewKey(true);
29  pubkeys.emplace_back(key.GetPubKey());
30  }
31  CScript multisig_script = GetScriptForMultisig(1, pubkeys);
32  CScript p2sh_script = GetScriptForDestination(ScriptHash(multisig_script));
33  SignatureData data;
34 
35  // Verify the p2sh(multisig) script is not recognized until the multisig
36  // script is added to the keystore to make it solvable
37  BOOST_CHECK(!keyman.CanProvide(p2sh_script, data));
38  keyman.AddCScript(multisig_script);
39  BOOST_CHECK(keyman.CanProvide(p2sh_script, data));
40 }
41 
43 } // namespace wallet
wallet.h
setup_common.h
GetScriptForDestination
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition: standard.cpp:310
m_node
node::NodeContext m_node
Definition: bitcoin-gui.cpp:36
wallet
Definition: node.h:38
BOOST_FIXTURE_TEST_SUITE
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
wallet
std::shared_ptr< CWallet > wallet
Definition: notifications.cpp:38
scriptpubkeyman.h
wallet::CreateDummyWalletDatabase
std::unique_ptr< WalletDatabase > CreateDummyWalletDatabase()
Return object for accessing dummy database with no read/write capabilities.
Definition: walletdb.cpp:1184
wallet::LegacyScriptPubKeyMan::AddCScript
bool AddCScript(const CScript &redeemScript) override
Definition: scriptpubkeyman.cpp:1498
SignatureData
Definition: sign.h:63
wallet::LegacyScriptPubKeyMan
Definition: scriptpubkeyman.h:264
wallet::CWallet
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:232
GetScriptForMultisig
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
Generate a multisig script.
Definition: standard.cpp:320
standard.h
BasicTestingSetup
Basic testing setup.
Definition: setup_common.h:83
wallet::LegacyScriptPubKeyMan::CanProvide
bool CanProvide(const CScript &script, SignatureData &sigdata) override
Whether this ScriptPubKeyMan can provide a SigningProvider (via GetSolvingProvider) that,...
Definition: scriptpubkeyman.cpp:582
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:405
wallet::BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(bnb_search_test)
Definition: coinselector_tests.cpp:177
key.h
CKey
An encapsulated private key.
Definition: key.h:26
ScriptHash
Definition: standard.h:89
BOOST_CHECK
#define BOOST_CHECK(expr)
Definition: object.cpp:17
node::NodeContext::chain
std::unique_ptr< interfaces::Chain > chain
Definition: context.h:51