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", {1505683,9304455,10114563,22791213,4035556,9345213,16397229,25618807,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {424096,20333317,10622499,20209226,6884666,27470139,23474454,30531201,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2179663,27008838,7162220,11963499,5092907,18014816,28361015,31223796,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {303751,21454192,8761201,12598180,4577837,29015619,20421055,22955596,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1751790,19856152,8574507,16953069,4251312,13393763,5955453,28913023,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {785184,14253319,24484102,27390835,1317570,12730552,16069105,29576909,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1718219,27413934,2674938,15453490,13954323,25472379,16189626,19128343,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {629365,1981622,1749373,24877483,8217463,18016882,14658154,27211901,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1688422,3318138,17890535,32625825,12604028,31950324,14297499,19466358,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {6533168,12680284,12068506,12751411,12567359,27540043,12768573,16069354,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {968090,8442388,1117421,7976193,14006881,31798833,18085134,20401083,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3514701,12360162,5234778,5999621,11789340,18832893,22869850,23439344,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2575979,27830265,13819669,22742927,3121997,13349293,6263893,15290297,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {5062267,7659171,14486124,23330332,11966804,24824323,14038938,18878817,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {11213446,20265755,12893621,23017856,16734884,31765345,21333472,23827684,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {5518261,30764760,12823014,13655635,7134888,32813890,11382973,17173863,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {664025,15589977,1951845,15881472,1451881,20455835,14830157,31859267,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1381023,8353598,5447556,7981905,3286916,28307849,12223998,24222776,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2270156,9693893,7097804,33155995,5209943,24608558,23175278,23996312,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {598743,7549066,12220120,16548000,1187946,6360178,9203030,20938470,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {7169872,31048822,17475729,28022573,14929725,33419266,19983803,21561441,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {823149,1383285,2864831,18895121,4028941,6686607,23910447,28604567,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2182559,17932563,5472524,13379261,8567276,32616974,13001732,29914746,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {8611685,24932345,31206257,33073835,19148378,25317035,19310180,22845583,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {83068,29700240,3972272,6850295,9153017,29691329,22889643,28586890,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {2036436,33222933,10430117,26029089,14468206,23205454,16914535,23655899,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {54367,28431614,4046008,18177082,6036369,11490568,10955988,30899748,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2546890,18985534,25329149,33071236,4813628,14855283,9753607,18836650,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {10805583,19004556,28249173,32689480,11182279,15314398,16390145,19761642,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {165667,26786566,1226777,1745893,3573753,20991068,16300414,25762822,}},
{"0000000000000000000000000000000000000000000000000000000000000003", {62918,4072570,4440776,26738888,3934004,19477034,20612480,32574298,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1719533,12082749,11189320,14802151,1932592,6082360,3182419,15839619,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {3264146,31555777,9558781,24052145,3492269,12679179,20287639,24428614,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {9620201,29437274,12503846,23031898,12057554,20334741,13655193,19216975,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {7885417,28251852,18863119,30898457,15346252,26882297,18476594,21100099,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {240010,13062691,13209296,15801269,5482499,6697795,20389947,30871777,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1069937,5009862,20476681,21883864,3816975,18168447,12966753,27204663,}},
{"0000000000000000000000000000000000000000000000000000000000000003", {4720504,28475581,30132313,32996687,15421528,33006056,19410498,32808177,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {3375419,19887018,3583901,18414401,4072420,5558293,9497494,22664087,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2812898,30205959,7980517,16869166,10455874,11175055,28088879,29386025,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {91377,8095055,15028975,21569250,7121267,23141695,10638134,22152880,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {5320074,19134224,5908808,20417182,9802516,29176362,11327661,27117599,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2304141,20069153,19299006,32940065,4897139,26940432,31702454,32395918,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2183041,9634135,32043677,33261946,18256807,30835923,19504088,20654921,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {7646265,16434464,9910305,18212419,12149694,22678629,32034346,32963185,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {924537,5073683,1803756,28393103,21164203,30767320,21433406,22064835,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2606837,19557323,21550527,21601365,6848017,22514207,25667860,30755108,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {131529,17520841,8190594,12399429,1736902,29945839,25566017,31113393,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {74277,30398806,5823084,26201084,4363661,31286936,8937184,25310621,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {5629775,21833920,16203890,25997616,6778531,10871927,26779945,32073815,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {7360230,29863781,8172797,25440735,9306446,31827129,10966698,20794387,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1020818,19742792,2996289,3324122,4671579,8811651,9334761,25096551,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {6257905,25988186,21198798,27940315,11405239,18843426,13218595,16970291,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3661427,29865559,4313400,13731482,5384386,9968554,13573546,18976286,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {297493,14307372,3086420,11769568,1531156,33417896,16891836,26835748,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {850439,939868,16088315,17847062,1459858,18852207,21613990,31341287,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1498173,5659035,3580647,9784724,7042945,27605458,13983089,21772555,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {265300,25657381,5837906,32684326,6197029,26496479,11782433,28354118,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4235902,8416342,16760709,18644724,9088314,21041118,16132732,19921969,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {7054865,20285428,13191729,31228813,7505236,24662594,21292235,27185614,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {805354,2124453,6739370,31189471,19047536,20922898,19270405,25919260,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1250066,15110709,6902216,30436877,17319807,22578956,25091517,30273798,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {5860838,12990745,6387378,25809956,16172365,27030579,20735436,22490295,}},
{"0000000000000000000000000000000000000000000000000000000000000003", {2907633,29738850,19732451,33309735,11787163,13756425,15433747,25267074,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {5804619,14577145,23001890,25863602,15458582,17688201,21112935,29728563,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1688425,18136649,4537229,13269806,3269606,8593962,12360926,33488147,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1665070,25244052,10550119,32208768,5137014,8320231,16775388,27839194,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {8311110,18046143,12839548,22041548,13420948,13944339,18677700,30812557,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4390682,27036744,19696521,24884392,4681756,23237938,25816582,32996775,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1477153,6568369,21857553,29435914,6140396,22576862,7262979,19002076,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {2965409,8684457,14803533,17967084,5354409,24881786,11719903,14361443,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {5102862,17625845,28100560,28357633,17222636,18254369,18018129,30189744,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {5708850,27621214,13753873,29665262,12657384,30563632,17310655,27915369,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {2621572,12689538,4630982,29901889,3629010,6756957,3677965,30610562,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {6500643,24447105,7448249,19069836,7887394,13551853,20649165,28423060,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {2036368,6750468,15795769,15825950,19238166,20733230,26877439,27642252,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1652218,13634797,12191514,32332965,6697455,11150626,14892178,19111832,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {111950,30863388,8779039,26464089,10089865,12353207,11894521,14091302,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {3078281,23872429,20954798,21282269,4882746,21043227,7172181,33550236,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3503224,25625938,18816585,29803345,3951932,12591146,6670269,15890043,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {605872,33319409,1817073,12822625,20032228,27403095,23666911,27183623,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1766741,14384326,5278687,22979584,2203181,32152823,3183017,10965482,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {3169640,23411466,3176871,23877547,16430704,19991138,24227956,28550729,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {233750,13283920,15875314,27705359,6749492,16980557,13229511,13859447,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1077756,26076907,2621177,14078132,4915880,8647511,29725443,32637495,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1752795,25529160,13826361,21067812,6077322,28675496,24371900,30366250,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1546413,6490653,19447435,27055625,9234404,9968283,20817365,28434279,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2468906,31932096,3450912,22420554,6120742,15406354,30836680,32518512,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2123031,24896642,7125942,24921615,12317438,24914782,14264318,32418155,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {3353184,6915242,5315514,15444924,6518261,16708409,24086722,25093861,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {857291,31955694,8619476,13282852,5131527,18688880,19863466,19950736,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1739656,25530805,3754388,6793402,15290893,29035753,29565345,30305622,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {2611937,27825146,10822599,15545335,5617357,29278495,15877832,17901616,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3831314,7379114,18116475,23520810,14414038,21954620,18383396,27660414,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {7130501,27003497,14460801,23267542,9842198,21710006,20485258,25867107,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2508815,15933718,29539325,32090536,4829668,10149214,26025842,27744647,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {279100,29887493,785496,18973521,2321564,14770369,20866351,31894781,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1699206,29970967,5475930,14850478,4783802,13945615,16786338,16900692,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1744255,6901279,7349326,32108795,3573261,15043801,16532064,22293749,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1559827,5877322,1737945,18114144,3789777,18167812,18370250,31124870,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1116048,17556996,8840198,29420603,20557703,20953366,30328439,30663015,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {798196,16377273,22015317,22772453,5946638,18262318,13868482,23874803,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {257224,19262005,22082724,22118460,7866566,25856702,14611593,20556202,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1155318,18602392,18835625,19453594,15574365,25501175,26620735,29546443,}},
{"0000000000000000000000000000000000000000000000000000000000000004", {1118617,21836063,21221995,26806476,18126093,20913596,18777695,32729986,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4113293,20842387,8047389,14992088,5113685,11404673,19908238,27527216,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1907186,28213894,13785483,22598351,2314631,32975665,17852278,26847039,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1452278,11354301,1662083,19787092,1800371,12918477,22475783,23758259,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {219653,29803795,9124713,9874906,14412340,23444473,16935535,21346968,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {17292969,19730374,18717002,28865642,20109525,30112035,20906344,26953734,}},
};
// 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()