Update to Core 0.13.2
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"txid": "d21633ba23f70118185227be58a63527675641ad37967e2aa461559f577aec43",
|
||||
"hash": "d21633ba23f70118185227be58a63527675641ad37967e2aa461559f577aec43",
|
||||
"version": 1,
|
||||
"locktime": 0,
|
||||
"vin": [
|
||||
|
||||
@@ -1100,7 +1100,7 @@
|
||||
"NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP 0 0 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 20 CHECKMULTISIG 0 0 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 20 CHECKMULTISIG 0 0 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 20 CHECKMULTISIG 0 0 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 20 CHECKMULTISIG 0 0 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 20 CHECKMULTISIG 0 0 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 20 CHECKMULTISIG 0 0 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 20 CHECKMULTISIG 0 0 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 20 CHECKMULTISIG 0 0 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 20 CHECKMULTISIG",
|
||||
"P2SH,STRICTENC",
|
||||
"OP_COUNT",
|
||||
"Fails due to 201 sig op limit"],
|
||||
"Fails due to 201 script operation limit"],
|
||||
|
||||
["1",
|
||||
"NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP 0 0 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 20 CHECKMULTISIGVERIFY 0 0 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 20 CHECKMULTISIGVERIFY 0 0 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 20 CHECKMULTISIGVERIFY 0 0 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 20 CHECKMULTISIGVERIFY 0 0 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 20 CHECKMULTISIGVERIFY 0 0 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 20 CHECKMULTISIGVERIFY 0 0 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 20 CHECKMULTISIGVERIFY 0 0 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 20 CHECKMULTISIGVERIFY 0 0 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 20 CHECKMULTISIGVERIFY",
|
||||
@@ -1310,6 +1310,13 @@
|
||||
"EVAL_FALSE",
|
||||
"P2SH(P2PK), bad redeemscript"
|
||||
],
|
||||
[
|
||||
"0x47 0x30440220781ba4f59a7b207a10db87628bc2168df4d59b844b397d2dbc9a5835fb2f2b7602206ed8fbcc1072fe2dfc5bb25909269e5dc42ffcae7ec2bc81d59692210ff30c2b01 0x41 0x0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 0x19 0x76a91491b24bf9f5288532960ac687abb035127b1d28a588ac",
|
||||
"HASH160 0x14 0x7f67f0521934a57d3039f77f9f32cf313f3ac74b EQUAL",
|
||||
"P2SH",
|
||||
"OK",
|
||||
"P2SH(P2PKH)"
|
||||
],
|
||||
[
|
||||
"0x47 0x304402204e2eb034be7b089534ac9e798cf6a2c79f38bcb34d1b179efd6f2de0841735db022071461beb056b5a7be1819da6a3e3ce3662831ecc298419ca101eb6887b5dd6a401 0x19 0x76a9147cf9c846cd4882efec4bf07e44ebdad495c94f4b88ac",
|
||||
"HASH160 0x14 0x2df519943d5acc0ef5222091f9dfe3543f489a82 EQUAL",
|
||||
@@ -1478,6 +1485,27 @@
|
||||
"OK",
|
||||
"BIP66 example 4, with DERSIG"
|
||||
],
|
||||
[
|
||||
"0x09 0x300602010102010101",
|
||||
"0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 CHECKSIG NOT",
|
||||
"DERSIG",
|
||||
"OK",
|
||||
"BIP66 example 4, with DERSIG, non-null DER-compliant signature"
|
||||
],
|
||||
[
|
||||
"0",
|
||||
"0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 CHECKSIG NOT",
|
||||
"DERSIG,NULLFAIL",
|
||||
"OK",
|
||||
"BIP66 example 4, with DERSIG and NULLFAIL"
|
||||
],
|
||||
[
|
||||
"0x09 0x300602010102010101",
|
||||
"0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 CHECKSIG NOT",
|
||||
"DERSIG,NULLFAIL",
|
||||
"NULLFAIL",
|
||||
"BIP66 example 4, with DERSIG and NULLFAIL, non-null DER-compliant signature"
|
||||
],
|
||||
[
|
||||
"1",
|
||||
"0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 CHECKSIG",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"txid": "81b2035be1da1abe745c6141174a73d151009ec17b3d5ebffa2e177408c50dfd",
|
||||
"hash": "81b2035be1da1abe745c6141174a73d151009ec17b3d5ebffa2e177408c50dfd",
|
||||
"version": 1,
|
||||
"locktime": 0,
|
||||
"vin": [
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"txid": "c46ccd75b5050e942b2e86a3648f843f525fe6fc000bf0534ba5973063354493",
|
||||
"hash": "c46ccd75b5050e942b2e86a3648f843f525fe6fc000bf0534ba5973063354493",
|
||||
"version": 1,
|
||||
"locktime": 0,
|
||||
"vin": [
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"txid": "aded538f642c17e15f4d3306b8be7e1a4d1ae0c4616d641ab51ea09ba65e5cb5",
|
||||
"hash": "aded538f642c17e15f4d3306b8be7e1a4d1ae0c4616d641ab51ea09ba65e5cb5",
|
||||
"version": 1,
|
||||
"locktime": 317000,
|
||||
"vin": [
|
||||
|
||||
@@ -30,10 +30,6 @@
|
||||
"010000000100010000000000000000000000000000000000000000000000000000000000000000000009085768617420697320ffffffff010000000000000000015100000000", "P2SH"],
|
||||
|
||||
["Tests for CheckTransaction()"],
|
||||
["No inputs"],
|
||||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "HASH160 0x14 0x7a052c840ba73af26755de42cf01cc9e0a49fef0 EQUAL"]],
|
||||
"0100000000010000000000000000015100000000", "P2SH"],
|
||||
|
||||
["No outputs"],
|
||||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "HASH160 0x14 0x05ab9e14d983742513f0f451e105ffb4198d1dd4 EQUAL"]],
|
||||
"01000000010001000000000000000000000000000000000000000000000000000000000000000000006d483045022100f16703104aab4e4088317c862daec83440242411b039d14280e03dd33b487ab802201318a7be236672c5c56083eb7a5a195bc57a40af7923ff8545016cd3b571e2a601232103c40e5d339df3f30bf753e7e04450ae4ef76c9e45587d1d993bdc4cd06f0651c7acffffffff0000000000", "P2SH"],
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"txid": "f70f0d6c71416ed538e37549f430ab3665fee2437a42f10238c1bd490e782231",
|
||||
"hash": "f70f0d6c71416ed538e37549f430ab3665fee2437a42f10238c1bd490e782231",
|
||||
"version": 1,
|
||||
"locktime": 0,
|
||||
"vin": [
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"txid": "cf90229625e9eb10f6be8156bf6aa5ec2eca19a42b1e05c11f3029b560a32e13",
|
||||
"hash": "cf90229625e9eb10f6be8156bf6aa5ec2eca19a42b1e05c11f3029b560a32e13",
|
||||
"version": 1,
|
||||
"locktime": 0,
|
||||
"vin": [
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"txid": "07894b4d12fe7853dd911402db1620920d261b9627c447f931417d330c25f06e",
|
||||
"hash": "07894b4d12fe7853dd911402db1620920d261b9627c447f931417d330c25f06e",
|
||||
"version": 1,
|
||||
"locktime": 0,
|
||||
"vin": [
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"txid": "4ed17118f5e932ba8c75c461787d171bc02a016d8557cb5bcf34cd416c27bb8b",
|
||||
"hash": "4ed17118f5e932ba8c75c461787d171bc02a016d8557cb5bcf34cd416c27bb8b",
|
||||
"version": 1,
|
||||
"locktime": 0,
|
||||
"vin": [
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"txid": "71603ccb1cd76d73d76eb6cfd5f0b9df6d65d90d76860ee52cb461c4be7032e8",
|
||||
"hash": "71603ccb1cd76d73d76eb6cfd5f0b9df6d65d90d76860ee52cb461c4be7032e8",
|
||||
"version": 1,
|
||||
"locktime": 0,
|
||||
"vin": [
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"txid": "c4dea671b0d7b48f8ab10bc46650e8329d3c5766931f548f513847a19f5ba75b",
|
||||
"hash": "c4dea671b0d7b48f8ab10bc46650e8329d3c5766931f548f513847a19f5ba75b",
|
||||
"version": 1,
|
||||
"locktime": 0,
|
||||
"vin": [
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"txid": "977e7cd286cb72cd470d539ba6cb48400f8f387d97451d45cdb8819437a303af",
|
||||
"hash": "977e7cd286cb72cd470d539ba6cb48400f8f387d97451d45cdb8819437a303af",
|
||||
"version": 1,
|
||||
"locktime": 0,
|
||||
"vin": [
|
||||
|
||||
@@ -181,6 +181,7 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey,
|
||||
// NOTE: These tests rely on CreateNewBlock doing its own self-validation!
|
||||
BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
{
|
||||
// Note that by default, these tests run with size accounting enabled.
|
||||
const CChainParams& chainparams = Params(CBaseChainParams::MAIN);
|
||||
CScript scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
|
||||
CBlockTemplate *pblocktemplate;
|
||||
@@ -212,6 +213,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
txCoinbase.vin[0].scriptSig = CScript();
|
||||
txCoinbase.vin[0].scriptSig.push_back(blockinfo[i].extranonce);
|
||||
txCoinbase.vin[0].scriptSig.push_back(chainActive.Height());
|
||||
txCoinbase.vout.resize(1);
|
||||
txCoinbase.vout[0].scriptPubKey = CScript();
|
||||
pblock->vtx[0] = CTransaction(txCoinbase);
|
||||
if (txFirst.size() == 0)
|
||||
@@ -264,7 +266,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
hash = tx.GetHash();
|
||||
bool spendsCoinbase = (i == 0) ? true : false; // only first tx spends coinbase
|
||||
// If we do set the # of sig ops in the CTxMemPoolEntry, template creation passes
|
||||
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).SigOps(20).FromTx(tx));
|
||||
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).SigOpsCost(20).FromTx(tx));
|
||||
tx.vin[0].prevout.hash = hash;
|
||||
}
|
||||
BOOST_CHECK(pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey));
|
||||
@@ -477,7 +479,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 3);
|
||||
delete pblocktemplate;
|
||||
// However if we advance height by 1 and time by 512, all of them should be mined
|
||||
for (int i = 0; i < 11; i++)
|
||||
for (int i = 0; i < CBlockIndex::nMedianTimeSpan; i++)
|
||||
chainActive.Tip()->GetAncestor(chainActive.Tip()->nHeight - i)->nTime += 512; //Trick the MedianTimePast
|
||||
chainActive.Tip()->nHeight++;
|
||||
SetMockTime(chainActive.Tip()->GetPastTimeLimit() + 1);
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
#include "test/test_bitcoin.h"
|
||||
#include <string>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "chainparams.h"
|
||||
#include "hash.h"
|
||||
#include "serialize.h"
|
||||
#include "streams.h"
|
||||
#include "net.h"
|
||||
#include "netbase.h"
|
||||
#include "chainparams.h"
|
||||
#include "serialize.h"
|
||||
#include "streams.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "util.h"
|
||||
#include "utilstrencodings.h"
|
||||
#include "test/test_bitcoin.h"
|
||||
#include "rpc/server.h"
|
||||
|
||||
#if defined(HAVE_CONSENSUS_LIB)
|
||||
#include "script/bitcoinconsensus.h"
|
||||
@@ -149,12 +150,15 @@ CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CMu
|
||||
void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, int flags, const std::string& message, int scriptError, CAmount nValue = 0)
|
||||
{
|
||||
bool expect = (scriptError == SCRIPT_ERR_OK);
|
||||
if (flags & SCRIPT_VERIFY_CLEANSTACK) {
|
||||
flags |= SCRIPT_VERIFY_P2SH;
|
||||
}
|
||||
ScriptError err;
|
||||
CMutableTransaction txCredit = BuildCreditingTransaction(scriptPubKey, nValue);
|
||||
CMutableTransaction tx = BuildSpendingTransaction(scriptSig, txCredit);
|
||||
CMutableTransaction tx2 = tx;
|
||||
BOOST_CHECK_MESSAGE(VerifyScript(scriptSig, scriptPubKey, flags, MutableTransactionSignatureChecker(&tx, 0, txCredit.vout[0].nValue), &err) == expect, message);
|
||||
BOOST_CHECK_MESSAGE(expect == (err == SCRIPT_ERR_OK), std::string(ScriptErrorString(err)) + ": " + message);
|
||||
BOOST_CHECK_MESSAGE(err == scriptError, std::string(FormatScriptError(err)) + " where " + std::string(FormatScriptError((ScriptError_t)scriptError)) + " expected: " + message);
|
||||
#if defined(HAVE_CONSENSUS_LIB)
|
||||
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
|
||||
stream << tx2;
|
||||
@@ -242,11 +246,13 @@ struct KeyData
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class TestBuilder
|
||||
{
|
||||
private:
|
||||
CScript scriptPubKey;
|
||||
//! Actually executed script
|
||||
CScript script;
|
||||
//! The P2SH redeemscript
|
||||
CScript redeemscript;
|
||||
CTransaction creditTx;
|
||||
CMutableTransaction spendTx;
|
||||
bool havePush;
|
||||
@@ -272,8 +278,9 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
TestBuilder(const CScript& redeemScript, const std::string& comment_, int flags_, bool P2SH = false) : scriptPubKey(redeemScript), havePush(false), comment(comment_), flags(flags_), scriptError(SCRIPT_ERR_OK), nValue(nValue_)
|
||||
TestBuilder(const CScript& script_, const std::string& comment_, int flags_, bool P2SH = false, CAmount nValue_ = 0) : script(script_), havePush(false), comment(comment_), flags(flags_), scriptError(SCRIPT_ERR_OK), nValue(nValue_)
|
||||
{
|
||||
CScript scriptPubKey = script;
|
||||
if (P2SH) {
|
||||
redeemscript = scriptPubKey;
|
||||
scriptPubKey = CScript() << OP_HASH160 << ToByteVector(CScriptID(redeemscript)) << OP_EQUAL;
|
||||
@@ -308,9 +315,14 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
TestBuilder& Push(const CScript& script) {
|
||||
DoPush(std::vector<unsigned char>(script.begin(), script.end()));
|
||||
return *this;
|
||||
}
|
||||
|
||||
TestBuilder& PushSig(const CKey& key, int nHashType = SIGHASH_ALL, unsigned int lenR = 32, unsigned int lenS = 32, CAmount amount = 0)
|
||||
{
|
||||
uint256 hash = SignatureHash(scriptPubKey, spendTx, 0, nHashType, amount);
|
||||
uint256 hash = SignatureHash(script, spendTx, 0, nHashType, amount);
|
||||
std::vector<unsigned char> vchSig, r, s;
|
||||
uint32_t iter = 0;
|
||||
do {
|
||||
@@ -334,7 +346,7 @@ public:
|
||||
|
||||
TestBuilder& PushRedeem()
|
||||
{
|
||||
DoPush(std::vector<unsigned char>(scriptPubKey.begin(), scriptPubKey.end()));
|
||||
DoPush(std::vector<unsigned char>(redeemscript.begin(), redeemscript.end()));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -441,7 +453,9 @@ BOOST_AUTO_TEST_CASE(script_build)
|
||||
tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey0C) << OP_CHECKSIG,
|
||||
"P2SH(P2PK), bad redeemscript", SCRIPT_VERIFY_P2SH, true
|
||||
).PushSig(keys.key0).PushRedeem().DamagePush(10).ScriptError(SCRIPT_ERR_EVAL_FALSE));
|
||||
|
||||
tests.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << ToByteVector(keys.pubkey0.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG,
|
||||
"P2SH(P2PKH)", SCRIPT_VERIFY_P2SH, true
|
||||
).PushSig(keys.key0).Push(keys.pubkey0).PushRedeem());
|
||||
tests.push_back(TestBuilder(CScript() << OP_DUP << OP_HASH160 << ToByteVector(keys.pubkey1.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG,
|
||||
"P2SH(P2PKH), bad sig but no VERIFY_P2SH", 0, true
|
||||
).PushSig(keys.key0).DamagePush(10).PushRedeem());
|
||||
@@ -671,7 +685,6 @@ BOOST_AUTO_TEST_CASE(script_build)
|
||||
"P2SH with CLEANSTACK", SCRIPT_VERIFY_CLEANSTACK | SCRIPT_VERIFY_P2SH, true
|
||||
).PushSig(keys.key0).PushRedeem());
|
||||
|
||||
|
||||
std::set<std::string> tests_set;
|
||||
|
||||
{
|
||||
@@ -812,7 +825,7 @@ BOOST_AUTO_TEST_CASE(script_CHECKMULTISIG12)
|
||||
CScript scriptPubKey12;
|
||||
scriptPubKey12 << OP_1 << ToByteVector(key1.GetPubKey()) << ToByteVector(key2.GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
|
||||
|
||||
CMutableTransaction txFrom12 = BuildCreditingTransaction(scriptPubKey12, 0);
|
||||
CMutableTransaction txFrom12 = BuildCreditingTransaction(scriptPubKey12);
|
||||
CMutableTransaction txTo12 = BuildSpendingTransaction(CScript(), txFrom12);
|
||||
|
||||
CScript goodsig1 = sign_multisig(scriptPubKey12, key1, txTo12);
|
||||
@@ -843,7 +856,7 @@ BOOST_AUTO_TEST_CASE(script_CHECKMULTISIG23)
|
||||
CScript scriptPubKey23;
|
||||
scriptPubKey23 << OP_2 << ToByteVector(key1.GetPubKey()) << ToByteVector(key2.GetPubKey()) << ToByteVector(key3.GetPubKey()) << OP_3 << OP_CHECKMULTISIG;
|
||||
|
||||
CMutableTransaction txFrom23 = BuildCreditingTransaction(scriptPubKey23, 0);
|
||||
CMutableTransaction txFrom23 = BuildCreditingTransaction(scriptPubKey23);
|
||||
CMutableTransaction txTo23 = BuildSpendingTransaction(CScript(), txFrom23);
|
||||
|
||||
std::vector<CKey> keys;
|
||||
@@ -916,7 +929,7 @@ BOOST_AUTO_TEST_CASE(script_combineSigs)
|
||||
keystore.AddKey(key);
|
||||
}
|
||||
|
||||
CMutableTransaction txFrom = BuildCreditingTransaction(GetScriptForDestination(keys[0].GetPubKey().GetID()), 0);
|
||||
CMutableTransaction txFrom = BuildCreditingTransaction(GetScriptForDestination(keys[0].GetPubKey().GetID()));
|
||||
CMutableTransaction txTo = BuildSpendingTransaction(CScript(), txFrom);
|
||||
CScript& scriptPubKey = txFrom.vout[0].scriptPubKey;
|
||||
CScript& scriptSig = txTo.vin[0].scriptSig;
|
||||
@@ -927,44 +940,44 @@ BOOST_AUTO_TEST_CASE(script_combineSigs)
|
||||
|
||||
// Single signature case:
|
||||
SignSignature(keystore, txFrom, txTo, 0, SIGHASH_ALL); // changes scriptSig
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), scriptSig, empty);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), SignatureData(scriptSig), empty);
|
||||
BOOST_CHECK(combined == scriptSig);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), empty, scriptSig);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), empty, SignatureData(scriptSig));
|
||||
BOOST_CHECK(combined == scriptSig);
|
||||
CScript scriptSigCopy = scriptSig;
|
||||
// Signing again will give a different, valid signature:
|
||||
SignSignature(keystore, txFrom, txTo, 0);
|
||||
combined = CombineSignatures(scriptPubKey, txTo, 0, scriptSigCopy, scriptSig);
|
||||
BOOST_CHECK(combined == scriptSigCopy || combined == scriptSig);
|
||||
SignSignature(keystore, txFrom, txTo, 0, SIGHASH_ALL);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), SignatureData(scriptSigCopy), SignatureData(scriptSig));
|
||||
BOOST_CHECK(combined.scriptSig == scriptSigCopy || combined.scriptSig == scriptSig);
|
||||
|
||||
// P2SH, single-signature case:
|
||||
CScript pkSingle; pkSingle << ToByteVector(keys[0].GetPubKey()) << OP_CHECKSIG;
|
||||
keystore.AddCScript(pkSingle);
|
||||
scriptPubKey = GetScriptForDestination(CScriptID(pkSingle));
|
||||
SignSignature(keystore, txFrom, txTo, 0, SIGHASH_ALL);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), scriptSig, empty);
|
||||
BOOST_CHECK(combined == scriptSig);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), empty, scriptSig);
|
||||
BOOST_CHECK(combined == scriptSig);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), SignatureData(scriptSig), empty);
|
||||
BOOST_CHECK(combined.scriptSig == scriptSig);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), empty, SignatureData(scriptSig));
|
||||
BOOST_CHECK(combined.scriptSig == scriptSig);
|
||||
scriptSigCopy = scriptSig;
|
||||
SignSignature(keystore, txFrom, txTo, 0, SIGHASH_ALL);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), scriptSigCopy, scriptSig);
|
||||
BOOST_CHECK(combined == scriptSigCopy || combined == scriptSig);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), SignatureData(scriptSigCopy), SignatureData(scriptSig));
|
||||
BOOST_CHECK(combined.scriptSig == scriptSigCopy || combined.scriptSig == scriptSig);
|
||||
// dummy scriptSigCopy with placeholder, should always choose non-placeholder:
|
||||
scriptSigCopy = CScript() << OP_0 << vector<unsigned char>(pkSingle.begin(), pkSingle.end());
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), scriptSigCopy, scriptSig);
|
||||
BOOST_CHECK(combined == scriptSig);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), scriptSig, scriptSigCopy);
|
||||
BOOST_CHECK(combined == scriptSig);
|
||||
scriptSigCopy = CScript() << OP_0 << std::vector<unsigned char>(pkSingle.begin(), pkSingle.end());
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), SignatureData(scriptSigCopy), SignatureData(scriptSig));
|
||||
BOOST_CHECK(combined.scriptSig == scriptSig);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), SignatureData(scriptSig), SignatureData(scriptSigCopy));
|
||||
BOOST_CHECK(combined.scriptSig == scriptSig);
|
||||
|
||||
// Hardest case: Multisig 2-of-3
|
||||
scriptPubKey = GetScriptForMultisig(2, pubkeys);
|
||||
keystore.AddCScript(scriptPubKey);
|
||||
SignSignature(keystore, txFrom, txTo, 0, SIGHASH_ALL);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), scriptSig, empty);
|
||||
BOOST_CHECK(combined == scriptSig);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), empty, scriptSig);
|
||||
BOOST_CHECK(combined == scriptSig);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), SignatureData(scriptSig), empty);
|
||||
BOOST_CHECK(combined.scriptSig == scriptSig);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), empty, SignatureData(scriptSig));
|
||||
BOOST_CHECK(combined.scriptSig == scriptSig);
|
||||
|
||||
// A couple of partially-signed versions:
|
||||
vector<unsigned char> sig1;
|
||||
@@ -992,22 +1005,22 @@ BOOST_AUTO_TEST_CASE(script_combineSigs)
|
||||
CScript complete13 = CScript() << OP_0 << sig1 << sig3;
|
||||
CScript complete23 = CScript() << OP_0 << sig2 << sig3;
|
||||
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), partial1a, partial1b);
|
||||
BOOST_CHECK(combined == partial1a);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), partial1a, partial2a);
|
||||
BOOST_CHECK(combined == complete12);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), partial2a, partial1a);
|
||||
BOOST_CHECK(combined == complete12);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), partial1b, partial2b);
|
||||
BOOST_CHECK(combined == complete12);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), partial3b, partial1b);
|
||||
BOOST_CHECK(combined == complete13);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), partial2a, partial3a);
|
||||
BOOST_CHECK(combined == complete23);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), partial3b, partial2b);
|
||||
BOOST_CHECK(combined == complete23);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), partial3b, partial3a);
|
||||
BOOST_CHECK(combined == partial3c);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), SignatureData(partial1a), SignatureData(partial1b));
|
||||
BOOST_CHECK(combined.scriptSig == partial1a);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), SignatureData(partial1a), SignatureData(partial2a));
|
||||
BOOST_CHECK(combined.scriptSig == complete12);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), SignatureData(partial2a), SignatureData(partial1a));
|
||||
BOOST_CHECK(combined.scriptSig == complete12);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), SignatureData(partial1b), SignatureData(partial2b));
|
||||
BOOST_CHECK(combined.scriptSig == complete12);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), SignatureData(partial3b), SignatureData(partial1b));
|
||||
BOOST_CHECK(combined.scriptSig == complete13);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), SignatureData(partial2a), SignatureData(partial3a));
|
||||
BOOST_CHECK(combined.scriptSig == complete23);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), SignatureData(partial3b), SignatureData(partial2b));
|
||||
BOOST_CHECK(combined.scriptSig == complete23);
|
||||
combined = CombineSignatures(scriptPubKey, MutableTransactionSignatureChecker(&txTo, 0, amount), SignatureData(partial3b), SignatureData(partial3a));
|
||||
BOOST_CHECK(combined.scriptSig == partial3c);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(script_standard_push)
|
||||
|
||||
@@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE(GetTxSigOpCost)
|
||||
CScript scriptPubKey = GetScriptForDestination(CScriptID(redeemScript));
|
||||
CScript scriptSig = CScript() << OP_0 << OP_0 << ToByteVector(redeemScript);
|
||||
|
||||
BuildTxs(spendingTx, coins, creationTx, scriptPubKey, scriptSig));
|
||||
BuildTxs(spendingTx, coins, creationTx, scriptPubKey, scriptSig);
|
||||
assert(GetTransactionSigOpCount(CTransaction(spendingTx), coins, flags) == 2);
|
||||
assert(VerifyWithFlag(creationTx, spendingTx, flags) == SCRIPT_ERR_CHECKMULTISIGVERIFY);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2011-2015 The Bitcoin Core developers
|
||||
// Copyright (c) 2011-2016 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "test/test_bitcoin.h"
|
||||
|
||||
#include "clientversion.h"
|
||||
#include "checkqueue.h"
|
||||
#include "consensus/validation.h"
|
||||
#include "core_io.h"
|
||||
#include "key.h"
|
||||
@@ -14,7 +15,9 @@
|
||||
#include "main.h" // For CheckTransaction
|
||||
#include "policy/policy.h"
|
||||
#include "script/script.h"
|
||||
#include "script/sign.h"
|
||||
#include "script/script_error.h"
|
||||
#include "script/standard.h"
|
||||
#include "utilstrencodings.h"
|
||||
|
||||
#include <map>
|
||||
@@ -30,6 +33,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef vector<unsigned char> valtype;
|
||||
|
||||
// In script_tests.cpp
|
||||
extern UniValue read_json(const std::string& jsondata);
|
||||
|
||||
@@ -110,6 +115,7 @@ BOOST_AUTO_TEST_CASE(tx_valid)
|
||||
}
|
||||
|
||||
map<COutPoint, CScript> mapprevOutScriptPubKeys;
|
||||
map<COutPoint, int64_t> mapprevOutValues;
|
||||
UniValue inputs = test[0].get_array();
|
||||
bool fValid = true;
|
||||
for (unsigned int inpIdx = 0; inpIdx < inputs.size(); inpIdx++) {
|
||||
@@ -120,13 +126,17 @@ BOOST_AUTO_TEST_CASE(tx_valid)
|
||||
break;
|
||||
}
|
||||
UniValue vinput = input.get_array();
|
||||
if (vinput.size() != 3)
|
||||
if (vinput.size() < 3 || vinput.size() > 4)
|
||||
{
|
||||
fValid = false;
|
||||
break;
|
||||
}
|
||||
|
||||
mapprevOutScriptPubKeys[COutPoint(uint256S(vinput[0].get_str()), vinput[1].get_int())] = ParseScript(vinput[2].get_str());
|
||||
COutPoint outpoint(uint256S(vinput[0].get_str()), vinput[1].get_int());
|
||||
mapprevOutScriptPubKeys[outpoint] = ParseScript(vinput[2].get_str());
|
||||
if (vinput.size() >= 4)
|
||||
{
|
||||
mapprevOutValues[outpoint] = vinput[3].get_int64();
|
||||
}
|
||||
}
|
||||
if (!fValid)
|
||||
{
|
||||
@@ -153,6 +163,9 @@ BOOST_AUTO_TEST_CASE(tx_valid)
|
||||
}
|
||||
|
||||
CAmount amount = 0;
|
||||
if (mapprevOutValues.count(tx.vin[i].prevout)) {
|
||||
amount = mapprevOutValues[tx.vin[i].prevout];
|
||||
}
|
||||
unsigned int verify_flags = ParseScriptFlags(test[2].get_str());
|
||||
BOOST_CHECK_MESSAGE(VerifyScript(tx.vin[i].scriptSig, mapprevOutScriptPubKeys[tx.vin[i].prevout],
|
||||
verify_flags, TransactionSignatureChecker(&tx, i, amount, txdata), &err),
|
||||
@@ -187,6 +200,7 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
|
||||
}
|
||||
|
||||
map<COutPoint, CScript> mapprevOutScriptPubKeys;
|
||||
map<COutPoint, int64_t> mapprevOutValues;
|
||||
UniValue inputs = test[0].get_array();
|
||||
bool fValid = true;
|
||||
for (unsigned int inpIdx = 0; inpIdx < inputs.size(); inpIdx++) {
|
||||
@@ -197,13 +211,17 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
|
||||
break;
|
||||
}
|
||||
UniValue vinput = input.get_array();
|
||||
if (vinput.size() != 3)
|
||||
if (vinput.size() < 3 || vinput.size() > 4)
|
||||
{
|
||||
fValid = false;
|
||||
break;
|
||||
}
|
||||
|
||||
mapprevOutScriptPubKeys[COutPoint(uint256S(vinput[0].get_str()), vinput[1].get_int())] = ParseScript(vinput[2].get_str());
|
||||
COutPoint outpoint(uint256S(vinput[0].get_str()), vinput[1].get_int());
|
||||
mapprevOutScriptPubKeys[outpoint] = ParseScript(vinput[2].get_str());
|
||||
if (vinput.size() >= 4)
|
||||
{
|
||||
mapprevOutValues[outpoint] = vinput[3].get_int64();
|
||||
}
|
||||
}
|
||||
if (!fValid)
|
||||
{
|
||||
@@ -230,6 +248,9 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
|
||||
|
||||
unsigned int verify_flags = ParseScriptFlags(test[2].get_str());
|
||||
CAmount amount = 0;
|
||||
if (mapprevOutValues.count(tx.vin[i].prevout)) {
|
||||
amount = mapprevOutValues[tx.vin[i].prevout];
|
||||
}
|
||||
fValid = VerifyScript(tx.vin[i].scriptSig, mapprevOutScriptPubKeys[tx.vin[i].prevout],
|
||||
verify_flags, TransactionSignatureChecker(&tx, i, amount, txdata), &err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user