9#include <chainparams.h>
12#include <test/util/random.h>
13#include <test/util/setup_common.h>
15#include <boost/test/unit_test.hpp>
17BOOST_FIXTURE_TEST_SUITE(eda_tests, BasicTestingSetup)
23 int64_t nLastRetargetTime = 1261130161;
26 pindexLast.
nTime = 1262152739;
27 pindexLast.
nBits = 0x1d00ffff;
33 unsigned int expected_nbits = 0x1d00d86aU;
34 auto consensus_params = config.GetChainParams().GetConsensus();
40 pindexLast.
nBits, expected_nbits));
47 int64_t nLastRetargetTime = 1231006505;
50 pindexLast.
nTime = 1233061996;
51 pindexLast.
nBits = 0x1d00ffff;
52 unsigned int expected_nbits = 0x1d00ffffU;
53 auto consensus_params = config.GetChainParams().GetConsensus();
59 pindexLast.
nBits, expected_nbits));
66 int64_t nLastRetargetTime = 1279008237;
69 pindexLast.
nTime = 1279297671;
70 pindexLast.
nBits = 0x1c05a3f4;
71 unsigned int expected_nbits = 0x1c0168fdU;
72 auto consensus_params = config.GetChainParams().GetConsensus();
78 pindexLast.
nBits, expected_nbits));
81 unsigned int invalid_nbits = expected_nbits - 1;
84 pindexLast.
nBits, invalid_nbits));
91 int64_t nLastRetargetTime = 1263163443;
94 pindexLast.
nTime = 1269211443;
95 pindexLast.
nBits = 0x1c387f6f;
96 unsigned int expected_nbits = 0x1d00e1fdU;
97 auto consensus_params = config.GetChainParams().GetConsensus();
103 pindexLast.
nBits, expected_nbits));
106 unsigned int invalid_nbits = expected_nbits + 1;
109 pindexLast.
nBits, invalid_nbits));
113 const auto consensus =
123 const auto consensus =
126 unsigned int nBits = ~0x00800000;
132 const auto consensus =
144 const auto consensus =
156 const auto consensus =
169 std::vector<CBlockIndex> blocks(10000);
170 for (
int i = 0; i < 10000; i++) {
171 blocks[i].pprev = i ? &blocks[i - 1] :
nullptr;
172 blocks[i].nHeight = i;
175 i * config.GetChainParams().GetConsensus().nPowTargetSpacing;
176 blocks[i].nBits = 0x207fffff;
177 blocks[i].nChainWork =
182 for (
int j = 0; j < 1000; j++) {
183 CBlockIndex *p1 = &blocks[InsecureRandRange(10000)];
184 CBlockIndex *p2 = &blocks[InsecureRandRange(10000)];
185 CBlockIndex *p3 = &blocks[InsecureRandRange(10000)];
188 *p1, *p2, *p3, config.GetChainParams().GetConsensus());
196 block.
pprev = pindexPrev;
198 block.
nTime = pindexPrev->
nTime + nTimeInterval;
208 std::vector<CBlockIndex> blocks(115);
213 uint32_t initialBits = currentPow.
GetCompact();
217 blocks[0].nHeight = 0;
218 blocks[0].nTime = 1269211443;
219 blocks[0].nBits = initialBits;
224 for (
size_t i = 1; i < 100; i++) {
234 for (
size_t i = 100; i < 110; i++) {
235 blocks[i] =
GetBlockIndex(&blocks[i - 1], 2 * 3600, initialBits);
242 blocks[110] =
GetBlockIndex(&blocks[109], 2 * 3600, initialBits);
244 currentPow += (currentPow >> 2);
253 currentPow += (currentPow >> 2);
262 currentPow += (currentPow >> 2);
271 currentPow += (currentPow >> 2);
285BOOST_AUTO_TEST_SUITE_END()
arith_uint256 UintToArith256(const uint256 &a)
uint256 ArithToUint256(const arith_uint256 &a)
arith_uint256 GetBlockProof(const CBlockIndex &block)
int64_t GetBlockProofEquivalentTime(const CBlockIndex &to, const CBlockIndex &from, const CBlockIndex &tip, const Consensus::Params ¶ms)
Return the time it would take to redo the work difference between from and to, assuming the current h...
std::unique_ptr< const CChainParams > CreateChainParams(const ArgsManager &args, const std::string &chain)
Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
static const std::string MAIN
BIP70 chain name strings (main, test or regtest)
The block chain is a tree shaped structure starting with the genesis block at the root,...
CBlockIndex * pprev
pointer to the index of the predecessor of this block
arith_uint256 nChainWork
(memory only) Total amount of work (expected number of hashes) in the chain up to and including this ...
int64_t GetBlockTime() const
int nHeight
height of the entry in the chain. The genesis block has height 0
256-bit unsigned big integer.
arith_uint256 & SetCompact(uint32_t nCompact, bool *pfNegative=nullptr, bool *pfOverflow=nullptr)
The "compact" format is a representation of a whole number N using an unsigned 32bit number similar t...
uint32_t GetCompact(bool fNegative=false) const
void SetHex(const char *psz)
uint32_t GetNextEDAWorkRequired(const CBlockIndex *pindexPrev, const CBlockHeader *pblock, const Consensus::Params ¶ms)
Compute the next required proof of work using the legacy Bitcoin difficulty adjustment + Emergency Di...
uint32_t CalculateNextWorkRequired(const CBlockIndex *pindexPrev, int64_t nFirstBlockTime, const Consensus::Params ¶ms)
Do difficulty adjustement Satoshi's way.
BOOST_AUTO_TEST_CASE(get_next_work)
static CBlockIndex GetBlockIndex(CBlockIndex *pindexPrev, int64_t nTimeInterval, uint32_t nBits)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
bool CheckProofOfWork(const BlockHash &hash, uint32_t nBits, const Consensus::Params ¶ms)
Check whether a block hash satisfies the proof-of-work requirement specified by nBits.
bool PermittedDifficultyTransition(const Consensus::Params ¶ms, int64_t height, uint32_t old_nbits, uint32_t new_nbits)
Return false if the proof-of-work requirement specified by new_nbits at a given height is not possibl...
A BlockHash is a unqiue identifier for a block.
Parameters that influence chain consensus.
uint256 powLimit
Proof of work parameters.
int64_t nPowTargetSpacing