Changeset View
Changeset View
Standalone View
Standalone View
src/test/miner_tests.cpp
Show First 20 Lines • Show All 254 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
CMutableTransaction tx, tx2; | CMutableTransaction tx, tx2; | ||||
CScript script; | CScript script; | ||||
uint256 hash; | uint256 hash; | ||||
TestMemPoolEntryHelper entry; | TestMemPoolEntryHelper entry; | ||||
entry.nFee = 11 * SATOSHI; | entry.nFee = 11 * SATOSHI; | ||||
entry.dPriority = 111.0; | entry.dPriority = 111.0; | ||||
entry.nHeight = 11; | entry.nHeight = 11; | ||||
LOCK(cs_main); | |||||
fCheckpointsEnabled = false; | fCheckpointsEnabled = false; | ||||
GlobalConfig config; | GlobalConfig config; | ||||
// Simple block creation, nothing special yet: | // Simple block creation, nothing special yet: | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
pblocktemplate = | pblocktemplate = | ||||
BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey)); | BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey)); | ||||
// We can't make transactions until we have inputs. Therefore, load 100 | // We can't make transactions until we have inputs. Therefore, load 100 | ||||
// blocks :) | // blocks :) | ||||
int baseheight = 0; | int baseheight = 0; | ||||
std::vector<CTransactionRef> txFirst; | std::vector<CTransactionRef> txFirst; | ||||
for (size_t i = 0; i < sizeof(blockinfo) / sizeof(*blockinfo); ++i) { | for (size_t i = 0; i < sizeof(blockinfo) / sizeof(*blockinfo); ++i) { | ||||
// pointer for convenience. | // pointer for convenience. | ||||
CBlock *pblock = &pblocktemplate->block; | CBlock *pblock = &pblocktemplate->block; | ||||
{ | |||||
LOCK(cs_main); | |||||
pblock->nVersion = 1; | pblock->nVersion = 1; | ||||
pblock->nTime = chainActive.Tip()->GetMedianTimePast() + 1; | pblock->nTime = chainActive.Tip()->GetMedianTimePast() + 1; | ||||
CMutableTransaction txCoinbase(*pblock->vtx[0]); | CMutableTransaction txCoinbase(*pblock->vtx[0]); | ||||
txCoinbase.nVersion = 1; | txCoinbase.nVersion = 1; | ||||
txCoinbase.vin[0].scriptSig = CScript(); | txCoinbase.vin[0].scriptSig = CScript(); | ||||
txCoinbase.vin[0].scriptSig.push_back(blockinfo[i].extranonce); | txCoinbase.vin[0].scriptSig.push_back(blockinfo[i].extranonce); | ||||
txCoinbase.vin[0].scriptSig.push_back(chainActive.Height()); | txCoinbase.vin[0].scriptSig.push_back(chainActive.Height()); | ||||
// Ignore the (optional) segwit commitment added by CreateNewBlock (as | |||||
// the hardcoded nonces don't account for this) | |||||
txCoinbase.vout.resize(1); | txCoinbase.vout.resize(1); | ||||
txCoinbase.vout[0].scriptPubKey = CScript(); | txCoinbase.vout[0].scriptPubKey = CScript(); | ||||
pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase)); | pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase)); | ||||
if (txFirst.size() == 0) { | if (txFirst.size() == 0) { | ||||
baseheight = chainActive.Height(); | baseheight = chainActive.Height(); | ||||
} | } | ||||
if (txFirst.size() < 4) { | if (txFirst.size() < 4) { | ||||
txFirst.push_back(pblock->vtx[0]); | txFirst.push_back(pblock->vtx[0]); | ||||
} | } | ||||
pblock->hashMerkleRoot = BlockMerkleRoot(*pblock); | pblock->hashMerkleRoot = BlockMerkleRoot(*pblock); | ||||
pblock->nNonce = blockinfo[i].nonce; | pblock->nNonce = blockinfo[i].nonce; | ||||
} | |||||
std::shared_ptr<const CBlock> shared_pblock = | std::shared_ptr<const CBlock> shared_pblock = | ||||
std::make_shared<const CBlock>(*pblock); | std::make_shared<const CBlock>(*pblock); | ||||
BOOST_CHECK(ProcessNewBlock(config, shared_pblock, true, nullptr)); | BOOST_CHECK(ProcessNewBlock(config, shared_pblock, true, nullptr)); | ||||
pblock->hashPrevBlock = pblock->GetHash(); | pblock->hashPrevBlock = pblock->GetHash(); | ||||
} | } | ||||
LOCK(cs_main); | |||||
// Just to make sure we can still make simple blocks. | // Just to make sure we can still make simple blocks. | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
pblocktemplate = | pblocktemplate = | ||||
BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey)); | BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey)); | ||||
const Amount BLOCKSUBSIDY = 50 * COIN; | const Amount BLOCKSUBSIDY = 50 * COIN; | ||||
const Amount LOWFEE = CENT; | const Amount LOWFEE = CENT; | ||||
const Amount HIGHFEE = COIN; | const Amount HIGHFEE = COIN; | ||||
▲ Show 20 Lines • Show All 457 Lines • Show Last 20 Lines |