diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/fuzz/pow.cpp | 14 | ||||
-rw-r--r-- | src/test/miner_tests.cpp | 12 |
2 files changed, 13 insertions, 13 deletions
diff --git a/src/test/fuzz/pow.cpp b/src/test/fuzz/pow.cpp index 507ce57ec0..eecf50f475 100644 --- a/src/test/fuzz/pow.cpp +++ b/src/test/fuzz/pow.cpp @@ -25,7 +25,7 @@ FUZZ_TARGET_INIT(pow, initialize_pow) { FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); const Consensus::Params& consensus_params = Params().GetConsensus(); - std::vector<CBlockIndex> blocks; + std::vector<std::unique_ptr<CBlockIndex>> blocks; const uint32_t fixed_time = fuzzed_data_provider.ConsumeIntegral<uint32_t>(); const uint32_t fixed_bits = fuzzed_data_provider.ConsumeIntegral<uint32_t>(); LIMITED_WHILE(fuzzed_data_provider.remaining_bytes() > 0, 10000) { @@ -33,9 +33,10 @@ FUZZ_TARGET_INIT(pow, initialize_pow) if (!block_header) { continue; } - CBlockIndex current_block{*block_header}; + CBlockIndex& current_block{ + *blocks.emplace_back(std::make_unique<CBlockIndex>(*block_header))}; { - CBlockIndex* previous_block = blocks.empty() ? nullptr : &PickValue(fuzzed_data_provider, blocks); + CBlockIndex* previous_block = blocks.empty() ? nullptr : PickValue(fuzzed_data_provider, blocks).get(); const int current_height = (previous_block != nullptr && previous_block->nHeight != std::numeric_limits<int>::max()) ? previous_block->nHeight + 1 : 0; if (fuzzed_data_provider.ConsumeBool()) { current_block.pprev = previous_block; @@ -57,7 +58,6 @@ FUZZ_TARGET_INIT(pow, initialize_pow) } else { current_block.nChainWork = ConsumeArithUInt256(fuzzed_data_provider); } - blocks.push_back(current_block); } { (void)GetBlockProof(current_block); @@ -67,9 +67,9 @@ FUZZ_TARGET_INIT(pow, initialize_pow) } } { - const CBlockIndex* to = &PickValue(fuzzed_data_provider, blocks); - const CBlockIndex* from = &PickValue(fuzzed_data_provider, blocks); - const CBlockIndex* tip = &PickValue(fuzzed_data_provider, blocks); + const auto& to = PickValue(fuzzed_data_provider, blocks); + const auto& from = PickValue(fuzzed_data_provider, blocks); + const auto& tip = PickValue(fuzzed_data_provider, blocks); try { (void)GetBlockProofEquivalentTime(*to, *from, *tip, consensus_params); } catch (const uint_error&) { diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index 9f5fb17b60..2f091492e1 100644 --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -78,11 +78,11 @@ constexpr static struct { {0, 792342903}, {6, 678455063}, {6, 773251385}, {5, 186617471}, {6, 883189502}, {7, 396077336}, {8, 254702874}, {0, 455592851}}; -static CBlockIndex CreateBlockIndex(int nHeight, CBlockIndex* active_chain_tip) EXCLUSIVE_LOCKS_REQUIRED(cs_main) +static std::unique_ptr<CBlockIndex> CreateBlockIndex(int nHeight, CBlockIndex* active_chain_tip) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { - CBlockIndex index; - index.nHeight = nHeight; - index.pprev = active_chain_tip; + auto index{std::make_unique<CBlockIndex>()}; + index->nHeight = nHeight; + index->pprev = active_chain_tip; return index; } @@ -394,7 +394,7 @@ void MinerTestingSetup::TestBasicMining(const CChainParams& chainparams, const C { CBlockIndex* active_chain_tip = m_node.chainman->ActiveChain().Tip(); - BOOST_CHECK(SequenceLocks(CTransaction(tx), flags, prevheights, CreateBlockIndex(active_chain_tip->nHeight + 2, active_chain_tip))); // Sequence locks pass on 2nd block + BOOST_CHECK(SequenceLocks(CTransaction(tx), flags, prevheights, *CreateBlockIndex(active_chain_tip->nHeight + 2, active_chain_tip))); // Sequence locks pass on 2nd block } // relative time locked @@ -411,7 +411,7 @@ void MinerTestingSetup::TestBasicMining(const CChainParams& chainparams, const C m_node.chainman->ActiveChain().Tip()->GetAncestor(m_node.chainman->ActiveChain().Tip()->nHeight - i)->nTime += SEQUENCE_LOCK_TIME; // Trick the MedianTimePast { CBlockIndex* active_chain_tip = m_node.chainman->ActiveChain().Tip(); - BOOST_CHECK(SequenceLocks(CTransaction(tx), flags, prevheights, CreateBlockIndex(active_chain_tip->nHeight + 1, active_chain_tip))); + BOOST_CHECK(SequenceLocks(CTransaction(tx), flags, prevheights, *CreateBlockIndex(active_chain_tip->nHeight + 1, active_chain_tip))); } for (int i = 0; i < CBlockIndex::nMedianTimeSpan; ++i) { |