Skip to content

Commit 6488f24

Browse files
committed
[Tests] Fix arith in pedersen_hash_/skiplist_/pmt_/transaction_tests
1 parent 86e177b commit 6488f24

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

src/arith_uint256.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,5 +384,6 @@ class arith_uint512 : public base_uint<512> {
384384
/** End classes definitions */
385385

386386
const arith_uint256 ARITH_UINT256_ZERO = arith_uint256();
387+
const arith_uint256 ARITH_UINT256_ONE = arith_uint256(1);
387388

388389
#endif // BITCOIN_UINT256_H

src/test/librust/pedersen_hash_tests.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
// Distributed under the MIT software license, see the accompanying
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

6+
#include "test/test_pivx.h"
7+
8+
#include "arith_uint256.h"
69
#include "uint256.h"
710
#include "utilstrencodings.h"
8-
#include "test/test_pivx.h"
911

1012
#include <boost/test/unit_test.hpp>
1113
#include <librustzcash.h>
@@ -26,7 +28,7 @@ BOOST_AUTO_TEST_CASE(pedersen_hash_testvectors)
2628
BOOST_CHECK(result == expected_result);
2729

2830
// Simple bad scenario check
29-
const uint256 c = uint256(1) + a;
31+
const uint256& c = ArithToUint256(ARITH_UINT256_ONE + UintToArith256(a));
3032
result.SetNull();
3133
librustzcash_merkle_hash(25, c.begin(), b.begin(), result.begin());
3234
BOOST_CHECK(result != expected_result);

src/test/pmt_tests.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ class CPartialMerkleTreeTester : public CPartialMerkleTree
2323
void Damage() {
2424
unsigned int n = InsecureRandRange(vHash.size());
2525
int bit = InsecureRandBits(8);
26-
uint256 &hash = vHash[n];
27-
hash ^= ((uint256)1 << bit);
26+
*(vHash[n].begin() + (bit>>3)) ^= 1<<(bit&7);
2827
}
2928
};
3029

src/test/skiplist_tests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,25 @@ BOOST_AUTO_TEST_CASE(getlocator_test)
5151
std::vector<uint256> vHashMain(100000);
5252
std::vector<CBlockIndex> vBlocksMain(100000);
5353
for (unsigned int i=0; i<vBlocksMain.size(); i++) {
54-
vHashMain[i] = i; // Set the hash equal to the height, so we can quickly check the distances.
54+
vHashMain[i] = ArithToUint256(i); // Set the hash equal to the height, so we can quickly check the distances.
5555
vBlocksMain[i].nHeight = i;
5656
vBlocksMain[i].pprev = i ? &vBlocksMain[i - 1] : nullptr;
5757
vBlocksMain[i].phashBlock = &vHashMain[i];
5858
vBlocksMain[i].BuildSkip();
59-
BOOST_CHECK_EQUAL((int)vBlocksMain[i].GetBlockHash().GetLow64(), vBlocksMain[i].nHeight);
59+
BOOST_CHECK_EQUAL((int)UintToArith256(vBlocksMain[i].GetBlockHash()).GetLow64(), vBlocksMain[i].nHeight);
6060
BOOST_CHECK(vBlocksMain[i].pprev == nullptr || vBlocksMain[i].nHeight == vBlocksMain[i].pprev->nHeight + 1);
6161
}
6262

6363
// Build a branch that splits off at block 49999, 50000 blocks long.
6464
std::vector<uint256> vHashSide(50000);
6565
std::vector<CBlockIndex> vBlocksSide(50000);
6666
for (unsigned int i=0; i<vBlocksSide.size(); i++) {
67-
vHashSide[i] = i + 50000 + (uint256(1) << 128); // Add 1<<128 to the hashes, so GetLow64() still returns the height.
67+
vHashSide[i] = ArithToUint256(i + 50000 + (ARITH_UINT256_ONE << 128)); // Add 1<<128 to the hashes, so GetLow64() still returns the height.
6868
vBlocksSide[i].nHeight = i + 50000;
6969
vBlocksSide[i].pprev = i ? &vBlocksSide[i - 1] : &vBlocksMain[49999];
7070
vBlocksSide[i].phashBlock = &vHashSide[i];
7171
vBlocksSide[i].BuildSkip();
72-
BOOST_CHECK_EQUAL((int)vBlocksSide[i].GetBlockHash().GetLow64(), vBlocksSide[i].nHeight);
72+
BOOST_CHECK_EQUAL((int)UintToArith256(vBlocksSide[i].GetBlockHash()).GetLow64(), vBlocksSide[i].nHeight);
7373
BOOST_CHECK(vBlocksSide[i].pprev == nullptr || vBlocksSide[i].nHeight == vBlocksSide[i].pprev->nHeight + 1);
7474
}
7575

@@ -89,13 +89,13 @@ BOOST_AUTO_TEST_CASE(getlocator_test)
8989

9090
// Entries 1 through 11 (inclusive) go back one step each.
9191
for (unsigned int i = 1; i < 12 && i < locator.vHave.size() - 1; i++) {
92-
BOOST_CHECK_EQUAL(locator.vHave[i].GetLow64(), tip->nHeight - i);
92+
BOOST_CHECK_EQUAL(UintToArith256(locator.vHave[i]).GetLow64(), tip->nHeight - i);
9393
}
9494

9595
// The further ones (excluding the last one) go back with exponential steps.
9696
unsigned int dist = 2;
9797
for (unsigned int i = 12; i < locator.vHave.size() - 1; i++) {
98-
BOOST_CHECK_EQUAL(locator.vHave[i - 1].GetLow64() - locator.vHave[i].GetLow64(), dist);
98+
BOOST_CHECK_EQUAL(UintToArith256(locator.vHave[i - 1]).GetLow64() - UintToArith256(locator.vHave[i]).GetLow64(), dist);
9999
dist *= 2;
100100
}
101101
}

src/test/transaction_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ BOOST_AUTO_TEST_CASE(tx_valid)
126126
break;
127127
}
128128

129-
mapprevOutScriptPubKeys[COutPoint(uint256(vinput[0].get_str()), vinput[1].get_int())] = ParseScript(vinput[2].get_str());
129+
mapprevOutScriptPubKeys[COutPoint(uint256S(vinput[0].get_str()), vinput[1].get_int())] = ParseScript(vinput[2].get_str());
130130
}
131131
if (!fValid)
132132
{
@@ -202,7 +202,7 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
202202
break;
203203
}
204204

205-
mapprevOutScriptPubKeys[COutPoint(uint256(vinput[0].get_str()), vinput[1].get_int())] = ParseScript(vinput[2].get_str());
205+
mapprevOutScriptPubKeys[COutPoint(uint256S(vinput[0].get_str()), vinput[1].get_int())] = ParseScript(vinput[2].get_str());
206206
}
207207
if (!fValid)
208208
{

0 commit comments

Comments
 (0)