| 342 | } |
| 343 | |
| 344 | void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst, int baseheight) |
| 345 | { |
| 346 | FakeNodeClock clock{}; |
| 347 | |
| 348 | Txid hash; |
| 349 | CMutableTransaction tx; |
| 350 | TestMemPoolEntryHelper entry; |
| 351 | entry.nFee = 11; |
| 352 | entry.nHeight = 11; |
| 353 | |
| 354 | const CAmount BLOCKSUBSIDY = 50 * COIN; |
| 355 | const CAmount LOWFEE = CENT; |
| 356 | const CAmount HIGHFEE = COIN; |
| 357 | const CAmount HIGHERFEE = 4 * COIN; |
| 358 | |
| 359 | auto mining{MakeMining()}; |
| 360 | BOOST_REQUIRE(mining); |
| 361 | |
| 362 | BlockCreateOptions options{ |
| 363 | .coinbase_output_script = scriptPubKey, |
| 364 | }; |
| 365 | |
| 366 | { |
| 367 | CTxMemPool& tx_mempool{MakeMempool()}; |
| 368 | LOCK(tx_mempool.cs); |
| 369 | |
| 370 | // Just to make sure we can still make simple blocks |
| 371 | auto block_template{mining->createNewBlock(options, /*cooldown=*/false)}; |
| 372 | BOOST_REQUIRE(block_template); |
| 373 | CBlock block{block_template->getBlock()}; |
| 374 | |
| 375 | auto txs = CreateBigSigOpsCluster(txFirst[0]); |
| 376 | |
| 377 | int64_t legacy_sigops = 0; |
| 378 | for (auto& t : txs) { |
| 379 | // If we don't set the number of sigops in the CTxMemPoolEntry, |
| 380 | // template creation fails during sanity checks. |
| 381 | TryAddToMempool(tx_mempool, entry.Fee(LOWFEE).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(t)); |
| 382 | legacy_sigops += GetLegacySigOpCount(*t); |
| 383 | BOOST_CHECK(tx_mempool.GetIter(t->GetHash()).has_value()); |
| 384 | } |
| 385 | assert(tx_mempool.mapTx.size() == 51); |
| 386 | assert(legacy_sigops == 20001); |
| 387 | BOOST_CHECK_EXCEPTION(mining->createNewBlock(options, /*cooldown=*/false), std::runtime_error, HasReason("bad-blk-sigops")); |
| 388 | } |
| 389 | |
| 390 | { |
| 391 | CTxMemPool& tx_mempool{MakeMempool()}; |
| 392 | LOCK(tx_mempool.cs); |
| 393 | |
| 394 | // Check that the mempool is empty. |
| 395 | assert(tx_mempool.mapTx.empty()); |
| 396 | |
| 397 | // Just to make sure we can still make simple blocks |
| 398 | auto block_template{mining->createNewBlock(options, /*cooldown=*/false)}; |
| 399 | BOOST_REQUIRE(block_template); |
| 400 | CBlock block{block_template->getBlock()}; |
| 401 |
nothing calls this directly
no test coverage detected