Changeset View
Changeset View
Standalone View
Standalone View
src/test/validation_block_tests.cpp
Show First 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | |||||
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) { | ||||
return; | return; | ||||
} | } | ||||
bool gen_invalid = GetRand(100) < invalid_rate; | bool gen_invalid = InsecureRandRange(100) < invalid_rate; | ||||
bool gen_fork = GetRand(100) < branch_rate; | bool gen_fork = InsecureRandRange(100) < branch_rate; | ||||
const std::shared_ptr<const CBlock> pblock = | const std::shared_ptr<const CBlock> pblock = | ||||
gen_invalid ? BadBlock(config, root) : GoodBlock(config, root); | gen_invalid ? BadBlock(config, root) : GoodBlock(config, root); | ||||
blocks.push_back(pblock); | blocks.push_back(pblock); | ||||
if (!gen_invalid) { | if (!gen_invalid) { | ||||
BuildChain(config, pblock->GetHash(), height - 1, invalid_rate, | BuildChain(config, pblock->GetHash(), height - 1, invalid_rate, | ||||
branch_rate, max_size, blocks); | branch_rate, max_size, blocks); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering) { | ||||
// at random this will create parallelism and randomness inside validation - | // at random this will create parallelism and randomness inside validation - | ||||
// the ValidationInterface will subscribe to events generated during block | // the ValidationInterface will subscribe to events generated during block | ||||
// validation and assert on ordering invariance | // validation and assert on ordering invariance | ||||
boost::thread_group threads; | boost::thread_group threads; | ||||
for (int i = 0; i < 10; i++) { | for (int i = 0; i < 10; i++) { | ||||
threads.create_thread([&config, &blocks]() { | threads.create_thread([&config, &blocks]() { | ||||
bool tlignored; | bool tlignored; | ||||
for (int j = 0; j < 1000; j++) { | for (int j = 0; j < 1000; j++) { | ||||
auto block = blocks[GetRand(blocks.size() - 1)]; | auto block = blocks[InsecureRandRange(blocks.size() - 1)]; | ||||
ProcessNewBlock(config, block, true, &tlignored); | ProcessNewBlock(config, block, true, &tlignored); | ||||
} | } | ||||
// to make sure that eventually we process the full chain - do it | // to make sure that eventually we process the full chain - do it | ||||
// here | // here | ||||
for (auto block : blocks) { | for (auto block : blocks) { | ||||
if (block->vtx.size() == 1) { | if (block->vtx.size() == 1) { | ||||
bool processed = | bool processed = | ||||
Show All 18 Lines |