1 #include <boost/assert.hpp>
2 #include <boost/assign/list_of.hpp>
3 #include <boost/assign/list_inserter.hpp>
4 #include <boost/assign/std/vector.hpp>
5 #include <boost/test/unit_test.hpp>
6 #include <boost/foreach.hpp>
7 #include <boost/tuple/tuple.hpp>
9 #include <openssl/ec.h>
10 #include <openssl/err.h>
24 BOOST_AUTO_TEST_SUITE(multisig_tests)
33 BOOST_FOREACH(
const CKey &key, keys)
35 vector<unsigned char> vchSig;
36 BOOST_CHECK(key.
Sign(hash, vchSig));
48 for (
int i = 0; i < 4; i++)
49 key[i].MakeNewKey(
true);
61 txFrom.
vout.resize(3);
62 txFrom.
vout[0].scriptPubKey = a_and_b;
63 txFrom.
vout[1].scriptPubKey = a_or_b;
64 txFrom.
vout[2].scriptPubKey = escrow;
67 for (
int i = 0; i < 3; i++)
69 txTo[i].
vin.resize(1);
70 txTo[i].
vout.resize(1);
71 txTo[i].
vin[0].prevout.n = i;
72 txTo[i].
vin[0].prevout.hash = txFrom.
GetHash();
73 txTo[i].
vout[0].nValue = 1;
81 keys += key[0],key[1];
83 BOOST_CHECK(
VerifyScript(s, a_and_b, txTo[0], 0, flags, 0));
85 for (
int i = 0; i < 4; i++)
93 keys += key[1],key[i];
99 for (
int i = 0; i < 4; i++)
104 if (i == 0 || i == 1)
111 BOOST_CHECK(!
VerifyScript(s, a_or_b, txTo[1], 0, flags, 0));
114 BOOST_CHECK(!
VerifyScript(s, a_or_b, txTo[1], 0, flags, 0));
117 for (
int i = 0; i < 4; i++)
118 for (
int j = 0; j < 4; j++)
121 keys += key[i],key[j];
123 if (i < j && i < 3 && j < 3)
124 BOOST_CHECK_MESSAGE(
VerifyScript(s, escrow, txTo[2], 0, flags, 0),
strprintf(
"escrow 1: %d %d", i, j));
126 BOOST_CHECK_MESSAGE(!
VerifyScript(s, escrow, txTo[2], 0, flags, 0),
strprintf(
"escrow 2: %d %d", i, j));
133 for (
int i = 0; i < 4; i++)
134 key[i].MakeNewKey(
true);
160 for (
int i = 0; i < 6; i++)
179 for (
int i = 0; i < 3; i++)
185 partialkeystore.
AddKey(key[0]);
188 vector<valtype> solutions;
192 BOOST_CHECK(
Solver(s, whichType, solutions));
193 BOOST_CHECK(solutions.size() == 1);
196 BOOST_CHECK(addr == keyaddr[0]);
197 BOOST_CHECK(
IsMine(keystore, s));
198 BOOST_CHECK(!
IsMine(emptykeystore, s));
201 vector<valtype> solutions;
205 BOOST_CHECK(
Solver(s, whichType, solutions));
206 BOOST_CHECK(solutions.size() == 1);
209 BOOST_CHECK(addr == keyaddr[0]);
210 BOOST_CHECK(
IsMine(keystore, s));
211 BOOST_CHECK(!
IsMine(emptykeystore, s));
214 vector<valtype> solutions;
218 BOOST_CHECK(
Solver(s, whichType, solutions));
219 BOOST_CHECK_EQUAL(solutions.size(), 4U);
222 BOOST_CHECK(
IsMine(keystore, s));
223 BOOST_CHECK(!
IsMine(emptykeystore, s));
224 BOOST_CHECK(!
IsMine(partialkeystore, s));
227 vector<valtype> solutions;
231 BOOST_CHECK(
Solver(s, whichType, solutions));
232 BOOST_CHECK_EQUAL(solutions.size(), 4U);
233 vector<CTxDestination> addrs;
236 BOOST_CHECK(addrs[0] == keyaddr[0]);
237 BOOST_CHECK(addrs[1] == keyaddr[1]);
238 BOOST_CHECK(nRequired == 1);
239 BOOST_CHECK(
IsMine(keystore, s));
240 BOOST_CHECK(!
IsMine(emptykeystore, s));
241 BOOST_CHECK(!
IsMine(partialkeystore, s));
244 vector<valtype> solutions;
248 BOOST_CHECK(
Solver(s, whichType, solutions));
249 BOOST_CHECK(solutions.size() == 5);
258 for (
int i = 0; i < 4; i++)
274 txFrom.
vout.resize(3);
275 txFrom.
vout[0].scriptPubKey = a_and_b;
276 txFrom.
vout[1].scriptPubKey = a_or_b;
277 txFrom.
vout[2].scriptPubKey = escrow;
280 for (
int i = 0; i < 3; i++)
282 txTo[i].
vin.resize(1);
283 txTo[i].
vout.resize(1);
284 txTo[i].
vin[0].prevout.n = i;
285 txTo[i].
vin[0].prevout.hash = txFrom.
GetHash();
286 txTo[i].
vout[0].nValue = 1;
289 for (
int i = 0; i < 3; i++)
296 BOOST_AUTO_TEST_SUITE_END()
#define strprintf(format,...)
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CTransaction &txTo, unsigned int nIn, unsigned int flags, int nHashType)
bool SignSignature(const CKeyStore &keystore, const CScript &fromPubKey, CTransaction &txTo, unsigned int nIn, int nHashType)
bool Sign(const uint256 &hash, std::vector< unsigned char > &vchSig) const
uint256 SignatureHash(CScript scriptCode, const CTransaction &txTo, unsigned int nIn, int nHashType)
CPubKey GetPubKey() const
std::vector< CTxOut > vout
void MakeNewKey(bool fCompressed)
bool Solver(const CScript &scriptPubKey, txnouttype &typeRet, vector< vector< unsigned char > > &vSolutionsRet)
virtual bool AddKey(const CKey &key)
CScript sign_multisig(CScript scriptPubKey, vector< CKey > keys, CTransaction transaction, int whichIn)
bool ExtractDestinations(const CScript &scriptPubKey, txnouttype &typeRet, vector< CTxDestination > &addressRet, int &nRequiredRet)
Serialized script, used inside transaction inputs and outputs.
bool IsMine(const CKeyStore &keystore, const CTxDestination &dest)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
bool IsStandard(const CScript &scriptPubKey)
BOOST_AUTO_TEST_CASE(multisig_verify)
vector< unsigned char > valtype
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
An encapsulated private key.
The basic transaction that is broadcasted on the network and contained in blocks. ...
Basic key store, that keeps keys in an address->secret map.