6#include <chainparams.h>
11#include <validation.h>
14#include <boost/test/unit_test.hpp>
25 const uint256& starting_hash,
const int nVersion,
int prev_time,
26 const uint256& merkle_root,
const uint32_t nBits);
32 ++(starting_header.
nNonce);
37 size_t count,
const uint256& starting_hash,
const int nVersion,
int prev_time,
38 const uint256& merkle_root,
const uint32_t nBits)
40 uint256 prev_hash = starting_hash;
42 while (headers.size() <
count) {
43 headers.emplace_back();
48 next_header.
nTime = prev_time+1;
49 next_header.
nBits = nBits;
52 prev_hash = next_header.
GetHash();
53 prev_time = next_header.
nTime;
70 std::vector<CBlockHeader> first_chain;
71 std::vector<CBlockHeader> second_chain;
73 std::unique_ptr<HeadersSyncState> hss;
75 const int target_blocks = 15000;
80 GenerateHeaders(first_chain, target_blocks-1,
Params().GenesisBlock().GetHash(),
81 Params().GenesisBlock().nVersion,
Params().GenesisBlock().nTime,
84 GenerateHeaders(second_chain, target_blocks-2,
Params().GenesisBlock().GetHash(),
85 Params().GenesisBlock().nVersion,
Params().GenesisBlock().nTime,
89 std::vector<CBlockHeader> headers_batch;
93 headers_batch.insert(headers_batch.end(), std::next(first_chain.begin()), first_chain.end());
96 (void)hss->ProcessNextHeaders({first_chain.front()},
true);
98 auto result = hss->ProcessNextHeaders(headers_batch,
true);
107 result = hss->ProcessNextHeaders(second_chain,
true);
113 (void)hss->ProcessNextHeaders(first_chain,
true);
116 result = hss->ProcessNextHeaders(first_chain,
true);
120 BOOST_CHECK(result.pow_validated_headers.size() == first_chain.size());
129 (void)hss->ProcessNextHeaders({second_chain.front()},
true);
132 headers_batch.clear();
133 headers_batch.insert(headers_batch.end(), std::next(second_chain.begin(), 1), second_chain.end());
137 result = hss->ProcessNextHeaders(headers_batch,
false);
uint256 ArithToUint256(const arith_uint256 &a)
const CChainParams & Params()
Return the currently selected parameters.
The block chain is a tree shaped structure starting with the genesis block at the root,...
256-bit unsigned big integer.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
#define BOOST_CHECK(expr)
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params ¶ms)
Check whether a block hash satisfies the proof-of-work requirement specified by nBits.
Identical to TestingSetup, but chain set to regtest.
std::unique_ptr< ChainstateManager > chainman
#define WITH_LOCK(cs, code)
Run code while locking a mutex.