aboutsummaryrefslogtreecommitdiff
path: root/src/test/pmt_tests.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/pmt_tests.cpp')
-rw-r--r--src/test/pmt_tests.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/test/pmt_tests.cpp b/src/test/pmt_tests.cpp
index edecf70c6f..2ba48d717a 100644
--- a/src/test/pmt_tests.cpp
+++ b/src/test/pmt_tests.cpp
@@ -17,22 +17,26 @@
class CPartialMerkleTreeTester : public CPartialMerkleTree
{
public:
+ CPartialMerkleTreeTester(FastRandomContext& rng) : m_rng{rng} {}
+
// flip one bit in one of the hashes - this should break the authentication
void Damage() {
- unsigned int n = InsecureRandRange(vHash.size());
- int bit = InsecureRandBits(8);
+ unsigned int n = m_rng.randrange(vHash.size());
+ int bit = m_rng.randbits(8);
*(vHash[n].begin() + (bit>>3)) ^= 1<<(bit&7);
}
+
+ FastRandomContext& m_rng;
};
BOOST_FIXTURE_TEST_SUITE(pmt_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(pmt_test1)
{
- static const unsigned int nTxCounts[] = {1, 4, 7, 17, 56, 100, 127, 256, 312, 513, 1000, 4095};
+ static const unsigned int tx_counts[] = {1, 4, 7, 17, 56, 100, 127, 256, 312, 513, 1000, 4095};
for (int i = 0; i < 12; i++) {
- unsigned int nTx = nTxCounts[i];
+ unsigned int nTx = tx_counts[i];
// build a block with some dummy transactions
CBlock block;
@@ -59,7 +63,7 @@ BOOST_AUTO_TEST_CASE(pmt_test1)
std::vector<bool> vMatch(nTx, false);
std::vector<uint256> vMatchTxid1;
for (unsigned int j=0; j<nTx; j++) {
- bool fInclude = InsecureRandBits(att / 2) == 0;
+ bool fInclude = m_rng.randbits(att / 2) == 0;
vMatch[j] = fInclude;
if (fInclude)
vMatchTxid1.push_back(vTxid[j]);
@@ -77,7 +81,7 @@ BOOST_AUTO_TEST_CASE(pmt_test1)
BOOST_CHECK(ss.size() <= 10 + (258*n+7)/8);
// deserialize into a tester copy
- CPartialMerkleTreeTester pmt2;
+ CPartialMerkleTreeTester pmt2{m_rng};
ss >> pmt2;
// extract merkle root and matched txids from copy