Changeset View
Changeset View
Standalone View
Standalone View
src/test/blockchain_tests.cpp
#include <rpc/blockchain.h> | #include <rpc/blockchain.h> | ||||
#include <chain.h> | #include <chain.h> | ||||
#include <util/string.h> | |||||
#include <test/util/setup_common.h> | #include <test/util/setup_common.h> | ||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
#include <cstdlib> | #include <cstdlib> | ||||
/** | /** | ||||
Show All 10 Lines | static CBlockIndex *CreateBlockIndexWithNbits(uint32_t nbits) { | ||||
block_index->nTime = 1269211443; | block_index->nTime = 1269211443; | ||||
block_index->nBits = nbits; | block_index->nBits = nbits; | ||||
return block_index; | return block_index; | ||||
} | } | ||||
static void RejectDifficultyMismatch(double difficulty, | static void RejectDifficultyMismatch(double difficulty, | ||||
double expected_difficulty) { | double expected_difficulty) { | ||||
BOOST_CHECK_MESSAGE(DoubleEquals(difficulty, expected_difficulty, 0.00001), | BOOST_CHECK_MESSAGE(DoubleEquals(difficulty, expected_difficulty, 0.00001), | ||||
"Difficulty was " + std::to_string(difficulty) + | "Difficulty was " + ToString(difficulty) + | ||||
" but was expected to be " + | " but was expected to be " + | ||||
std::to_string(expected_difficulty)); | ToString(expected_difficulty)); | ||||
} | } | ||||
/** | /** | ||||
* Given a BlockIndex with the provided nbits, | * Given a BlockIndex with the provided nbits, | ||||
* verify that the expected difficulty results. | * verify that the expected difficulty results. | ||||
*/ | */ | ||||
static void TestDifficulty(uint32_t nbits, double expected_difficulty) { | static void TestDifficulty(uint32_t nbits, double expected_difficulty) { | ||||
CBlockIndex *block_index = CreateBlockIndexWithNbits(nbits); | CBlockIndex *block_index = CreateBlockIndexWithNbits(nbits); | ||||
Show All 29 Lines |