2014-03-18 10:11:00 +01:00
|
|
|
// Copyright (c) 2011-2013 The Bitcoin Core developers
|
2014-12-13 05:09:33 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2014-03-18 10:11:00 +01:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2011-09-28 18:30:06 +02:00
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
#include "key.h"
|
2011-09-28 18:30:06 +02:00
|
|
|
#include "keystore.h"
|
2014-10-12 00:41:05 +02:00
|
|
|
#include "policy/policy.h"
|
2014-08-20 17:37:40 +02:00
|
|
|
#include "script/script.h"
|
2014-11-13 20:27:38 +01:00
|
|
|
#include "script/script_error.h"
|
2014-08-27 20:11:41 +02:00
|
|
|
#include "script/interpreter.h"
|
2014-08-27 17:22:33 +02:00
|
|
|
#include "script/sign.h"
|
2013-04-13 07:13:08 +02:00
|
|
|
#include "uint256.h"
|
2015-03-12 09:34:42 +01:00
|
|
|
#include "test/test_bitcoin.h"
|
2013-04-13 07:13:08 +02:00
|
|
|
|
2014-08-29 22:07:39 +02:00
|
|
|
#ifdef ENABLE_WALLET
|
2015-02-03 21:09:47 +01:00
|
|
|
#include "wallet/wallet_ismine.h"
|
2014-08-29 22:07:39 +02:00
|
|
|
#endif
|
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
#include <boost/test/unit_test.hpp>
|
2011-09-28 18:30:06 +02:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
typedef vector<unsigned char> valtype;
|
|
|
|
|
2015-03-12 09:34:42 +01:00
|
|
|
BOOST_FIXTURE_TEST_SUITE(multisig_tests, BasicTestingSetup)
|
2011-09-28 18:30:06 +02:00
|
|
|
|
|
|
|
CScript
|
|
|
|
sign_multisig(CScript scriptPubKey, vector<CKey> keys, CTransaction transaction, int whichIn)
|
|
|
|
{
|
|
|
|
uint256 hash = SignatureHash(scriptPubKey, transaction, whichIn, SIGHASH_ALL);
|
|
|
|
|
|
|
|
CScript result;
|
|
|
|
result << OP_0; // CHECKMULTISIG bug workaround
|
2013-05-01 06:52:05 +02:00
|
|
|
BOOST_FOREACH(const CKey &key, keys)
|
2011-09-28 18:30:06 +02:00
|
|
|
{
|
|
|
|
vector<unsigned char> vchSig;
|
|
|
|
BOOST_CHECK(key.Sign(hash, vchSig));
|
|
|
|
vchSig.push_back((unsigned char)SIGHASH_ALL);
|
|
|
|
result << vchSig;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(multisig_verify)
|
|
|
|
{
|
2012-11-13 23:03:25 +01:00
|
|
|
unsigned int flags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC;
|
|
|
|
|
2014-11-13 20:27:38 +01:00
|
|
|
ScriptError err;
|
2011-09-28 18:30:06 +02:00
|
|
|
CKey key[4];
|
|
|
|
for (int i = 0; i < 4; i++)
|
2012-02-20 18:32:33 +01:00
|
|
|
key[i].MakeNewKey(true);
|
2011-09-28 18:30:06 +02:00
|
|
|
|
|
|
|
CScript a_and_b;
|
2014-09-25 04:54:08 +02:00
|
|
|
a_and_b << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
2011-09-28 18:30:06 +02:00
|
|
|
|
|
|
|
CScript a_or_b;
|
2014-09-25 04:54:08 +02:00
|
|
|
a_or_b << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
2011-09-28 18:30:06 +02:00
|
|
|
|
|
|
|
CScript escrow;
|
2014-09-25 04:54:08 +02:00
|
|
|
escrow << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << ToByteVector(key[2].GetPubKey()) << OP_3 << OP_CHECKMULTISIG;
|
2011-09-28 18:30:06 +02:00
|
|
|
|
2014-06-07 13:53:27 +02:00
|
|
|
CMutableTransaction txFrom; // Funding transaction
|
2011-09-28 18:30:06 +02:00
|
|
|
txFrom.vout.resize(3);
|
|
|
|
txFrom.vout[0].scriptPubKey = a_and_b;
|
|
|
|
txFrom.vout[1].scriptPubKey = a_or_b;
|
|
|
|
txFrom.vout[2].scriptPubKey = escrow;
|
|
|
|
|
2014-06-07 13:53:27 +02:00
|
|
|
CMutableTransaction txTo[3]; // Spending transaction
|
2011-09-28 18:30:06 +02:00
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
txTo[i].vin.resize(1);
|
|
|
|
txTo[i].vout.resize(1);
|
|
|
|
txTo[i].vin[0].prevout.n = i;
|
|
|
|
txTo[i].vin[0].prevout.hash = txFrom.GetHash();
|
|
|
|
txTo[i].vout[0].nValue = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<CKey> keys;
|
|
|
|
CScript s;
|
|
|
|
|
|
|
|
// Test a AND b:
|
2014-12-19 22:49:00 +01:00
|
|
|
keys.assign(1,key[0]);
|
|
|
|
keys.push_back(key[1]);
|
2011-09-28 18:30:06 +02:00
|
|
|
s = sign_multisig(a_and_b, keys, txTo[0], 0);
|
2015-01-27 15:01:31 +01:00
|
|
|
BOOST_CHECK(VerifyScript(s, a_and_b, flags, MutableTransactionSignatureChecker(&txTo[0], 0), &err));
|
2014-11-13 20:27:38 +01:00
|
|
|
BOOST_CHECK_MESSAGE(err == SCRIPT_ERR_OK, ScriptErrorString(err));
|
2011-09-28 18:30:06 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
2014-12-19 22:49:00 +01:00
|
|
|
keys.assign(1,key[i]);
|
2011-09-28 18:30:06 +02:00
|
|
|
s = sign_multisig(a_and_b, keys, txTo[0], 0);
|
2015-01-27 15:01:31 +01:00
|
|
|
BOOST_CHECK_MESSAGE(!VerifyScript(s, a_and_b, flags, MutableTransactionSignatureChecker(&txTo[0], 0), &err), strprintf("a&b 1: %d", i));
|
2014-11-13 20:27:38 +01:00
|
|
|
BOOST_CHECK_MESSAGE(err == SCRIPT_ERR_INVALID_STACK_OPERATION, ScriptErrorString(err));
|
2011-09-28 18:30:06 +02:00
|
|
|
|
2014-12-19 22:49:00 +01:00
|
|
|
keys.assign(1,key[1]);
|
|
|
|
keys.push_back(key[i]);
|
2011-09-28 18:30:06 +02:00
|
|
|
s = sign_multisig(a_and_b, keys, txTo[0], 0);
|
2015-01-27 15:01:31 +01:00
|
|
|
BOOST_CHECK_MESSAGE(!VerifyScript(s, a_and_b, flags, MutableTransactionSignatureChecker(&txTo[0], 0), &err), strprintf("a&b 2: %d", i));
|
2014-11-13 20:27:38 +01:00
|
|
|
BOOST_CHECK_MESSAGE(err == SCRIPT_ERR_EVAL_FALSE, ScriptErrorString(err));
|
2011-09-28 18:30:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test a OR b:
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
2014-12-19 22:49:00 +01:00
|
|
|
keys.assign(1,key[i]);
|
2011-09-28 18:30:06 +02:00
|
|
|
s = sign_multisig(a_or_b, keys, txTo[1], 0);
|
|
|
|
if (i == 0 || i == 1)
|
2014-11-13 20:27:38 +01:00
|
|
|
{
|
2015-01-27 15:01:31 +01:00
|
|
|
BOOST_CHECK_MESSAGE(VerifyScript(s, a_or_b, flags, MutableTransactionSignatureChecker(&txTo[1], 0), &err), strprintf("a|b: %d", i));
|
2014-11-13 20:27:38 +01:00
|
|
|
BOOST_CHECK_MESSAGE(err == SCRIPT_ERR_OK, ScriptErrorString(err));
|
|
|
|
}
|
2011-09-28 18:30:06 +02:00
|
|
|
else
|
2014-11-13 20:27:38 +01:00
|
|
|
{
|
2015-01-27 15:01:31 +01:00
|
|
|
BOOST_CHECK_MESSAGE(!VerifyScript(s, a_or_b, flags, MutableTransactionSignatureChecker(&txTo[1], 0), &err), strprintf("a|b: %d", i));
|
2014-11-13 20:27:38 +01:00
|
|
|
BOOST_CHECK_MESSAGE(err == SCRIPT_ERR_EVAL_FALSE, ScriptErrorString(err));
|
|
|
|
}
|
2011-09-28 18:30:06 +02:00
|
|
|
}
|
|
|
|
s.clear();
|
|
|
|
s << OP_0 << OP_1;
|
2015-01-27 15:01:31 +01:00
|
|
|
BOOST_CHECK(!VerifyScript(s, a_or_b, flags, MutableTransactionSignatureChecker(&txTo[1], 0), &err));
|
2014-11-13 20:27:38 +01:00
|
|
|
BOOST_CHECK_MESSAGE(err == SCRIPT_ERR_SIG_DER, ScriptErrorString(err));
|
2011-09-28 18:30:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
for (int j = 0; j < 4; j++)
|
|
|
|
{
|
2014-12-19 22:49:00 +01:00
|
|
|
keys.assign(1,key[i]);
|
|
|
|
keys.push_back(key[j]);
|
2011-09-28 18:30:06 +02:00
|
|
|
s = sign_multisig(escrow, keys, txTo[2], 0);
|
|
|
|
if (i < j && i < 3 && j < 3)
|
2014-11-13 20:27:38 +01:00
|
|
|
{
|
2015-01-27 15:01:31 +01:00
|
|
|
BOOST_CHECK_MESSAGE(VerifyScript(s, escrow, flags, MutableTransactionSignatureChecker(&txTo[2], 0), &err), strprintf("escrow 1: %d %d", i, j));
|
2014-11-13 20:27:38 +01:00
|
|
|
BOOST_CHECK_MESSAGE(err == SCRIPT_ERR_OK, ScriptErrorString(err));
|
|
|
|
}
|
2011-09-28 18:30:06 +02:00
|
|
|
else
|
2014-11-13 20:27:38 +01:00
|
|
|
{
|
2015-01-27 15:01:31 +01:00
|
|
|
BOOST_CHECK_MESSAGE(!VerifyScript(s, escrow, flags, MutableTransactionSignatureChecker(&txTo[2], 0), &err), strprintf("escrow 2: %d %d", i, j));
|
2014-11-13 20:27:38 +01:00
|
|
|
BOOST_CHECK_MESSAGE(err == SCRIPT_ERR_EVAL_FALSE, ScriptErrorString(err));
|
|
|
|
}
|
2011-09-28 18:30:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(multisig_IsStandard)
|
|
|
|
{
|
2011-10-03 19:05:43 +02:00
|
|
|
CKey key[4];
|
|
|
|
for (int i = 0; i < 4; i++)
|
2012-02-20 18:32:33 +01:00
|
|
|
key[i].MakeNewKey(true);
|
2011-09-28 18:30:06 +02:00
|
|
|
|
2013-06-24 21:09:50 +02:00
|
|
|
txnouttype whichType;
|
|
|
|
|
2011-09-28 18:30:06 +02:00
|
|
|
CScript a_and_b;
|
2014-09-25 04:54:08 +02:00
|
|
|
a_and_b << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
2013-06-24 21:09:50 +02:00
|
|
|
BOOST_CHECK(::IsStandard(a_and_b, whichType));
|
2011-09-28 18:30:06 +02:00
|
|
|
|
|
|
|
CScript a_or_b;
|
2014-09-25 04:54:08 +02:00
|
|
|
a_or_b << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
2013-06-24 21:09:50 +02:00
|
|
|
BOOST_CHECK(::IsStandard(a_or_b, whichType));
|
2011-09-28 18:30:06 +02:00
|
|
|
|
|
|
|
CScript escrow;
|
2014-09-25 04:54:08 +02:00
|
|
|
escrow << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << ToByteVector(key[2].GetPubKey()) << OP_3 << OP_CHECKMULTISIG;
|
2013-06-24 21:09:50 +02:00
|
|
|
BOOST_CHECK(::IsStandard(escrow, whichType));
|
2011-10-03 19:05:43 +02:00
|
|
|
|
|
|
|
CScript one_of_four;
|
2014-09-25 04:54:08 +02:00
|
|
|
one_of_four << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << ToByteVector(key[2].GetPubKey()) << ToByteVector(key[3].GetPubKey()) << OP_4 << OP_CHECKMULTISIG;
|
2013-06-24 21:09:50 +02:00
|
|
|
BOOST_CHECK(!::IsStandard(one_of_four, whichType));
|
2011-10-03 19:05:43 +02:00
|
|
|
|
|
|
|
CScript malformed[6];
|
2014-09-25 04:54:08 +02:00
|
|
|
malformed[0] << OP_3 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
|
|
|
malformed[1] << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_3 << OP_CHECKMULTISIG;
|
|
|
|
malformed[2] << OP_0 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
|
|
|
malformed[3] << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_0 << OP_CHECKMULTISIG;
|
|
|
|
malformed[4] << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_CHECKMULTISIG;
|
|
|
|
malformed[5] << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey());
|
2011-10-03 19:05:43 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
2013-06-24 21:09:50 +02:00
|
|
|
BOOST_CHECK(!::IsStandard(malformed[i], whichType));
|
2011-09-28 18:30:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(multisig_Solver1)
|
|
|
|
{
|
|
|
|
// Tests Solver() that returns lists of keys that are
|
|
|
|
// required to satisfy a ScriptPubKey
|
|
|
|
//
|
2014-08-27 17:47:17 +02:00
|
|
|
// Also tests IsMine() and ExtractDestination()
|
2011-09-28 18:30:06 +02:00
|
|
|
//
|
2014-08-27 17:47:17 +02:00
|
|
|
// Note: ExtractDestination for the multisignature transactions
|
2011-09-28 18:30:06 +02:00
|
|
|
// always returns false for this release, even if you have
|
|
|
|
// one key that would satisfy an (a|b) or 2-of-3 keys needed
|
|
|
|
// to spend an escrow transaction.
|
|
|
|
//
|
2012-01-02 08:27:41 +01:00
|
|
|
CBasicKeyStore keystore, emptykeystore, partialkeystore;
|
2011-09-28 18:30:06 +02:00
|
|
|
CKey key[3];
|
2012-05-14 23:44:52 +02:00
|
|
|
CTxDestination keyaddr[3];
|
2011-09-28 18:30:06 +02:00
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
2012-02-20 18:32:33 +01:00
|
|
|
key[i].MakeNewKey(true);
|
2011-09-28 18:30:06 +02:00
|
|
|
keystore.AddKey(key[i]);
|
2012-05-14 23:44:52 +02:00
|
|
|
keyaddr[i] = key[i].GetPubKey().GetID();
|
2011-09-28 18:30:06 +02:00
|
|
|
}
|
2012-01-02 08:27:41 +01:00
|
|
|
partialkeystore.AddKey(key[0]);
|
2011-09-28 18:30:06 +02:00
|
|
|
|
|
|
|
{
|
2011-10-03 19:05:43 +02:00
|
|
|
vector<valtype> solutions;
|
2011-11-08 19:20:29 +01:00
|
|
|
txnouttype whichType;
|
2011-09-28 18:30:06 +02:00
|
|
|
CScript s;
|
2014-09-25 04:54:08 +02:00
|
|
|
s << ToByteVector(key[0].GetPubKey()) << OP_CHECKSIG;
|
2011-10-03 19:05:43 +02:00
|
|
|
BOOST_CHECK(Solver(s, whichType, solutions));
|
2011-09-28 18:30:06 +02:00
|
|
|
BOOST_CHECK(solutions.size() == 1);
|
2012-05-14 23:44:52 +02:00
|
|
|
CTxDestination addr;
|
|
|
|
BOOST_CHECK(ExtractDestination(s, addr));
|
2011-09-28 18:30:06 +02:00
|
|
|
BOOST_CHECK(addr == keyaddr[0]);
|
2014-08-29 22:07:39 +02:00
|
|
|
#ifdef ENABLE_WALLET
|
2011-09-28 18:30:06 +02:00
|
|
|
BOOST_CHECK(IsMine(keystore, s));
|
|
|
|
BOOST_CHECK(!IsMine(emptykeystore, s));
|
2014-08-29 22:07:39 +02:00
|
|
|
#endif
|
2011-09-28 18:30:06 +02:00
|
|
|
}
|
|
|
|
{
|
2011-10-03 19:05:43 +02:00
|
|
|
vector<valtype> solutions;
|
2011-11-08 19:20:29 +01:00
|
|
|
txnouttype whichType;
|
2011-09-28 18:30:06 +02:00
|
|
|
CScript s;
|
2014-09-25 04:54:08 +02:00
|
|
|
s << OP_DUP << OP_HASH160 << ToByteVector(key[0].GetPubKey().GetID()) << OP_EQUALVERIFY << OP_CHECKSIG;
|
2011-10-03 19:05:43 +02:00
|
|
|
BOOST_CHECK(Solver(s, whichType, solutions));
|
2011-09-28 18:30:06 +02:00
|
|
|
BOOST_CHECK(solutions.size() == 1);
|
2012-05-14 23:44:52 +02:00
|
|
|
CTxDestination addr;
|
|
|
|
BOOST_CHECK(ExtractDestination(s, addr));
|
2011-09-28 18:30:06 +02:00
|
|
|
BOOST_CHECK(addr == keyaddr[0]);
|
2014-08-29 22:07:39 +02:00
|
|
|
#ifdef ENABLE_WALLET
|
2011-09-28 18:30:06 +02:00
|
|
|
BOOST_CHECK(IsMine(keystore, s));
|
|
|
|
BOOST_CHECK(!IsMine(emptykeystore, s));
|
2014-08-29 22:07:39 +02:00
|
|
|
#endif
|
2011-09-28 18:30:06 +02:00
|
|
|
}
|
|
|
|
{
|
2011-10-03 19:05:43 +02:00
|
|
|
vector<valtype> solutions;
|
2011-11-08 19:20:29 +01:00
|
|
|
txnouttype whichType;
|
2011-09-28 18:30:06 +02:00
|
|
|
CScript s;
|
2014-09-25 04:54:08 +02:00
|
|
|
s << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
2011-10-03 19:05:43 +02:00
|
|
|
BOOST_CHECK(Solver(s, whichType, solutions));
|
2013-03-07 18:38:25 +01:00
|
|
|
BOOST_CHECK_EQUAL(solutions.size(), 4U);
|
2012-05-14 23:44:52 +02:00
|
|
|
CTxDestination addr;
|
|
|
|
BOOST_CHECK(!ExtractDestination(s, addr));
|
2014-08-29 22:07:39 +02:00
|
|
|
#ifdef ENABLE_WALLET
|
2011-09-28 18:30:06 +02:00
|
|
|
BOOST_CHECK(IsMine(keystore, s));
|
|
|
|
BOOST_CHECK(!IsMine(emptykeystore, s));
|
2012-01-02 08:27:41 +01:00
|
|
|
BOOST_CHECK(!IsMine(partialkeystore, s));
|
2014-08-29 22:07:39 +02:00
|
|
|
#endif
|
2011-09-28 18:30:06 +02:00
|
|
|
}
|
|
|
|
{
|
2011-10-03 19:05:43 +02:00
|
|
|
vector<valtype> solutions;
|
2011-11-08 19:20:29 +01:00
|
|
|
txnouttype whichType;
|
2011-09-28 18:30:06 +02:00
|
|
|
CScript s;
|
2014-09-25 04:54:08 +02:00
|
|
|
s << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
2011-10-03 19:05:43 +02:00
|
|
|
BOOST_CHECK(Solver(s, whichType, solutions));
|
2013-03-07 18:38:25 +01:00
|
|
|
BOOST_CHECK_EQUAL(solutions.size(), 4U);
|
2012-05-14 23:44:52 +02:00
|
|
|
vector<CTxDestination> addrs;
|
2011-10-03 19:05:43 +02:00
|
|
|
int nRequired;
|
2012-05-14 23:44:52 +02:00
|
|
|
BOOST_CHECK(ExtractDestinations(s, whichType, addrs, nRequired));
|
2011-10-03 19:05:43 +02:00
|
|
|
BOOST_CHECK(addrs[0] == keyaddr[0]);
|
|
|
|
BOOST_CHECK(addrs[1] == keyaddr[1]);
|
2012-06-21 20:37:49 +02:00
|
|
|
BOOST_CHECK(nRequired == 1);
|
2014-08-29 22:07:39 +02:00
|
|
|
#ifdef ENABLE_WALLET
|
2011-09-28 18:30:06 +02:00
|
|
|
BOOST_CHECK(IsMine(keystore, s));
|
|
|
|
BOOST_CHECK(!IsMine(emptykeystore, s));
|
2012-01-02 08:27:41 +01:00
|
|
|
BOOST_CHECK(!IsMine(partialkeystore, s));
|
2014-08-29 22:07:39 +02:00
|
|
|
#endif
|
2011-09-28 18:30:06 +02:00
|
|
|
}
|
|
|
|
{
|
2011-10-03 19:05:43 +02:00
|
|
|
vector<valtype> solutions;
|
2011-11-08 19:20:29 +01:00
|
|
|
txnouttype whichType;
|
2011-09-28 18:30:06 +02:00
|
|
|
CScript s;
|
2014-09-25 04:54:08 +02:00
|
|
|
s << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << ToByteVector(key[2].GetPubKey()) << OP_3 << OP_CHECKMULTISIG;
|
2011-10-03 19:05:43 +02:00
|
|
|
BOOST_CHECK(Solver(s, whichType, solutions));
|
|
|
|
BOOST_CHECK(solutions.size() == 5);
|
2011-09-28 18:30:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(multisig_Sign)
|
|
|
|
{
|
|
|
|
// Test SignSignature() (and therefore the version of Solver() that signs transactions)
|
|
|
|
CBasicKeyStore keystore;
|
|
|
|
CKey key[4];
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
2012-02-20 18:32:33 +01:00
|
|
|
key[i].MakeNewKey(true);
|
2011-09-28 18:30:06 +02:00
|
|
|
keystore.AddKey(key[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
CScript a_and_b;
|
2014-09-25 04:54:08 +02:00
|
|
|
a_and_b << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
2011-09-28 18:30:06 +02:00
|
|
|
|
|
|
|
CScript a_or_b;
|
2014-09-25 04:54:08 +02:00
|
|
|
a_or_b << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
2011-09-28 18:30:06 +02:00
|
|
|
|
|
|
|
CScript escrow;
|
2014-09-25 04:54:08 +02:00
|
|
|
escrow << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << ToByteVector(key[2].GetPubKey()) << OP_3 << OP_CHECKMULTISIG;
|
2011-09-28 18:30:06 +02:00
|
|
|
|
2014-06-07 13:53:27 +02:00
|
|
|
CMutableTransaction txFrom; // Funding transaction
|
2011-09-28 18:30:06 +02:00
|
|
|
txFrom.vout.resize(3);
|
|
|
|
txFrom.vout[0].scriptPubKey = a_and_b;
|
|
|
|
txFrom.vout[1].scriptPubKey = a_or_b;
|
|
|
|
txFrom.vout[2].scriptPubKey = escrow;
|
|
|
|
|
2014-06-07 13:53:27 +02:00
|
|
|
CMutableTransaction txTo[3]; // Spending transaction
|
2011-09-28 18:30:06 +02:00
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
txTo[i].vin.resize(1);
|
|
|
|
txTo[i].vout.resize(1);
|
|
|
|
txTo[i].vin[0].prevout.n = i;
|
|
|
|
txTo[i].vin[0].prevout.hash = txFrom.GetHash();
|
|
|
|
txTo[i].vout[0].nValue = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
BOOST_CHECK_MESSAGE(SignSignature(keystore, txFrom, txTo[i], 0), strprintf("SignSignature %d", i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|