10 #include <boost/test/unit_test.hpp> 18 int64_t nLastRetargetTime = 1261130161;
21 pindexLast.
nTime = 1262152739;
22 pindexLast.
nBits = 0x1d00ffff;
28 unsigned int expected_nbits = 0x1d00d86aU;
37 int64_t nLastRetargetTime = 1231006505;
40 pindexLast.
nTime = 1233061996;
41 pindexLast.
nBits = 0x1d00ffff;
42 unsigned int expected_nbits = 0x1d00ffffU;
51 int64_t nLastRetargetTime = 1279008237;
54 pindexLast.
nTime = 1279297671;
55 pindexLast.
nBits = 0x1c05a3f4;
56 unsigned int expected_nbits = 0x1c0168fdU;
60 unsigned int invalid_nbits = expected_nbits-1;
68 int64_t nLastRetargetTime = 1263163443;
71 pindexLast.
nTime = 1269211443;
72 pindexLast.
nBits = 0x1c387f6f;
73 unsigned int expected_nbits = 0x1d00e1fdU;
77 unsigned int invalid_nbits = expected_nbits+1;
95 unsigned int nBits{~0x00800000U};
138 std::vector<CBlockIndex> blocks(10000);
139 for (
int i = 0; i < 10000; i++) {
140 blocks[i].pprev = i ? &blocks[i - 1] :
nullptr;
141 blocks[i].nHeight = i;
142 blocks[i].nTime = 1269211443 + i * chainParams->GetConsensus().nPowTargetSpacing;
143 blocks[i].nBits = 0x207fffff;
147 for (
int j = 0; j < 1000; j++) {
160 const auto consensus = chainParams->GetConsensus();
163 BOOST_CHECK_EQUAL(consensus.hashGenesisBlock, chainParams->GenesisBlock().GetHash());
166 BOOST_CHECK_EQUAL(consensus.nPowTargetTimespan % consensus.nPowTargetSpacing, 0);
171 pow_compact.
SetCompact(chainParams->GenesisBlock().nBits, &neg, &over);
177 if (!consensus.fPowNoRetargeting) {
178 arith_uint256 targ_max(
"0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
179 targ_max /= consensus.nPowTargetTimespan*4;
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...
void sanity_check_chainparams(const ArgsManager &args, std::string chainName)
int64_t GetBlockTime() const
static const std::string REGTEST
unsigned int CalculateNextWorkRequired(const CBlockIndex *pindexLast, int64_t nFirstBlockTime, const Consensus::Params ¶ms)
uint32_t GetCompact(bool fNegative=false) const
arith_uint256 UintToArith256(const uint256 &a)
static const std::string MAIN
Chain name strings.
static uint64_t InsecureRandRange(uint64_t range)
BOOST_AUTO_TEST_SUITE_END()
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.
256-bit unsigned big integer.
uint256 ArithToUint256(const arith_uint256 &a)
#define BOOST_CHECK_EQUAL(v1, v2)
The block chain is a tree shaped structure starting with the genesis block at the root...
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...
static const std::string TESTNET
arith_uint256 GetBlockProof(const CBlockIndex &block)
int nHeight
height of the entry in the chain. The genesis block has height 0
void SetHex(const char *psz)
static const std::string SIGNET
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...
#define BOOST_CHECK(expr)
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.
BOOST_AUTO_TEST_CASE(get_next_work)