Changeset View
Changeset View
Standalone View
Standalone View
src/test/blockindex_tests.cpp
Show First 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | for (BlockValidity validity : validityValues) { | ||||
} | } | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(get_block_hash) { | BOOST_AUTO_TEST_CASE(get_block_hash) { | ||||
CBlockIndex index = CBlockIndex(); | CBlockIndex index = CBlockIndex(); | ||||
/* Test with all 0 hash */ | /* Test with all 0 hash */ | ||||
const uint256 zeroHash = uint256(); | const BlockHash zeroHash = BlockHash(); | ||||
index.phashBlock = &zeroHash; | index.phashBlock = &zeroHash; | ||||
uint256 hash = index.GetBlockHash(); | BlockHash hash = index.GetBlockHash(); | ||||
BOOST_CHECK(hash == zeroHash); | BOOST_CHECK(hash == zeroHash); | ||||
/* Test with a random hash */ | /* Test with a random hash */ | ||||
std::vector<uint8_t> hashBytes(32); | uint256 hashBytes; | ||||
std::generate(hashBytes.begin(), hashBytes.end(), | std::generate(hashBytes.begin(), hashBytes.end(), | ||||
[]() { return uint8_t(rand() % 255); }); | []() { return uint8_t(rand() % 255); }); | ||||
const uint256 randomHash = uint256(hashBytes); | const BlockHash randomHash = BlockHash(hashBytes); | ||||
index.phashBlock = &randomHash; | index.phashBlock = &randomHash; | ||||
hash = index.GetBlockHash(); | hash = index.GetBlockHash(); | ||||
BOOST_CHECK(hash == randomHash); | BOOST_CHECK(hash == randomHash); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(received_time) { | BOOST_AUTO_TEST_CASE(received_time) { | ||||
// Set to UINT32_MAX because that's the maximum value header.nTime can hold | // Set to UINT32_MAX because that's the maximum value header.nTime can hold | ||||
const int64_t expectedBlockTime = std::numeric_limits<uint32_t>::max(); | const int64_t expectedBlockTime = std::numeric_limits<uint32_t>::max(); | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(median_time_past) { | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(to_string) { | BOOST_AUTO_TEST_CASE(to_string) { | ||||
CBlockHeader header = CBlockHeader(); | CBlockHeader header = CBlockHeader(); | ||||
header.hashMerkleRoot = uint256(); | header.hashMerkleRoot = uint256(); | ||||
CBlockIndex index = CBlockIndex(header); | CBlockIndex index = CBlockIndex(header); | ||||
const uint256 hashBlock = uint256(); | const BlockHash hashBlock = BlockHash(); | ||||
index.phashBlock = &hashBlock; | index.phashBlock = &hashBlock; | ||||
index.nHeight = 123; | index.nHeight = 123; | ||||
CBlockIndex indexPrev = CBlockIndex(); | CBlockIndex indexPrev = CBlockIndex(); | ||||
std::string expectedString = ""; | std::string expectedString = ""; | ||||
std::string indexString = ""; | std::string indexString = ""; | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(to_string) { | ||||
/* CASE 5 : set some block hash */ | /* CASE 5 : set some block hash */ | ||||
expectedString = strprintf( | expectedString = strprintf( | ||||
"CBlockIndex(pprev=%p, nHeight=2147483647, " | "CBlockIndex(pprev=%p, nHeight=2147483647, " | ||||
"merkle=" | "merkle=" | ||||
"0000000000000000000000000000000000000000000000000123456789abcdef, " | "0000000000000000000000000000000000000000000000000123456789abcdef, " | ||||
"hashBlock=" | "hashBlock=" | ||||
"000000000000000000000000000000000000000000000000fedcba9876543210)", | "000000000000000000000000000000000000000000000000fedcba9876543210)", | ||||
&indexPrev); | &indexPrev); | ||||
const uint256 emptyHashBlock = uint256S("FEDCBA9876543210"); | const BlockHash emptyHashBlock = BlockHash::fromHex("FEDCBA9876543210"); | ||||
index.phashBlock = &emptyHashBlock; | index.phashBlock = &emptyHashBlock; | ||||
indexString = index.ToString(); | indexString = index.ToString(); | ||||
BOOST_CHECK_EQUAL(indexString, expectedString); | BOOST_CHECK_EQUAL(indexString, expectedString); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(index_validity_tests) { | BOOST_AUTO_TEST_CASE(index_validity_tests) { | ||||
CBlockIndex index; | CBlockIndex index; | ||||
▲ Show 20 Lines • Show All 159 Lines • Show Last 20 Lines |