mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-12 23:26:59 +02:00
Use arith_uint256 where necessary
Also add conversion from/to uint256 where needed.
This commit is contained in:
@ -49,12 +49,12 @@ BOOST_AUTO_TEST_CASE(getlocator_test)
|
||||
std::vector<uint256> vHashMain(100000);
|
||||
std::vector<CBlockIndex> vBlocksMain(100000);
|
||||
for (unsigned int i=0; i<vBlocksMain.size(); i++) {
|
||||
vHashMain[i] = i; // Set the hash equal to the height, so we can quickly check the distances.
|
||||
vHashMain[i] = ArithToUint256(i); // Set the hash equal to the height, so we can quickly check the distances.
|
||||
vBlocksMain[i].nHeight = i;
|
||||
vBlocksMain[i].pprev = i ? &vBlocksMain[i - 1] : NULL;
|
||||
vBlocksMain[i].phashBlock = &vHashMain[i];
|
||||
vBlocksMain[i].BuildSkip();
|
||||
BOOST_CHECK_EQUAL((int)vBlocksMain[i].GetBlockHash().GetLow64(), vBlocksMain[i].nHeight);
|
||||
BOOST_CHECK_EQUAL((int)UintToArith256(vBlocksMain[i].GetBlockHash()).GetLow64(), vBlocksMain[i].nHeight);
|
||||
BOOST_CHECK(vBlocksMain[i].pprev == NULL || vBlocksMain[i].nHeight == vBlocksMain[i].pprev->nHeight + 1);
|
||||
}
|
||||
|
||||
@ -62,12 +62,12 @@ BOOST_AUTO_TEST_CASE(getlocator_test)
|
||||
std::vector<uint256> vHashSide(50000);
|
||||
std::vector<CBlockIndex> vBlocksSide(50000);
|
||||
for (unsigned int i=0; i<vBlocksSide.size(); i++) {
|
||||
vHashSide[i] = i + 50000 + (uint256(1) << 128); // Add 1<<128 to the hashes, so GetLow64() still returns the height.
|
||||
vHashSide[i] = ArithToUint256(i + 50000 + (arith_uint256(1) << 128)); // Add 1<<128 to the hashes, so GetLow64() still returns the height.
|
||||
vBlocksSide[i].nHeight = i + 50000;
|
||||
vBlocksSide[i].pprev = i ? &vBlocksSide[i - 1] : &vBlocksMain[49999];
|
||||
vBlocksSide[i].phashBlock = &vHashSide[i];
|
||||
vBlocksSide[i].BuildSkip();
|
||||
BOOST_CHECK_EQUAL((int)vBlocksSide[i].GetBlockHash().GetLow64(), vBlocksSide[i].nHeight);
|
||||
BOOST_CHECK_EQUAL((int)UintToArith256(vBlocksSide[i].GetBlockHash()).GetLow64(), vBlocksSide[i].nHeight);
|
||||
BOOST_CHECK(vBlocksSide[i].pprev == NULL || vBlocksSide[i].nHeight == vBlocksSide[i].pprev->nHeight + 1);
|
||||
}
|
||||
|
||||
@ -87,13 +87,13 @@ BOOST_AUTO_TEST_CASE(getlocator_test)
|
||||
|
||||
// Entries 1 through 11 (inclusive) go back one step each.
|
||||
for (unsigned int i = 1; i < 12 && i < locator.vHave.size() - 1; i++) {
|
||||
BOOST_CHECK_EQUAL(locator.vHave[i].GetLow64(), tip->nHeight - i);
|
||||
BOOST_CHECK_EQUAL(UintToArith256(locator.vHave[i]).GetLow64(), tip->nHeight - i);
|
||||
}
|
||||
|
||||
// The further ones (excluding the last one) go back with exponential steps.
|
||||
unsigned int dist = 2;
|
||||
for (unsigned int i = 12; i < locator.vHave.size() - 1; i++) {
|
||||
BOOST_CHECK_EQUAL(locator.vHave[i - 1].GetLow64() - locator.vHave[i].GetLow64(), dist);
|
||||
BOOST_CHECK_EQUAL(UintToArith256(locator.vHave[i - 1]).GetLow64() - UintToArith256(locator.vHave[i]).GetLow64(), dist);
|
||||
dist *= 2;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user