18 #include <validation.h>
25 #include <boost/test/unit_test.hpp>
48 BlockAssembler::Options options;
55 constexpr
static struct {
58 }
BLOCKINFO[]{{8, 582909131}, {0, 971462344}, {2, 1169481553}, {6, 66147495}, {7, 427785981}, {8, 80538907},
59 {8, 207348013}, {2, 1951240923}, {4, 215054351}, {1, 491520534}, {8, 1282281282}, {4, 639565734},
60 {3, 248274685}, {8, 1160085976}, {6, 396349768}, {5, 393780549}, {5, 1096899528}, {4, 965381630},
61 {0, 728758712}, {5, 318638310}, {3, 164591898}, {2, 274234550}, {2, 254411237}, {7, 561761812},
62 {2, 268342573}, {0, 402816691}, {1, 221006382}, {6, 538872455}, {7, 393315655}, {4, 814555937},
63 {7, 504879194}, {6, 467769648}, {3, 925972193}, {2, 200581872}, {3, 168915404}, {8, 430446262},
64 {5, 773507406}, {3, 1195366164}, {0, 433361157}, {3, 297051771}, {0, 558856551}, {2, 501614039},
65 {3, 528488272}, {2, 473587734}, {8, 230125274}, {2, 494084400}, {4, 357314010}, {8, 60361686},
66 {7, 640624687}, {3, 480441695}, {8, 1424447925}, {4, 752745419}, {1, 288532283}, {6, 669170574},
67 {5, 1900907591}, {3, 555326037}, {3, 1121014051}, {0, 545835650}, {8, 189196651}, {5, 252371575},
68 {0, 199163095}, {6, 558895874}, {6, 1656839784}, {6, 815175452}, {6, 718677851}, {5, 544000334},
69 {0, 340113484}, {6, 850744437}, {4, 496721063}, {8, 524715182}, {6, 574361898}, {6, 1642305743},
70 {6, 355110149}, {5, 1647379658}, {8, 1103005356}, {7, 556460625}, {3, 1139533992}, {5, 304736030},
71 {2, 361539446}, {2, 143720360}, {6, 201939025}, {7, 423141476}, {4, 574633709}, {3, 1412254823},
72 {4, 873254135}, {0, 341817335}, {6, 53501687}, {3, 179755410}, {5, 172209688}, {8, 516810279},
73 {4, 1228391489}, {8, 325372589}, {6, 550367589}, {0, 876291812}, {7, 412454120}, {7, 717202854},
74 {2, 222677843}, {6, 251778867}, {7, 842004420}, {7, 194762829}, {4, 96668841}, {1, 925485796},
75 {0, 792342903}, {6, 678455063}, {6, 773251385}, {5, 186617471}, {6, 883189502}, {7, 396077336},
76 {8, 254702874}, {0, 455592851}};
82 index.
pprev = active_chain_tip;
89 void MinerTestingSetup::TestPackageSelection(
const CChainParams& chainparams,
const CScript& scriptPubKey,
const std::vector<CTransactionRef>& txFirst)
99 tx.
vin[0].prevout.hash = txFirst[0]->GetHash();
100 tx.
vin[0].prevout.n = 0;
102 tx.
vout[0].nValue = 5000000000LL - 1000;
108 tx.
vin[0].prevout.hash = txFirst[1]->GetHash();
109 tx.
vout[0].nValue = 5000000000LL - 10000;
114 tx.
vin[0].prevout.hash = hashParentTx;
115 tx.
vout[0].nValue = 5000000000LL - 1000 - 50000;
119 std::unique_ptr<CBlockTemplate> pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
120 BOOST_REQUIRE_EQUAL(pblocktemplate->block.vtx.size(), 4U);
121 BOOST_CHECK(pblocktemplate->block.vtx[1]->GetHash() == hashParentTx);
122 BOOST_CHECK(pblocktemplate->block.vtx[2]->GetHash() == hashHighFeeTx);
123 BOOST_CHECK(pblocktemplate->block.vtx[3]->GetHash() == hashMediumFeeTx);
126 tx.
vin[0].prevout.hash = hashHighFeeTx;
127 tx.
vout[0].nValue = 5000000000LL - 1000 - 50000;
136 tx.
vin[0].prevout.hash = hashFreeTx;
137 tx.
vout[0].nValue = 5000000000LL - 1000 - 50000 - feeToUse;
140 pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
142 for (
size_t i=0; i<pblocktemplate->block.vtx.size(); ++i) {
143 BOOST_CHECK(pblocktemplate->block.vtx[i]->GetHash() != hashFreeTx);
144 BOOST_CHECK(pblocktemplate->block.vtx[i]->GetHash() != hashLowFeeTx);
151 tx.
vout[0].nValue -= 2;
154 pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
155 BOOST_REQUIRE_EQUAL(pblocktemplate->block.vtx.size(), 6U);
156 BOOST_CHECK(pblocktemplate->block.vtx[4]->GetHash() == hashFreeTx);
157 BOOST_CHECK(pblocktemplate->block.vtx[5]->GetHash() == hashLowFeeTx);
162 tx.
vin[0].prevout.hash = txFirst[2]->GetHash();
164 tx.
vout[0].nValue = 5000000000LL - 100000000;
165 tx.
vout[1].nValue = 100000000;
170 tx.
vin[0].prevout.hash = hashFreeTx2;
173 tx.
vout[0].nValue = 5000000000LL - 100000000 - feeToUse;
176 pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
179 for (
size_t i=0; i<pblocktemplate->block.vtx.size(); ++i) {
180 BOOST_CHECK(pblocktemplate->block.vtx[i]->GetHash() != hashFreeTx2);
181 BOOST_CHECK(pblocktemplate->block.vtx[i]->GetHash() != hashLowFeeTx2);
186 tx.
vin[0].prevout.n = 1;
187 tx.
vout[0].nValue = 100000000 - 10000;
189 pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
190 BOOST_REQUIRE_EQUAL(pblocktemplate->block.vtx.size(), 9U);
191 BOOST_CHECK(pblocktemplate->block.vtx[8]->GetHash() == hashLowFeeTx2);
200 CScript scriptPubKey =
CScript() <<
ParseHex(
"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") <<
OP_CHECKSIG;
201 std::unique_ptr<CBlockTemplate> pblocktemplate;
212 BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
216 static_assert(std::size(
BLOCKINFO) == 110,
"Should have 110 blocks to import");
218 std::vector<CTransactionRef> txFirst;
220 CBlock *pblock = &pblocktemplate->block;
228 txCoinbase.
vout.resize(1);
231 if (txFirst.size() == 0)
233 if (txFirst.size() < 4)
234 txFirst.push_back(pblock->
vtx[0]);
236 pblock->
nNonce = bi.nonce;
238 std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(*pblock);
247 BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
258 tx.
vin[0].prevout.hash = txFirst[0]->GetHash();
259 tx.
vin[0].prevout.n = 0;
261 tx.
vout[0].nValue = BLOCKSUBSIDY;
262 for (
unsigned int i = 0; i < 1001; ++i)
264 tx.
vout[0].nValue -= LOWFEE;
269 tx.
vin[0].prevout.hash = hash;
272 BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error,
HasReason(
"bad-blk-sigops"));
275 tx.
vin[0].prevout.hash = txFirst[0]->GetHash();
276 tx.
vout[0].nValue = BLOCKSUBSIDY;
277 for (
unsigned int i = 0; i < 1001; ++i)
279 tx.
vout[0].nValue -= LOWFEE;
284 tx.
vin[0].prevout.hash = hash;
286 BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
292 std::vector<unsigned char> vchData(520);
293 for (
unsigned int i = 0; i < 18; ++i)
296 tx.
vin[0].prevout.hash = txFirst[0]->GetHash();
297 tx.
vout[0].nValue = BLOCKSUBSIDY;
298 for (
unsigned int i = 0; i < 128; ++i)
300 tx.
vout[0].nValue -= LOWFEE;
304 tx.
vin[0].prevout.hash = hash;
306 BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
312 BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error,
HasReason(
"bad-txns-inputs-missingorspent"));
317 tx.
vin[0].prevout.hash = txFirst[1]->GetHash();
318 tx.
vout[0].nValue = BLOCKSUBSIDY-HIGHFEE;
321 tx.
vin[0].prevout.hash = hash;
324 tx.
vin[1].prevout.hash = txFirst[0]->GetHash();
325 tx.
vin[1].prevout.n = 0;
326 tx.
vout[0].nValue = tx.
vout[0].nValue+BLOCKSUBSIDY-HIGHERFEE;
329 BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
334 tx.
vin[0].prevout.SetNull();
336 tx.
vout[0].nValue = 0;
341 BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error,
HasReason(
"bad-cb-multiple"));
345 tx.
vin[0].prevout.hash = txFirst[0]->GetHash();
347 tx.
vout[0].nValue = BLOCKSUBSIDY-HIGHFEE;
354 BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error,
HasReason(
"bad-txns-inputs-missingorspent"));
370 BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
382 BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
385 tx.
vin[0].prevout.hash = txFirst[0]->GetHash();
386 tx.
vin[0].prevout.n = 0;
388 tx.
vout[0].nValue = BLOCKSUBSIDY-LOWFEE;
393 tx.
vin[0].prevout.hash = hash;
394 tx.
vin[0].scriptSig =
CScript() << std::vector<unsigned char>(script.
begin(), script.
end());
395 tx.
vout[0].nValue -= LOWFEE;
399 BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error,
HasReason(
"block-validation-failed"));
415 std::vector<int> prevheights;
420 prevheights.resize(1);
421 tx.
vin[0].prevout.hash = txFirst[0]->GetHash();
422 tx.
vin[0].prevout.n = 0;
425 prevheights[0] = baseheight + 1;
427 tx.
vout[0].nValue = BLOCKSUBSIDY-HIGHFEE;
441 tx.
vin[0].prevout.hash = txFirst[1]->GetHash();
443 prevheights[0] = baseheight + 2;
461 tx.
vin[0].prevout.hash = txFirst[2]->GetHash();
463 prevheights[0] = baseheight + 3;
472 tx.
vin[0].prevout.hash = txFirst[3]->GetHash();
474 prevheights.resize(1);
475 prevheights[0] = baseheight + 4;
483 tx.
vin[0].prevout.hash = hash;
484 prevheights[0] =
m_node.
chainman->ActiveChain().Tip()->nHeight + 1;
486 tx.
vin[0].nSequence = 0;
489 tx.
vin[0].nSequence = 1;
496 BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
509 BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
516 TestPackageSelection(chainparams, scriptPubKey, txFirst);