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.

421 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", {216352,1018708,14037601,29429704,2494796,27147383,6675934,20511572,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {7863867,29124064,11004490,28155225,10050349,13402943,28382859,33286112,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {169471,19337013,4335518,10566558,9120654,28984284,22081278,23569130,}},
{"0000000000000000000000000000000000000000000000000000000000000004", {2411047,9766097,5865562,11493500,6886640,24323826,24014251,24058081,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4598434,31961097,26380422,26912453,19178416,30231514,25569745,30024594,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {4744463,23721331,16702646,32948865,12895364,22674052,16757409,20149442,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {375025,13373615,21683106,25856361,10145849,32430429,18173282,29195816,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {477635,5781180,2818347,25938101,6926588,15571188,7564010,25071567,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4551723,25691901,16242780,32913914,12083033,30201015,20164037,22465471,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {16520,20518430,1144707,7742973,5839683,22595129,24007036,26016915,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2837420,33325248,3494727,6897221,6570505,18599905,17580652,30119908,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3394318,12719729,6032280,32034148,7138821,17836282,24312124,28060983,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {10904990,32860971,12667074,27679457,11026753,22450787,13725435,28015877,}},
{"0000000000000000000000000000000000000000000000000000000000000004", {1965928,32593671,11916112,33519589,4439696,5463225,8260156,14753995,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {925306,1295985,18161249,32824347,1050388,15089627,15126153,26162143,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3633579,31983898,15584539,19766186,18004057,18332900,24205383,24465867,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2356723,23976633,4552275,6385134,8493810,28633235,19298870,21378879,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1959888,22654557,6474281,31748858,20082622,26550078,20264918,29712997,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {307453,19358543,29430800,31870134,9498175,17039188,25984927,29708092,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {579973,9373426,2663866,7349169,3818387,33229858,4093608,16461562,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1620139,9122166,5774863,11680063,6050524,13301932,7941532,33366261,}},
{"0000000000000000000000000000000000000000000000000000000000000004", {519956,31587388,1651632,14676460,9920521,30259574,21192494,29159346,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {7639147,30849510,15967391,29514312,12592973,25873044,16751871,24621393,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4321511,7231584,6964789,32516491,16551292,23311962,22749791,29688020,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {6371448,21534533,10676677,18512603,7200641,8736955,9059969,22412246,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {6479146,17442330,15064799,31757229,9917575,26919893,16249039,20185364,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1898548,8102870,27331469,28266576,7601708,15005984,9970478,23179881,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {8824523,32302979,30904324,32883737,12333733,25963100,15288867,18989669,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1548541,8843756,2755641,14485937,10070222,27300259,20569030,28831372,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3933582,32923759,22684416,32681323,5983801,32151279,8763644,20634443,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {5012656,10994861,16721985,30567353,19610350,32717977,25045228,33417764,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {17258015,27707751,26673969,32480251,21175481,31123996,30480722,33028625,}},
{"0000000000000000000000000000000000000000000000000000000000000004", {5903910,8655518,19731306,23870715,15498576,21520194,15566239,31655607,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1204528,11142967,3310310,10014673,8880746,12561187,23675817,33378929,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {76104,12682060,14628085,18171436,14981455,32744303,17056582,18770149,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {2696375,4820503,8559793,21524210,13599169,29147336,28403933,30552155,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1174385,5666437,8157877,12552667,8302517,8738371,12538730,14947174,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {615337,15689090,8431406,23563079,6899168,8800496,12950570,20173266,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1953266,11536716,18339238,29081823,5136210,13720741,19552516,24200164,}},
{"0000000000000000000000000000000000000000000000000000000000000004", {249398,16908574,18360411,30321347,2390792,33342214,5345732,23209599,}},
{"0000000000000000000000000000000000000000000000000000000000000003", {337570,15096899,950807,9258726,14597770,25482699,16338583,21823483,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {439297,19958741,10707482,23185296,5505982,5512387,26746726,28747056,}},
{"0000000000000000000000000000000000000000000000000000000000000003", {382428,20378022,13423578,16438183,8831736,23287565,16349318,22761138,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {997517,13645346,2278610,33102250,9532429,19721796,21163422,28204119,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {5539635,26357897,12410847,21826029,11144620,23084561,18700879,25928799,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2158337,25994688,10504737,30160761,12116158,28319046,12235990,14189630,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1436210,31626744,15898926,20060413,3036399,17054628,6259703,9455811,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {7978656,27534531,12406026,30227378,14747144,18286885,21527525,33038333,}},
{"0000000000000000000000000000000000000000000000000000000000000003", {252422,32197010,21490073,23059780,5455184,25487537,16068719,30014680,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1162839,2194236,29066916,32347888,9164579,29704919,14776042,32786384,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {5926523,26336777,6272293,25047609,8808382,9580150,11741921,32548287,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {485965,10980467,21070152,24146560,6060474,21603491,18854703,26569070,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {5530360,15850286,8323625,24337660,12505543,32524436,24896234,29424945,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {73124,19669640,6186952,11855781,17300508,26211536,19261491,25608557,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {6507045,12369767,9034123,25118377,11405198,13455953,27424266,28503839,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3152039,15920508,18081625,25689141,10744827,32688393,11420166,27045339,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1784239,7595315,30353799,30614116,6328014,30966331,7151736,30452480,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2694538,6650304,26983645,30240551,7990737,18246058,13819126,21461656,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2733076,15474778,6251503,23420762,8640670,26180816,10178088,22017673,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {892285,1051258,1261253,29955713,3813881,25282973,16060177,22704686,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1444629,26910303,6845637,20552767,5303179,13136113,8363446,21013103,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {468002,8189424,4614596,7656344,2759493,32914589,9492978,18142254,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3149773,20501373,13670277,32300221,5578821,27968301,7902924,22937692,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {4566477,22298090,5063792,18054718,5886835,22352284,8371750,22101911,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {8806142,14126367,9902594,24861914,9883421,15488143,10909056,21467314,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {3641746,4933661,14061855,18305499,4640168,11305894,9099587,21233653,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {799647,20796158,25579956,31946189,5316587,13163048,9711550,32526709,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1617653,27387537,28302718,33467915,6866140,19438600,21030899,26326740,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {8367176,12545169,8753130,15613328,11092478,33348288,17044467,30094385,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {6129285,8031962,16253119,16310122,23466613,25508437,27298247,31637071,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {33751,8455478,6478798,15300822,827208,4668740,4275780,6329486,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2569453,10000831,13754977,24337529,7096075,15897346,12488993,25354052,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1441927,29262792,6103777,23944999,9057967,25431237,19255170,30025327,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2349913,16463865,7688257,16505662,12686274,33250102,13899111,30839779,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {375902,22372207,15774817,16851615,19041805,24064402,24981401,25058103,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2282249,26812627,15212454,30604719,6421525,23219112,16909589,17575431,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2509256,22030655,27417447,29733625,3775718,18058391,13755781,26668823,}},
{"0000000000000000000000000000000000000000000000000000000000000004", {41327,27884303,8982554,15544395,1568960,27710196,6097908,11227268,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {427709,33168785,2173145,18463592,2859857,24461152,7706421,18780110,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2402883,4658669,16394321,19995911,9740181,28122698,14738781,30007925,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {359036,15835276,5213590,21161333,5620942,27395400,7805499,20799224,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1160068,23793408,5976768,29689631,15056387,32641235,19689023,23880772,}},
{"0000000000000000000000000000000000000000000000000000000000000003", {2734848,12177394,10302727,22658732,11425715,14641710,14711261,16523355,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {451341,10100671,21021666,27991878,5195582,5618314,5692846,10679709,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2964617,15229319,4076115,19204520,3648554,32697910,20197289,27636639,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {440072,30938322,27084206,30246143,3123795,8858970,16606542,32801246,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {9053804,29580504,11412391,28577156,13177965,13558034,16467244,17597272,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {3193671,25950281,14992426,29625315,7956969,8211246,15166507,27057711,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {334505,22052844,28756749,32918800,1843853,5749604,9399097,21031785,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4993887,11626466,6241557,24278440,11502165,19940637,26408954,29869824,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2407185,3852170,9504479,21953774,10050325,18652017,13951270,24166394,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {5420408,6981585,23870568,25089965,15225571,28209783,15340447,24744678,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1220752,5013344,19880580,29007540,4727548,32095982,5112086,16690708,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {8801517,28319229,11703943,14978087,16018730,16974587,23680776,25500260,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {116915,4812536,22036751,26372345,9620689,28535061,18749446,30769373,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {9814620,21390460,13072117,20767487,16932327,25313517,22832642,28148883,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {266314,838840,10202997,19159789,1488135,23070617,13686162,28880632,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {997789,25683952,23305604,27802671,8083925,11297332,11840318,23127675,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {804277,24368209,4696656,12413559,3664586,8298028,14691095,19302385,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4959792,7181349,11955606,30560922,11411750,12886320,15847408,30714873,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {676011,25074945,23692872,29269897,7294878,26983497,14954385,21473375,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {226406,10830525,10055779,10085800,1901739,3810417,14938451,31256809,}},
{"0000000000000000000000000000000000000000000000000000000000000005", {2995662,32503013,5787679,31858788,9325074,11503306,24879764,28676965,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {8671195,15011818,9378392,11477125,16056563,16400345,17535521,21619280,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2157875,27445165,5155391,30292735,9779645,11488081,20809173,22263281,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {11306513,18468576,30532327,30569445,12343544,20534469,24909512,25840040,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {2018384,14152248,10610344,16134504,10307466,28988177,18649688,29919281,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {3214055,23884942,10169222,14881676,8001971,22015673,22681053,23535540,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {9693164,28139918,15652061,23476135,10114742,31569401,17135058,32756480,}},
{"0000000000000000000000000000000000000000000000000000000000000005", {1276832,26649952,2610435,13194365,1439903,7796192,15145485,28696054,}},
};
// 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 = 4;
pblock->nTime = chainActive.Tip()->GetMedianTimePast()+1;
CMutableTransaction txCoinbase(pblock->vtx[0]);
txCoinbase.vin[0].scriptSig = CScript() << (chainActive.Height()+1) << OP_0;
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()