MCPcopy Create free account
hub / github.com/ElementsProject/elements / BOOST_AUTO_TEST_CASE

Function BOOST_AUTO_TEST_CASE

src/test/miner_tests.cpp:195–519  ·  view source on GitHub ↗

NOTE: These tests rely on CreateNewBlock doing its own self-validation!

Source from the content-addressed store, hash-verified

193
194// NOTE: These tests rely on CreateNewBlock doing its own self-validation!
195BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
196{
197 // Note that by default, these tests run with size accounting enabled.
198 const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
199 const CChainParams& chainparams = *chainParams;
200 CScript scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
201 std::unique_ptr<CBlockTemplate> pblocktemplate;
202 CMutableTransaction tx;
203 CScript script;
204 uint256 hash;
205 TestMemPoolEntryHelper entry;
206 entry.nFee = 11;
207 entry.nHeight = 11;
208
209 fCheckpointsEnabled = false;
210
211 // Simple block creation, nothing special yet:
212 BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
213
214 // We can't make transactions until we have inputs
215 // Therefore, load 110 blocks :)
216 static_assert(std::size(BLOCKINFO) == 110, "Should have 110 blocks to import");
217 int baseheight = 0;
218 std::vector<CTransactionRef> txFirst;
219 for (const auto& bi : BLOCKINFO) {
220 CBlock *pblock = &pblocktemplate->block; // pointer for convenience
221 {
222 LOCK(cs_main);
223 pblock->nVersion = VERSIONBITS_TOP_BITS;
224 pblock->nTime = m_node.chainman->ActiveChain().Tip()->GetMedianTimePast()+1;
225 CMutableTransaction txCoinbase(*pblock->vtx[0]);
226 txCoinbase.nVersion = 1;
227 txCoinbase.vin[0].scriptSig = CScript{} << (m_node.chainman->ActiveChain().Height() + 1) << bi.extranonce;
228 txCoinbase.vout.resize(1); // Ignore the (optional) segwit commitment added by CreateNewBlock (as the hardcoded nonces don't account for this)
229 txCoinbase.vout[0].scriptPubKey = CScript();
230 pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase));
231 if (txFirst.size() == 0)
232 baseheight = m_node.chainman->ActiveChain().Height();
233 if (txFirst.size() < 4)
234 txFirst.push_back(pblock->vtx[0]);
235 pblock->hashMerkleRoot = BlockMerkleRoot(*pblock);
236 pblock->nNonce = bi.nonce;
237 }
238 std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(*pblock);
239 BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlock(chainparams, shared_pblock, true, nullptr));
240 pblock->hashPrevBlock = pblock->GetHash();
241 }
242
243 LOCK(cs_main);
244 LOCK(m_node.mempool->cs);
245
246 // Just to make sure we can still make simple blocks
247 BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
248
249 const CAmount BLOCKSUBSIDY = 50*COIN;
250 const CAmount LOWFEE = CENT;
251 const CAmount HIGHFEE = COIN;
252 const CAmount HIGHERFEE = 4*COIN;

Callers

nothing calls this directly

Calls 15

CreateChainParamsFunction · 0.85
ParseHexFunction · 0.85
BlockMerkleRootFunction · 0.85
GetTimeFunction · 0.85
HasReasonClass · 0.85
InsecureRand256Function · 0.85
GetScriptForDestinationFunction · 0.85
ScriptHashClass · 0.85
SetMockTimeFunction · 0.85
CheckFinalTxFunction · 0.85
SequenceLocksFunction · 0.85
IsFinalTxFunction · 0.85

Tested by

no test coverage detected