diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -222,8 +222,8 @@ BOOST_CHECK(pblocktemplate->block.vtx[8]->GetId() == lowFeeTxId2); } -void TestCoinbaseMessageEB(uint64_t eb, std::string cbmsg, - const CTxMemPool &mempool) { +static void TestCoinbaseMessageEB(uint64_t eb, std::string cbmsg, + const NodeContext &node) { GlobalConfig config; config.SetMaxBlockSize(eb); @@ -234,16 +234,17 @@ << OP_CHECKSIG; std::unique_ptr pblocktemplate = - BlockAssembler(config, ::ChainstateActive(), mempool) + BlockAssembler(config, node.chainman->ActiveChainstate(), *node.mempool) .CreateNewBlock(scriptPubKey); CBlock *pblock = &pblocktemplate->block; // IncrementExtraNonce creates a valid coinbase and merkleRoot unsigned int extraNonce = 0; - IncrementExtraNonce(pblock, ::ChainActive().Tip(), config.GetMaxBlockSize(), + CBlockIndex *active_chain_tip = node.chainman->ActiveChain().Tip(); + IncrementExtraNonce(pblock, active_chain_tip, config.GetMaxBlockSize(), extraNonce); - unsigned int nHeight = ::ChainActive().Tip()->nHeight + 1; + unsigned int nHeight = active_chain_tip->nHeight + 1; std::vector vec(cbmsg.begin(), cbmsg.end()); BOOST_CHECK(pblock->vtx[0]->vin[0].scriptSig == (CScript() << nHeight << CScriptNum(extraNonce) << vec)); @@ -252,10 +253,10 @@ // Coinbase scriptSig has to contains the correct EB value // converted to MB, rounded down to the first decimal BOOST_AUTO_TEST_CASE(CheckCoinbase_EB) { - TestCoinbaseMessageEB(1000001, "/EB1.0/", *m_node.mempool); - TestCoinbaseMessageEB(2000000, "/EB2.0/", *m_node.mempool); - TestCoinbaseMessageEB(8000000, "/EB8.0/", *m_node.mempool); - TestCoinbaseMessageEB(8320000, "/EB8.3/", *m_node.mempool); + TestCoinbaseMessageEB(1000001, "/EB1.0/", m_node); + TestCoinbaseMessageEB(2000000, "/EB2.0/", m_node); + TestCoinbaseMessageEB(8000000, "/EB8.0/", m_node); + TestCoinbaseMessageEB(8320000, "/EB8.3/", m_node); } // NOTE: These tests rely on CreateNewBlock doing its own self-validation! @@ -685,11 +686,11 @@ fCheckpointsEnabled = true; } -void CheckBlockMaxSize(const Config &config, const CTxMemPool &mempool, - uint64_t size, uint64_t expected) { +static void CheckBlockMaxSize(const Config &config, const NodeContext &node, + uint64_t size, uint64_t expected) { gArgs.ForceSetArg("-blockmaxsize", ToString(size)); - BlockAssembler ba(config, ::ChainstateActive(), mempool); + BlockAssembler ba(config, node.chainman->ActiveChainstate(), *node.mempool); BOOST_CHECK_EQUAL(ba.GetMaxGeneratedBlockSize(), expected); } @@ -701,31 +702,27 @@ // Test around historical 1MB (plus one byte because that's mandatory) config.SetMaxBlockSize(ONE_MEGABYTE + 1); - CheckBlockMaxSize(config, *m_node.mempool, 0, 1000); - CheckBlockMaxSize(config, *m_node.mempool, 1000, 1000); - CheckBlockMaxSize(config, *m_node.mempool, 1001, 1001); - CheckBlockMaxSize(config, *m_node.mempool, 12345, 12345); - - CheckBlockMaxSize(config, *m_node.mempool, ONE_MEGABYTE - 1001, - ONE_MEGABYTE - 1001); - CheckBlockMaxSize(config, *m_node.mempool, ONE_MEGABYTE - 1000, - ONE_MEGABYTE - 1000); - CheckBlockMaxSize(config, *m_node.mempool, ONE_MEGABYTE - 999, - ONE_MEGABYTE - 999); - CheckBlockMaxSize(config, *m_node.mempool, ONE_MEGABYTE, - ONE_MEGABYTE - 999); + CheckBlockMaxSize(config, m_node, 0, 1000); + CheckBlockMaxSize(config, m_node, 1000, 1000); + CheckBlockMaxSize(config, m_node, 1001, 1001); + CheckBlockMaxSize(config, m_node, 12345, 12345); + + CheckBlockMaxSize(config, m_node, ONE_MEGABYTE - 1001, ONE_MEGABYTE - 1001); + CheckBlockMaxSize(config, m_node, ONE_MEGABYTE - 1000, ONE_MEGABYTE - 1000); + CheckBlockMaxSize(config, m_node, ONE_MEGABYTE - 999, ONE_MEGABYTE - 999); + CheckBlockMaxSize(config, m_node, ONE_MEGABYTE, ONE_MEGABYTE - 999); // Test around default cap config.SetMaxBlockSize(DEFAULT_MAX_BLOCK_SIZE); // Now we can use the default max block size. - CheckBlockMaxSize(config, *m_node.mempool, DEFAULT_MAX_BLOCK_SIZE - 1001, + CheckBlockMaxSize(config, m_node, DEFAULT_MAX_BLOCK_SIZE - 1001, DEFAULT_MAX_BLOCK_SIZE - 1001); - CheckBlockMaxSize(config, *m_node.mempool, DEFAULT_MAX_BLOCK_SIZE - 1000, + CheckBlockMaxSize(config, m_node, DEFAULT_MAX_BLOCK_SIZE - 1000, DEFAULT_MAX_BLOCK_SIZE - 1000); - CheckBlockMaxSize(config, *m_node.mempool, DEFAULT_MAX_BLOCK_SIZE - 999, + CheckBlockMaxSize(config, m_node, DEFAULT_MAX_BLOCK_SIZE - 999, DEFAULT_MAX_BLOCK_SIZE - 1000); - CheckBlockMaxSize(config, *m_node.mempool, DEFAULT_MAX_BLOCK_SIZE, + CheckBlockMaxSize(config, m_node, DEFAULT_MAX_BLOCK_SIZE, DEFAULT_MAX_BLOCK_SIZE - 1000); // If the parameter is not specified, we use