Bitcoin ABC  0.24.11
P2P Digital Currency
scriptpubkeyman_tests.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020 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 <chainparams.h>
6 #include <key.h>
7 #include <script/standard.h>
8 #include <test/util/setup_common.h>
10 #include <wallet/wallet.h>
11 
12 #include <boost/test/unit_test.hpp>
13 
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.
18 BOOST_AUTO_TEST_CASE(CanProvide) {
19  // Set up wallet and keyman variables.
20  NodeContext node;
21  std::unique_ptr<interfaces::Chain> chain =
23  CWallet wallet(chain.get(), "", CreateDummyWalletDatabase());
25 
26  // Make a 1 of 2 multisig script
27  std::vector<CKey> keys(2);
28  std::vector<CPubKey> pubkeys;
29  for (CKey &key : keys) {
30  key.MakeNewKey(true);
31  pubkeys.emplace_back(key.GetPubKey());
32  }
33  CScript multisig_script = GetScriptForMultisig(1, pubkeys);
34  CScript p2sh_script = GetScriptForDestination(ScriptHash(multisig_script));
35  SignatureData data;
36 
37  // Verify the p2sh(multisig) script is not recognized until the multisig
38  // script is added to the keystore to make it solvable
39  BOOST_CHECK(!keyman.CanProvide(p2sh_script, data));
40  keyman.AddCScript(multisig_script);
41  BOOST_CHECK(keyman.CanProvide(p2sh_script, data));
42 }
43 
CreateDummyWalletDatabase
std::unique_ptr< WalletDatabase > CreateDummyWalletDatabase()
Return object for accessing dummy database with no read/write capabilities.
Definition: walletdb.cpp:1164
wallet.h
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(CanProvide)
Definition: scriptpubkeyman_tests.cpp:18
GetScriptForDestination
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition: standard.cpp:243
LegacyScriptPubKeyMan
Definition: scriptpubkeyman.h:320
chainparams.h
BOOST_FIXTURE_TEST_SUITE
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
scriptpubkeyman.h
SignatureData
Definition: sign.h:66
GetScriptForMultisig
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
Generate a multisig script.
Definition: standard.cpp:252
standard.h
LegacyScriptPubKeyMan::AddCScript
bool AddCScript(const CScript &redeemScript) override
Definition: scriptpubkeyman.cpp:1480
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:430
key.h
LegacyScriptPubKeyMan::CanProvide
bool CanProvide(const CScript &script, SignatureData &sigdata) override
Whether this ScriptPubKeyMan can provide a SigningProvider (via GetSolvingProvider) that,...
Definition: scriptpubkeyman.cpp:524
CKey
An encapsulated secp256k1 private key.
Definition: key.h:28
CWallet
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:678
Params
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:508
interfaces::MakeChain
std::unique_ptr< Chain > MakeChain(NodeContext &node, const CChainParams &params)
Return implementation of Chain interface.
Definition: chain.cpp:492
NodeContext
NodeContext struct containing references to chain state and connection state.
Definition: context.h:36
ScriptHash
Definition: standard.h:114
CWallet::GetOrCreateLegacyScriptPubKeyMan
LegacyScriptPubKeyMan * GetOrCreateLegacyScriptPubKeyMan()
Definition: wallet.cpp:4887
BOOST_CHECK
#define BOOST_CHECK(expr)
Definition: object.cpp:17
BOOST_AUTO_TEST_SUITE_END
#define BOOST_AUTO_TEST_SUITE_END()
Definition: object.cpp:16