17 #include <boost/test/unit_test.hpp> 28 for (
const CKey &key : keys)
30 std::vector<unsigned char> vchSig;
45 for (
int i = 0; i < 4; i++)
46 key[i].MakeNewKey(
true);
58 txFrom.
vout.resize(3);
59 txFrom.
vout[0].scriptPubKey = a_and_b;
60 txFrom.
vout[1].scriptPubKey = a_or_b;
61 txFrom.
vout[2].scriptPubKey = escrow;
64 for (
int i = 0; i < 3; i++)
66 txTo[i].
vin.resize(1);
67 txTo[i].
vout.resize(1);
68 txTo[i].
vin[0].prevout.n = i;
69 txTo[i].
vin[0].prevout.hash = txFrom.
GetHash();
70 txTo[i].
vout[0].nValue = 1;
73 std::vector<CKey> keys;
78 keys.push_back(key[1]);
83 for (
int i = 0; i < 4; i++)
85 keys.assign(1,key[i]);
87 BOOST_CHECK_MESSAGE(!
VerifyScript(s, a_and_b,
nullptr,
flags,
MutableTransactionSignatureChecker(&txTo[0], 0, amount,
MissingDataBehavior::ASSERT_FAIL), &err),
strprintf(
"a&b 1: %d", i));
90 keys.assign(1,key[1]);
91 keys.push_back(key[i]);
93 BOOST_CHECK_MESSAGE(!
VerifyScript(s, a_and_b,
nullptr,
flags,
MutableTransactionSignatureChecker(&txTo[0], 0, amount,
MissingDataBehavior::ASSERT_FAIL), &err),
strprintf(
"a&b 2: %d", i));
98 for (
int i = 0; i < 4; i++)
100 keys.assign(1,key[i]);
102 if (i == 0 || i == 1)
104 BOOST_CHECK_MESSAGE(
VerifyScript(s, a_or_b,
nullptr,
flags,
MutableTransactionSignatureChecker(&txTo[1], 0, amount,
MissingDataBehavior::ASSERT_FAIL), &err),
strprintf(
"a|b: %d", i));
109 BOOST_CHECK_MESSAGE(!
VerifyScript(s, a_or_b,
nullptr,
flags,
MutableTransactionSignatureChecker(&txTo[1], 0, amount,
MissingDataBehavior::ASSERT_FAIL), &err),
strprintf(
"a|b: %d", i));
119 for (
int i = 0; i < 4; i++)
120 for (
int j = 0; j < 4; j++)
122 keys.assign(1,key[i]);
123 keys.push_back(key[j]);
125 if (i < j && i < 3 && j < 3)
127 BOOST_CHECK_MESSAGE(
VerifyScript(s, escrow,
nullptr,
flags,
MutableTransactionSignatureChecker(&txTo[2], 0, amount,
MissingDataBehavior::ASSERT_FAIL), &err),
strprintf(
"escrow 1: %d %d", i, j));
132 BOOST_CHECK_MESSAGE(!
VerifyScript(s, escrow,
nullptr,
flags,
MutableTransactionSignatureChecker(&txTo[2], 0, amount,
MissingDataBehavior::ASSERT_FAIL), &err),
strprintf(
"escrow 2: %d %d", i, j));
141 for (
int i = 0; i < 4; i++)
142 key[i].MakeNewKey(
true);
144 const auto is_standard{[](
const CScript& spk) {
177 for (
int i = 0; i < 6; i++) {
187 for (
int i = 0; i < 4; i++)
203 txFrom.
vout.resize(3);
204 txFrom.
vout[0].scriptPubKey = a_and_b;
205 txFrom.
vout[1].scriptPubKey = a_or_b;
206 txFrom.
vout[2].scriptPubKey = escrow;
209 for (
int i = 0; i < 3; i++)
211 txTo[i].
vin.resize(1);
212 txTo[i].
vout.resize(1);
213 txTo[i].
vin[0].prevout.n = i;
214 txTo[i].
vin[0].prevout.hash = txFrom.
GetHash();
215 txTo[i].
vout[0].nValue = 1;
218 for (
int i = 0; i < 3; i++)
bool SignSignature(const SigningProvider &provider, const CScript &fromPubKey, CMutableTransaction &txTo, unsigned int nIn, const CAmount &amount, int nHashType, SignatureData &sig_data)
Produce a satisfying script (scriptSig or witness).
void assign(size_type n, const T &val)
enum ScriptError_t ScriptError
static CScript sign_multisig(const CScript &scriptPubKey, const std::vector< CKey > &keys, const CTransaction &transaction, int whichIn)
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *serror)
Bare scripts and BIP16 P2SH-wrapped redeemscripts.
bool IsStandard(const CScript &scriptPubKey, const std::optional< unsigned > &max_datacarrier_bytes, TxoutType &whichType)
int64_t CAmount
Amount in satoshis (Can be negative)
Abort execution through assertion failure (for consensus code)
BOOST_AUTO_TEST_SUITE_END()
Fillable signing provider that keeps keys in an address->secret map.
std::string ScriptErrorString(const ScriptError serror)
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
GenericTransactionSignatureChecker< CMutableTransaction > MutableTransactionSignatureChecker
Txid GetHash() const
Compute the hash of this CMutableTransaction.
std::vector< CTxOut > vout
std::vector< unsigned char > ToByteVector(const T &in)
#define BOOST_CHECK_EQUAL(v1, v2)
Serialized script, used inside transaction inputs and outputs.
static bool GetPubKey(const SigningProvider &provider, const SignatureData &sigdata, const CKeyID &address, CPubKey &pubkey)
uint256 SignatureHash(const CScript &scriptCode, const T &txTo, unsigned int nIn, int nHashType, const CAmount &amount, SigVersion sigversion, const PrecomputedTransactionData *cache)
BOOST_AUTO_TEST_CASE(multisig_verify)
A mutable version of CTransaction.
An encapsulated private key.
The basic transaction that is broadcasted on the network and contained in blocks. ...
virtual bool AddKey(const CKey &key)
#define BOOST_CHECK(expr)