Hush Full Node software. We were censored from Github, this is where all development happens now. https://hush.is
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

423 lines
27 KiB

// Copyright (c) 2011-2014 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "arith_uint256.h"
#include "consensus/validation.h"
#include "main.h"
#include "miner.h"
#include "pubkey.h"
#include "uint256.h"
#include "util.h"
#include "crypto/equihash.h"
#include "test/test_bitcoin.h"
#include <boost/test/unit_test.hpp>
BOOST_FIXTURE_TEST_SUITE(miner_tests, TestingSetup)
#define NUM_EQUIHASH_SOLUTIONS 8 // k = 3
static
struct {
const char *nonce_hex;
uint32_t vSolutions[NUM_EQUIHASH_SOLUTIONS];
} blockinfo[] = {
{"0000000000000000000000000000000000000000000000000000000000000000", {97743,30132657,484063,549799,19348864,23335066,22922656,25212984,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3704844,19676691,5558781,19454332,6669915,23401490,14677063,19400208,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1163066,10418279,18213323,33214736,22651636,27284477,27568170,31886880,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {9437140,11715184,19371050,28966349,16609248,24809554,21156339,24329400,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {2060808,14976084,3929233,8635606,2129994,29321978,18009732,20899603,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {6553151,27547222,14374815,26966781,11572967,18515299,13425522,25942859,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {3830400,31681697,8210152,12108799,6539013,7272751,8002435,18353246,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {2347532,11316683,3657242,6346602,7767083,9711208,14774567,20327455,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {375375,10923448,2690587,4355326,5387974,26027068,8838706,26025107,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3085258,31739796,20142350,24205810,20852611,26722451,30903228,32829827,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {5395844,27138460,14773502,17738417,7702401,20224724,27335595,27369205,}},
{"0000000000000000000000000000000000000000000000000000000000000004", {1902919,22420687,11555907,26533901,7140909,9533324,23456860,29031946,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {6847902,22822141,22499684,28459893,8721831,21654167,15186174,27048912,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1590139,14875756,11673960,20903589,7199901,14497011,8704820,27430995,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1124558,8305774,17764744,27873733,5387634,6987439,6986181,21127745,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3197745,5825725,17977936,19348879,5874615,15887691,15017865,31597246,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {10469647,26060158,15880265,25775850,11043315,30083864,13122460,19138629,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {11010883,27697707,26476073,29000438,17504202,19922171,29822139,33063857,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3404296,23492192,8817274,29619278,8418789,14105467,17418978,30576012,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1508731,11137601,2115128,16969615,2067207,23465770,7575884,9882258,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {177353,8924531,9983009,10616028,3772765,7424649,5422939,20970804,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {320212,7857131,18308879,25253336,6561829,8589182,8966024,10570267,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {181083,31789696,24507346,26209656,7718065,22999323,10743327,31353280,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {465807,9228966,3083171,7969599,4928825,26972710,15817909,31729384,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3676,2909041,5948826,11593877,10433824,33508618,11427438,31524008,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1640081,28434654,26510595,29673164,7842550,19055553,9833590,13400268,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {1061609,15612480,7681662,30991237,19882132,29284639,25169376,30303278,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {99804,33190805,8421265,22831818,15597760,29765176,18462058,27399781,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {393632,8223856,18154872,31857036,6466434,10898122,8092016,23510083,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1168321,22320269,20146313,31053384,2136680,16384955,5347965,16673756,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {6572873,29527411,6961349,22187080,13188505,15731402,26508098,30432587,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4924166,6980487,19176475,20298240,8648353,28273621,8799191,18322308,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {2842168,18835810,9111204,13670859,5206568,26351703,10247067,14161373,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1140,7428267,18165632,32442656,11324427,28921953,20742626,22277053,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {2377188,19710714,10547871,32643708,10404302,18785688,13079055,18715471,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {856180,18364822,7089832,29888479,10722910,18669870,22122535,32894082,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {3907433,24897047,4534936,7797466,10715155,22967816,11132191,16463669,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1158847,10985791,1984321,24625094,2275980,10061803,14987747,29048783,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1313124,27847846,19551178,32271024,15895849,28869054,17547180,26443544,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1662315,12524026,6888640,27496996,7333655,15233456,12309604,25012207,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1788805,5825783,9425477,31593658,11444111,32242541,23080214,25810332,}},
{"0000000000000000000000000000000000000000000000000000000000000003", {2538508,32602057,16694134,18822406,6729083,25625751,17569380,33186084,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {178290,20453209,5144992,10328787,6345446,26439712,14656409,15726547,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {999921,16132813,3186087,11047015,3534048,4930850,7305627,21301240,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2548772,3363393,21706776,31686311,14614075,27114655,22343013,32107261,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {740515,26901858,12687793,31790705,1690282,7959602,3805504,25476964,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {912272,19107394,2828728,28392925,1676293,3269042,5935967,16052535,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1879164,14761835,20935337,27097296,23971052,26699336,25380084,26237031,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {428872,30650130,7842851,18041619,810070,9893203,23497766,24044141,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3041035,11729659,4346845,24654869,8299008,19199980,12708456,13113057,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {279352,22425147,6920303,12396944,7181346,22615426,7234243,31260044,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2642203,26353464,6990714,20461271,3859654,26044145,7003288,10950283,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {69721,2003244,3433727,16788763,11137223,22692583,25917212,28264898,}},
{"0000000000000000000000000000000000000000000000000000000000000003", {827361,14757187,12173872,32927653,4834580,16014323,28522559,32720842,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {943082,26125428,7063890,12689201,19366814,29929114,20021732,23723681,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2345325,11820207,4536851,32283539,6108863,8350508,14558654,27427717,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {379670,20128453,18366504,22664728,2539170,11976200,14142317,21628231,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2224626,12595113,13278637,22210479,5804387,10218802,25593718,32524722,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1258057,22452082,23017388,26124428,7859519,13551906,17990962,21957359,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {9072862,18661859,17472368,21283456,16167224,24215261,22615447,28419440,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {324128,23482316,6387287,18783001,1027618,18277617,23304693,32909066,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {726841,22091586,4707954,9012045,18174370,26925115,19667216,28271947,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {6483973,11911695,30612326,32606885,13729745,20313064,27823097,33023741,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {271633,25251940,1551390,14796372,9225743,32098496,13649799,25998208,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4077520,22355925,9637752,30500696,15798234,32393429,19650327,25852691,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {628461,19694351,16549678,24252512,18473404,28936053,18732469,19101118,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {5074185,16255586,33416220,33476906,6397497,9343800,18135165,25731401,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2617008,3320422,10084397,24518906,3158345,29451440,13200984,27878786,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1912945,9445790,16354788,31126073,5743413,10976421,16228101,22853225,}},
{"0000000000000000000000000000000000000000000000000000000000000003", {4432996,15508567,14297344,33399602,18160067,20997003,25843025,33480466,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {445614,609785,29644824,31224472,1839565,21164124,6783649,10669305,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {584483,20375592,9768355,22723677,6409108,19606833,10334066,20651287,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1516393,2834213,15969993,28842985,2791251,5698434,30633491,33418737,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4169681,7798686,24930841,26067909,6436856,10356829,18755059,20202877,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {597623,30693250,13226060,26024715,6136533,33518750,17855976,19074153,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {787970,14793171,8299648,31091678,1655550,22351161,12333408,14598544,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1111500,14103714,5246332,25430530,5521024,17003503,10668446,22070268,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {6057501,22294380,8135795,33259648,6998249,8031836,22346743,22903931,}},
{"0000000000000000000000000000000000000000000000000000000000000003", {896965,12013733,15857331,26117022,5023142,6107703,17790821,27388113,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {15073914,26886328,18131701,18591331,16607610,26669160,18609534,22370025,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {630127,4805826,1058189,13200575,6187595,6465800,20904724,30542083,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3081952,30329585,8807240,32684619,11381758,23263447,19399856,33082704,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2142018,21724119,7811869,24398105,3966578,28142144,14104322,29508481,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {2874547,30802580,15892355,22003984,9346208,18178692,14076304,20733888,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {779844,18706159,28895671,31803912,10184018,28298709,20777057,27940184,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {10859544,32356399,25045820,29204699,12535111,29771035,17779397,20293821,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2236797,24188729,26471954,31067490,20790752,25499712,27964953,30534637,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {2569923,33091378,14013336,31245271,3494782,29723492,13410015,22620131,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {9760213,26449094,24273305,32591923,18561773,32580017,31879094,33248534,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {94257,5369755,19980716,32932183,8406229,20368558,17504990,20181390,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {510146,7533784,1891615,13054235,6705711,20187878,27010433,32053536,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {2166293,20065304,14414805,21032397,4133862,23019683,6531714,7126905,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1041778,4456065,5358631,13763143,7577200,26665229,24068796,28800398,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {937582,26826308,28058792,28694768,5189727,19372397,15614322,16105488,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4521500,6966737,6323323,13862143,11485955,12307184,11629729,26024368,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {9040844,21264220,14276904,24928489,19506656,30369558,27472157,27786434,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1614072,27004142,14105308,32866905,5852759,27596517,26864322,30651762,}},
{"0000000000000000000000000000000000000000000000000000000000000003", {6202568,10379593,16337809,31904445,7415075,15097878,17352682,23565977,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {10572238,22741016,11410795,26024250,12178838,26399921,18113727,27056540,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {17757,2573951,8211950,24719701,2117286,11676185,6515678,25435925,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1574654,20492089,10353675,29134399,10903399,17528416,17768662,26623799,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2696594,32385619,9085580,18428083,13894117,32532539,16764630,30477048,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {566464,19542928,11742509,23529539,16553277,32987568,20939994,29146760,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2493469,11900665,10188594,27320996,16250998,33188477,28435414,30583363,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {5722857,30015694,24112853,28247326,21832584,28338357,26816419,32122301,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1734816,3552535,9674546,27191644,3451938,22052830,10479347,18547655,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {3087729,17246853,12037147,16883103,6833770,31054683,12987022,15748037,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {8229812,16931970,30132685,30164944,9206203,31075410,19923587,33312205,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2481700,27601048,4684063,18020803,16501451,17797310,23596122,33335733,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3778911,19607199,16603727,20456918,7209095,31778215,9795558,18557070,}},
};
// NOTE: These tests rely on CreateNewBlock doing its own self-validation!
BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
{
CScript scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
CBlockTemplate *pblocktemplate;
CMutableTransaction tx,tx2;
CScript script;
uint256 hash;
LOCK(cs_main);
fCheckpointsEnabled = false;
// We can't make transactions until we have inputs
// Therefore, load 100 blocks :)
std::vector<CTransaction*>txFirst;
for (unsigned int i = 0; i < sizeof(blockinfo)/sizeof(*blockinfo); ++i)
{
// Simple block creation, nothing special yet:
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
CBlock *pblock = &pblocktemplate->block; // pointer for convenience
pblock->nVersion = 1;
pblock->nTime = chainActive.Tip()->GetMedianTimePast()+1;
CMutableTransaction txCoinbase(pblock->vtx[0]);
txCoinbase.vin[0].scriptSig = CScript();
txCoinbase.vin[0].scriptSig.push_back((unsigned char) 0);
txCoinbase.vin[0].scriptSig.push_back(chainActive.Height());
txCoinbase.vout[0].scriptPubKey = CScript();
pblock->vtx[0] = CTransaction(txCoinbase);
if (txFirst.size() < 2)
txFirst.push_back(new CTransaction(pblock->vtx[0]));
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
pblock->nNonce = uint256S(blockinfo[i].nonce_hex);
pblock->nSolution = std::vector<uint32_t>(blockinfo[i].vSolutions,
blockinfo[i].vSolutions + NUM_EQUIHASH_SOLUTIONS);
/*
{
arith_uint256 try_nonce(0);
unsigned int n = 96;
unsigned int k = 3;
// Hash state
crypto_generichash_blake2b_state eh_state;
EhInitialiseState(n, k, eh_state);
// I = the block header minus nonce and solution.
CEquihashInput I{*pblock};
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << I;
// H(I||...
crypto_generichash_blake2b_update(&eh_state, (unsigned char*)&ss[0], ss.size());
while (true) {
pblock->nNonce = ArithToUint256(try_nonce);
// H(I||V||...
crypto_generichash_blake2b_state curr_state;
curr_state = eh_state;
crypto_generichash_blake2b_update(&curr_state,
pblock->nNonce.begin(),
pblock->nNonce.size());
// (x_1, x_2, ...) = A(I, V, n, k)
std::set<std::vector<unsigned int>> solns;
EhOptimisedSolve(n, k, curr_state, solns);
bool ret;
for (auto soln : solns) {
EhIsValidSolution(n, k, curr_state, soln, ret);
assert(ret);
pblock->nSolution = soln;
CValidationState state;
if (ProcessNewBlock(state, NULL, pblock, true, NULL) && state.IsValid()) {
goto foundit;
}
//std::cout << state.GetRejectReason() << std::endl;
}
try_nonce += 1;
}
foundit:
std::cout << " {\"" << pblock->nNonce.GetHex() << "\", {";
BOOST_FOREACH(auto num, pblock->nSolution) {
std::cout << num << ",";
}
std::cout << "}}," << std::endl;
}
*/
CValidationState state;
BOOST_CHECK(ProcessNewBlock(state, NULL, pblock, true, NULL));
BOOST_CHECK_MESSAGE(state.IsValid(), state.GetRejectReason());
pblock->hashPrevBlock = pblock->GetHash();
// Need to recreate the template each round because of mining slow start
delete pblocktemplate;
}
// Just to make sure we can still make simple blocks
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
delete pblocktemplate;
// block sigops > limit: 1000 CHECKMULTISIG + 1
tx.vin.resize(1);
// NOTE: OP_NOP is used to force 20 SigOps for the CHECKMULTISIG
tx.vin[0].scriptSig = CScript() << OP_0 << OP_0 << OP_0 << OP_NOP << OP_CHECKMULTISIG << OP_1;
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
tx.vin[0].prevout.n = 0;
tx.vout.resize(1);
tx.vout[0].nValue = 50000LL;
for (unsigned int i = 0; i < 1001; ++i)
{
tx.vout[0].nValue -= 10;
hash = tx.GetHash();
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
tx.vin[0].prevout.hash = hash;
}
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
delete pblocktemplate;
mempool.clear();
// block size > limit
tx.vin[0].scriptSig = CScript();
// 18 * (520char + DROP) + OP_1 = 9433 bytes
std::vector<unsigned char> vchData(520);
for (unsigned int i = 0; i < 18; ++i)
tx.vin[0].scriptSig << vchData << OP_DROP;
tx.vin[0].scriptSig << OP_1;
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
tx.vout[0].nValue = 50000LL;
for (unsigned int i = 0; i < 128; ++i)
{
tx.vout[0].nValue -= 350;
hash = tx.GetHash();
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
tx.vin[0].prevout.hash = hash;
}
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
delete pblocktemplate;
mempool.clear();
// orphan in mempool
hash = tx.GetHash();
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
delete pblocktemplate;
mempool.clear();
// child with higher priority than parent
tx.vin[0].scriptSig = CScript() << OP_1;
tx.vin[0].prevout.hash = txFirst[1]->GetHash();
tx.vout[0].nValue = 39000LL;
hash = tx.GetHash();
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
tx.vin[0].prevout.hash = hash;
tx.vin.resize(2);
tx.vin[1].scriptSig = CScript() << OP_1;
tx.vin[1].prevout.hash = txFirst[0]->GetHash();
tx.vin[1].prevout.n = 0;
tx.vout[0].nValue = 49000LL;
hash = tx.GetHash();
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
delete pblocktemplate;
mempool.clear();
// coinbase in mempool
tx.vin.resize(1);
tx.vin[0].prevout.SetNull();
tx.vin[0].scriptSig = CScript() << OP_0 << OP_1;
tx.vout[0].nValue = 0;
hash = tx.GetHash();
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
delete pblocktemplate;
mempool.clear();
// invalid (pre-p2sh) txn in mempool
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
tx.vin[0].prevout.n = 0;
tx.vin[0].scriptSig = CScript() << OP_1;
tx.vout[0].nValue = 49000LL;
script = CScript() << OP_0;
tx.vout[0].scriptPubKey = GetScriptForDestination(CScriptID(script));
hash = tx.GetHash();
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
tx.vin[0].prevout.hash = hash;
tx.vin[0].scriptSig = CScript() << (std::vector<unsigned char>)script;
tx.vout[0].nValue -= 10000;
hash = tx.GetHash();
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
delete pblocktemplate;
mempool.clear();
// double spend txn pair in mempool
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
tx.vin[0].scriptSig = CScript() << OP_1;
tx.vout[0].nValue = 49000LL;
tx.vout[0].scriptPubKey = CScript() << OP_1;
hash = tx.GetHash();
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
tx.vout[0].scriptPubKey = CScript() << OP_2;
hash = tx.GetHash();
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
delete pblocktemplate;
mempool.clear();
// subsidy changing
int nHeight = chainActive.Height();
chainActive.Tip()->nHeight = 209999;
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
delete pblocktemplate;
chainActive.Tip()->nHeight = 210000;
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
delete pblocktemplate;
chainActive.Tip()->nHeight = nHeight;
// non-final txs in mempool
SetMockTime(chainActive.Tip()->GetMedianTimePast()+1);
// height locked
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
tx.vin[0].scriptSig = CScript() << OP_1;
tx.vin[0].nSequence = 0;
tx.vout[0].nValue = 49000LL;
tx.vout[0].scriptPubKey = CScript() << OP_1;
tx.nLockTime = chainActive.Tip()->nHeight+1;
hash = tx.GetHash();
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
BOOST_CHECK(!CheckFinalTx(tx, LOCKTIME_MEDIAN_TIME_PAST));
// time locked
tx2.vin.resize(1);
tx2.vin[0].prevout.hash = txFirst[1]->GetHash();
tx2.vin[0].prevout.n = 0;
tx2.vin[0].scriptSig = CScript() << OP_1;
tx2.vin[0].nSequence = 0;
tx2.vout.resize(1);
tx2.vout[0].nValue = 79000LL;
tx2.vout[0].scriptPubKey = CScript() << OP_1;
tx2.nLockTime = chainActive.Tip()->GetMedianTimePast()+1;
hash = tx2.GetHash();
mempool.addUnchecked(hash, CTxMemPoolEntry(tx2, 11, GetTime(), 111.0, 11));
BOOST_CHECK(!CheckFinalTx(tx2, LOCKTIME_MEDIAN_TIME_PAST));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
// Neither tx should have make it into the template.
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 1);
delete pblocktemplate;
// However if we advance height and time by one, both will.
chainActive.Tip()->nHeight++;
SetMockTime(chainActive.Tip()->GetMedianTimePast()+2);
// FIXME: we should *actually* create a new block so the following test
// works; CheckFinalTx() isn't fooled by monkey-patching nHeight.
//BOOST_CHECK(CheckFinalTx(tx));
//BOOST_CHECK(CheckFinalTx(tx2));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 2);
delete pblocktemplate;
chainActive.Tip()->nHeight--;
SetMockTime(0);
mempool.clear();
BOOST_FOREACH(CTransaction *tx, txFirst)
delete tx;
fCheckpointsEnabled = true;
}
BOOST_AUTO_TEST_SUITE_END()