Changeset View
Changeset View
Standalone View
Standalone View
src/test/validation_block_tests.cpp
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | std::shared_ptr<CBlock> Block(const Config &config, const uint256 &prev_hash) { | ||||
CMutableTransaction txCoinbase(*pblock->vtx[0]); | CMutableTransaction txCoinbase(*pblock->vtx[0]); | ||||
txCoinbase.vout.resize(1); | txCoinbase.vout.resize(1); | ||||
pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase)); | pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase)); | ||||
return pblock; | return pblock; | ||||
} | } | ||||
std::shared_ptr<CBlock> FinalizeBlock(const Config &config, | std::shared_ptr<CBlock> FinalizeBlock(const Consensus::Params ¶ms, | ||||
std::shared_ptr<CBlock> pblock) { | std::shared_ptr<CBlock> pblock) { | ||||
pblock->hashMerkleRoot = BlockMerkleRoot(*pblock); | pblock->hashMerkleRoot = BlockMerkleRoot(*pblock); | ||||
while (!CheckProofOfWork(pblock->GetHash(), pblock->nBits, config)) { | while (!CheckProofOfWork(pblock->GetHash(), pblock->nBits, params)) { | ||||
++(pblock->nNonce); | ++(pblock->nNonce); | ||||
} | } | ||||
return pblock; | return pblock; | ||||
} | } | ||||
// construct a valid block | // construct a valid block | ||||
const std::shared_ptr<const CBlock> GoodBlock(const Config &config, | const std::shared_ptr<const CBlock> GoodBlock(const Config &config, | ||||
const uint256 &prev_hash) { | const uint256 &prev_hash) { | ||||
return FinalizeBlock(config, Block(config, prev_hash)); | return FinalizeBlock(config.GetChainParams().GetConsensus(), | ||||
Block(config, prev_hash)); | |||||
} | } | ||||
// construct an invalid block (but with a valid header) | // construct an invalid block (but with a valid header) | ||||
const std::shared_ptr<const CBlock> BadBlock(const Config &config, | const std::shared_ptr<const CBlock> BadBlock(const Config &config, | ||||
const uint256 &prev_hash) { | const uint256 &prev_hash) { | ||||
auto pblock = Block(config, prev_hash); | auto pblock = Block(config, prev_hash); | ||||
CMutableTransaction coinbase_spend; | CMutableTransaction coinbase_spend; | ||||
coinbase_spend.vin.push_back( | coinbase_spend.vin.push_back( | ||||
CTxIn(COutPoint(pblock->vtx[0]->GetId(), 0), CScript(), 0)); | CTxIn(COutPoint(pblock->vtx[0]->GetId(), 0), CScript(), 0)); | ||||
coinbase_spend.vout.push_back(pblock->vtx[0]->vout[0]); | coinbase_spend.vout.push_back(pblock->vtx[0]->vout[0]); | ||||
CTransactionRef tx = MakeTransactionRef(coinbase_spend); | CTransactionRef tx = MakeTransactionRef(coinbase_spend); | ||||
pblock->vtx.push_back(tx); | pblock->vtx.push_back(tx); | ||||
auto ret = FinalizeBlock(config, pblock); | auto ret = FinalizeBlock(config.GetChainParams().GetConsensus(), pblock); | ||||
return ret; | return ret; | ||||
} | } | ||||
void BuildChain(const Config &config, const uint256 &root, int height, | void BuildChain(const Config &config, const uint256 &root, int height, | ||||
const unsigned int invalid_rate, const unsigned int branch_rate, | const unsigned int invalid_rate, const unsigned int branch_rate, | ||||
const unsigned int max_size, | const unsigned int max_size, | ||||
std::vector<std::shared_ptr<const CBlock>> &blocks) { | std::vector<std::shared_ptr<const CBlock>> &blocks) { | ||||
if (height <= 0 || blocks.size() >= max_size) { | if (height <= 0 || blocks.size() >= max_size) { | ||||
▲ Show 20 Lines • Show All 97 Lines • Show Last 20 Lines |