scripted-diff: use insecure_rand256/randrange more

-BEGIN VERIFY SCRIPT-
sed -i "s/\<GetRandHash(/insecure_rand256(/" src/test/*_tests.cpp
sed -i "s/\<GetRand(/insecure_randrange(/" src/test/*_tests.cpp src/test/test_bitcoin.cpp
sed -i 's/\<insecure_rand() % \([0-9]\+\)/insecure_randrange(\1)/g' src/test/*_tests.cpp
-END VERIFY SCRIPT-
This commit is contained in:
Pieter Wuille 2017-05-23 15:28:45 -07:00
parent 1119927df0
commit efee1db21a
15 changed files with 72 additions and 72 deletions

View File

@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE(DoS_bantime)
CTransactionRef RandomOrphan()
{
std::map<uint256, COrphanTx>::iterator it;
it = mapOrphanTransactions.lower_bound(GetRandHash());
it = mapOrphanTransactions.lower_bound(insecure_rand256());
if (it == mapOrphanTransactions.end())
it = mapOrphanTransactions.begin();
return it->second.tx;
@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
CMutableTransaction tx;
tx.vin.resize(1);
tx.vin[0].prevout.n = 0;
tx.vin[0].prevout.hash = GetRandHash();
tx.vin[0].prevout.hash = insecure_rand256();
tx.vin[0].scriptSig << OP_1;
tx.vout.resize(1);
tx.vout[0].nValue = 1*CENT;

View File

@ -30,16 +30,16 @@ static CBlock BuildBlockTestCase() {
block.vtx.resize(3);
block.vtx[0] = MakeTransactionRef(tx);
block.nVersion = 42;
block.hashPrevBlock = GetRandHash();
block.hashPrevBlock = insecure_rand256();
block.nBits = 0x207fffff;
tx.vin[0].prevout.hash = GetRandHash();
tx.vin[0].prevout.hash = insecure_rand256();
tx.vin[0].prevout.n = 0;
block.vtx[1] = MakeTransactionRef(tx);
tx.vin.resize(10);
for (size_t i = 0; i < tx.vin.size(); i++) {
tx.vin[i].prevout.hash = GetRandHash();
tx.vin[i].prevout.hash = insecure_rand256();
tx.vin[i].prevout.n = 0;
}
block.vtx[2] = MakeTransactionRef(tx);
@ -283,7 +283,7 @@ BOOST_AUTO_TEST_CASE(EmptyBlockRoundTripTest)
block.vtx.resize(1);
block.vtx[0] = MakeTransactionRef(std::move(coinbase));
block.nVersion = 42;
block.hashPrevBlock = GetRandHash();
block.hashPrevBlock = insecure_rand256();
block.nBits = 0x207fffff;
bool mutated;
@ -316,7 +316,7 @@ BOOST_AUTO_TEST_CASE(EmptyBlockRoundTripTest)
BOOST_AUTO_TEST_CASE(TransactionsRequestSerializationTest) {
BlockTransactionsRequest req1;
req1.blockhash = GetRandHash();
req1.blockhash = insecure_rand256();
req1.indexes.resize(4);
req1.indexes[0] = 0;
req1.indexes[1] = 1;

View File

@ -463,7 +463,7 @@ BOOST_AUTO_TEST_CASE(merkle_block_4_test_update_none)
static std::vector<unsigned char> RandomData()
{
uint256 r = GetRandHash();
uint256 r = insecure_rand256();
return std::vector<unsigned char>(r.begin(), r.end());
}

View File

@ -160,7 +160,7 @@ void Correct_Queue_range(std::vector<size_t> range)
FakeCheckCheckCompletion::n_calls = 0;
CCheckQueueControl<FakeCheckCheckCompletion> control(small_queue.get());
while (total) {
vChecks.resize(std::min(total, (size_t) GetRand(10)));
vChecks.resize(std::min(total, (size_t) insecure_randrange(10)));
total -= vChecks.size();
control.Add(vChecks);
}
@ -204,7 +204,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Correct_Random)
{
std::vector<size_t> range;
range.reserve(100000/1000);
for (size_t i = 2; i < 100000; i += std::max((size_t)1, (size_t)GetRand(std::min((size_t)1000, ((size_t)100000) - i))))
for (size_t i = 2; i < 100000; i += std::max((size_t)1, (size_t)insecure_randrange(std::min((size_t)1000, ((size_t)100000) - i))))
range.push_back(i);
Correct_Queue_range(range);
}
@ -224,7 +224,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure)
CCheckQueueControl<FailingCheck> control(fail_queue.get());
size_t remaining = i;
while (remaining) {
size_t r = GetRand(10);
size_t r = insecure_randrange(10);
std::vector<FailingCheck> vChecks;
vChecks.reserve(r);
@ -286,7 +286,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck)
{
CCheckQueueControl<UniqueCheck> control(queue.get());
while (total) {
size_t r = GetRand(10);
size_t r = insecure_randrange(10);
std::vector<UniqueCheck> vChecks;
for (size_t k = 0; k < r && total; k++)
vChecks.emplace_back(--total);
@ -320,7 +320,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory)
{
CCheckQueueControl<MemoryCheck> control(queue.get());
while (total) {
size_t r = GetRand(10);
size_t r = insecure_randrange(10);
std::vector<MemoryCheck> vChecks;
for (size_t k = 0; k < r && total; k++) {
total--;

View File

@ -43,7 +43,7 @@ public:
return false;
}
coin = it->second;
if (coin.IsSpent() && insecure_rand() % 2 == 0) {
if (coin.IsSpent() && insecure_randrange(2) == 0) {
// Randomly return false in case of an empty entry.
return false;
}
@ -64,7 +64,7 @@ public:
if (it->second.flags & CCoinsCacheEntry::DIRTY) {
// Same optimization used in CCoinsViewDB is to only write dirty entries.
map_[it->first] = it->second.coin;
if (it->second.coin.IsSpent() && insecure_rand() % 3 == 0) {
if (it->second.coin.IsSpent() && insecure_randrange(3) == 0) {
// Randomly delete empty entries on write.
map_.erase(it->first);
}
@ -139,7 +139,7 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test)
std::vector<uint256> txids;
txids.resize(NUM_SIMULATION_ITERATIONS / 8);
for (unsigned int i = 0; i < txids.size(); i++) {
txids[i] = GetRandHash();
txids[i] = insecure_rand256();
}
for (unsigned int i = 0; i < NUM_SIMULATION_ITERATIONS; i++) {
@ -147,14 +147,14 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test)
{
uint256 txid = txids[insecure_rand() % txids.size()]; // txid we're going to modify in this iteration.
Coin& coin = result[COutPoint(txid, 0)];
const Coin& entry = (insecure_rand() % 500 == 0) ? AccessByTxid(*stack.back(), txid) : stack.back()->AccessCoin(COutPoint(txid, 0));
const Coin& entry = (insecure_randrange(500) == 0) ? AccessByTxid(*stack.back(), txid) : stack.back()->AccessCoin(COutPoint(txid, 0));
BOOST_CHECK(coin == entry);
if (insecure_rand() % 5 == 0 || coin.IsSpent()) {
if (insecure_randrange(5) == 0 || coin.IsSpent()) {
Coin newcoin;
newcoin.out.nValue = insecure_rand();
newcoin.nHeight = 1;
if (insecure_rand() % 16 == 0 && coin.IsSpent()) {
if (insecure_randrange(16) == 0 && coin.IsSpent()) {
newcoin.out.scriptPubKey.assign(1 + (insecure_rand() & 0x3F), OP_RETURN);
BOOST_CHECK(newcoin.out.scriptPubKey.IsUnspendable());
added_an_unspendable_entry = true;
@ -172,7 +172,7 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test)
}
// One every 10 iterations, remove a random entry from the cache
if (insecure_rand() % 10 == 0) {
if (insecure_randrange(10) == 0) {
COutPoint out(txids[insecure_rand() % txids.size()], 0);
int cacheid = insecure_rand() % stack.size();
stack[cacheid]->Uncache(out);
@ -180,7 +180,7 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test)
}
// Once every 1000 iterations and at the end, verify the full cache.
if (insecure_rand() % 1000 == 1 || i == NUM_SIMULATION_ITERATIONS - 1) {
if (insecure_randrange(1000) == 1 || i == NUM_SIMULATION_ITERATIONS - 1) {
for (auto it = result.begin(); it != result.end(); it++) {
bool have = stack.back()->HaveCoin(it->first);
const Coin& coin = stack.back()->AccessCoin(it->first);
@ -198,22 +198,22 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test)
}
}
if (insecure_rand() % 100 == 0) {
if (insecure_randrange(100) == 0) {
// Every 100 iterations, flush an intermediate cache
if (stack.size() > 1 && insecure_rand() % 2 == 0) {
if (stack.size() > 1 && insecure_randrange(2) == 0) {
unsigned int flushIndex = insecure_rand() % (stack.size() - 1);
stack[flushIndex]->Flush();
}
}
if (insecure_rand() % 100 == 0) {
if (insecure_randrange(100) == 0) {
// Every 100 iterations, change the cache stack.
if (stack.size() > 0 && insecure_rand() % 2 == 0) {
if (stack.size() > 0 && insecure_randrange(2) == 0) {
//Remove the top cache
stack.back()->Flush();
delete stack.back();
stack.pop_back();
}
if (stack.size() == 0 || (stack.size() < 4 && insecure_rand() % 2)) {
if (stack.size() == 0 || (stack.size() < 4 && insecure_randrange(2))) {
//Add a new cache
CCoinsView* tip = &base;
if (stack.size() > 0) {
@ -253,7 +253,7 @@ UtxoData utxoData;
UtxoData::iterator FindRandomFrom(const std::set<COutPoint> &utxoSet) {
assert(utxoSet.size());
auto utxoSetIt = utxoSet.lower_bound(COutPoint(GetRandHash(), 0));
auto utxoSetIt = utxoSet.lower_bound(COutPoint(insecure_rand256(), 0));
if (utxoSetIt == utxoSet.end()) {
utxoSetIt = utxoSet.begin();
}
@ -301,7 +301,7 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test)
// 2/20 times create a new coinbase
if (randiter % 20 < 2 || coinbase_coins.size() < 10) {
// 1/10 of those times create a duplicate coinbase
if (insecure_rand() % 10 == 0 && coinbase_coins.size()) {
if (insecure_randrange(10) == 0 && coinbase_coins.size()) {
auto utxod = FindRandomFrom(coinbase_coins);
// Reuse the exact same coinbase
tx = std::get<0>(utxod->second);
@ -411,7 +411,7 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test)
}
// Once every 1000 iterations and at the end, verify the full cache.
if (insecure_rand() % 1000 == 1 || i == NUM_SIMULATION_ITERATIONS - 1) {
if (insecure_randrange(1000) == 1 || i == NUM_SIMULATION_ITERATIONS - 1) {
for (auto it = result.begin(); it != result.end(); it++) {
bool have = stack.back()->HaveCoin(it->first);
const Coin& coin = stack.back()->AccessCoin(it->first);
@ -421,31 +421,31 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test)
}
// One every 10 iterations, remove a random entry from the cache
if (utxoset.size() > 1 && insecure_rand() % 30 == 0) {
if (utxoset.size() > 1 && insecure_randrange(30) == 0) {
stack[insecure_rand() % stack.size()]->Uncache(FindRandomFrom(utxoset)->first);
}
if (disconnected_coins.size() > 1 && insecure_rand() % 30 == 0) {
if (disconnected_coins.size() > 1 && insecure_randrange(30) == 0) {
stack[insecure_rand() % stack.size()]->Uncache(FindRandomFrom(disconnected_coins)->first);
}
if (duplicate_coins.size() > 1 && insecure_rand() % 30 == 0) {
if (duplicate_coins.size() > 1 && insecure_randrange(30) == 0) {
stack[insecure_rand() % stack.size()]->Uncache(FindRandomFrom(duplicate_coins)->first);
}
if (insecure_rand() % 100 == 0) {
if (insecure_randrange(100) == 0) {
// Every 100 iterations, flush an intermediate cache
if (stack.size() > 1 && insecure_rand() % 2 == 0) {
if (stack.size() > 1 && insecure_randrange(2) == 0) {
unsigned int flushIndex = insecure_rand() % (stack.size() - 1);
stack[flushIndex]->Flush();
}
}
if (insecure_rand() % 100 == 0) {
if (insecure_randrange(100) == 0) {
// Every 100 iterations, change the cache stack.
if (stack.size() > 0 && insecure_rand() % 2 == 0) {
if (stack.size() > 0 && insecure_randrange(2) == 0) {
stack.back()->Flush();
delete stack.back();
stack.pop_back();
}
if (stack.size() == 0 || (stack.size() < 4 && insecure_rand() % 2)) {
if (stack.size() == 0 || (stack.size() < 4 && insecure_randrange(2))) {
CCoinsView* tip = &base;
if (stack.size() > 0) {
tip = stack.back();

View File

@ -31,7 +31,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper)
fs::path ph = fs::temp_directory_path() / fs::unique_path();
CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate);
char key = 'k';
uint256 in = GetRandHash();
uint256 in = insecure_rand256();
uint256 res;
// Ensure that we're doing real obfuscation when obfuscate=true
@ -53,11 +53,11 @@ BOOST_AUTO_TEST_CASE(dbwrapper_batch)
CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate);
char key = 'i';
uint256 in = GetRandHash();
uint256 in = insecure_rand256();
char key2 = 'j';
uint256 in2 = GetRandHash();
uint256 in2 = insecure_rand256();
char key3 = 'k';
uint256 in3 = GetRandHash();
uint256 in3 = insecure_rand256();
uint256 res;
CDBBatch batch(dbw);
@ -91,10 +91,10 @@ BOOST_AUTO_TEST_CASE(dbwrapper_iterator)
// The two keys are intentionally chosen for ordering
char key = 'j';
uint256 in = GetRandHash();
uint256 in = insecure_rand256();
BOOST_CHECK(dbw.Write(key, in));
char key2 = 'k';
uint256 in2 = GetRandHash();
uint256 in2 = insecure_rand256();
BOOST_CHECK(dbw.Write(key2, in2));
std::unique_ptr<CDBIterator> it(const_cast<CDBWrapper*>(&dbw)->NewIterator());
@ -132,7 +132,7 @@ BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate)
// Set up a non-obfuscated wrapper to write some initial data.
CDBWrapper* dbw = new CDBWrapper(ph, (1 << 10), false, false, false);
char key = 'k';
uint256 in = GetRandHash();
uint256 in = insecure_rand256();
uint256 res;
BOOST_CHECK(dbw->Write(key, in));
@ -155,7 +155,7 @@ BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate)
BOOST_CHECK(!odbw.IsEmpty()); // There should be existing data
BOOST_CHECK(is_null_key(dbwrapper_private::GetObfuscateKey(odbw))); // The key should be an empty string
uint256 in2 = GetRandHash();
uint256 in2 = insecure_rand256();
uint256 res3;
// Check that we can write successfully
@ -174,7 +174,7 @@ BOOST_AUTO_TEST_CASE(existing_data_reindex)
// Set up a non-obfuscated wrapper to write some initial data.
CDBWrapper* dbw = new CDBWrapper(ph, (1 << 10), false, false, false);
char key = 'k';
uint256 in = GetRandHash();
uint256 in = insecure_rand256();
uint256 res;
BOOST_CHECK(dbw->Write(key, in));
@ -193,7 +193,7 @@ BOOST_AUTO_TEST_CASE(existing_data_reindex)
BOOST_CHECK(!odbw.Read(key, res2));
BOOST_CHECK(!is_null_key(dbwrapper_private::GetObfuscateKey(odbw)));
uint256 in2 = GetRandHash();
uint256 in2 = insecure_rand256();
uint256 res3;
// Check that we can write successfully

View File

@ -134,7 +134,7 @@ BOOST_AUTO_TEST_CASE(siphash)
for (int i = 0; i < 16; ++i) {
uint64_t k1 = ctx.rand64();
uint64_t k2 = ctx.rand64();
uint256 x = GetRandHash();
uint256 x = insecure_rand256();
uint32_t n = ctx.rand32();
uint8_t nb[4];
WriteLE32(nb, n);

View File

@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE(merkle_test)
{
for (int i = 0; i < 32; i++) {
// Try 32 block sizes: all sizes from 0 to 16 inclusive, and then 15 random sizes.
int ntx = (i <= 16) ? i : 17 + (insecure_rand() % 4000);
int ntx = (i <= 16) ? i : 17 + (insecure_randrange(4000));
// Try up to 3 mutations.
for (int mutate = 0; mutate <= 3; mutate++) {
int duplicate1 = mutate >= 1 ? 1 << ctz(ntx) : 0; // The last how many transactions to duplicate first.

View File

@ -372,7 +372,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
while (chainActive.Tip()->nHeight < 209999) {
CBlockIndex* prev = chainActive.Tip();
CBlockIndex* next = new CBlockIndex();
next->phashBlock = new uint256(GetRandHash());
next->phashBlock = new uint256(insecure_rand256());
pcoinsTip->SetBestBlock(next->GetBlockHash());
next->pprev = prev;
next->nHeight = prev->nHeight + 1;
@ -384,7 +384,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
while (chainActive.Tip()->nHeight < 210000) {
CBlockIndex* prev = chainActive.Tip();
CBlockIndex* next = new CBlockIndex();
next->phashBlock = new uint256(GetRandHash());
next->phashBlock = new uint256(insecure_rand256());
pcoinsTip->SetBestBlock(next->GetBlockHash());
next->pprev = prev;
next->nHeight = prev->nHeight + 1;

View File

@ -22,7 +22,7 @@ public:
// flip one bit in one of the hashes - this should break the authentication
void Damage() {
unsigned int n = insecure_rand() % vHash.size();
int bit = insecure_rand() % 256;
int bit = insecure_randrange(256);
*(vHash[n].begin() + (bit>>3)) ^= 1<<(bit&7);
}
};

View File

@ -74,9 +74,9 @@ BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
}
for (int j = 0; j < 1000; j++) {
CBlockIndex *p1 = &blocks[GetRand(10000)];
CBlockIndex *p2 = &blocks[GetRand(10000)];
CBlockIndex *p3 = &blocks[GetRand(10000)];
CBlockIndex *p1 = &blocks[insecure_randrange(10000)];
CBlockIndex *p2 = &blocks[insecure_randrange(10000)];
CBlockIndex *p3 = &blocks[insecure_randrange(10000)];
int64_t tdiff = GetBlockProofEquivalentTime(*p1, *p2, *p3, chainParams->GetConsensus());
BOOST_CHECK_EQUAL(tdiff, p1->GetBlockTime() - p2->GetBlockTime());

View File

@ -206,14 +206,14 @@ BOOST_AUTO_TEST_CASE(PrevectorTestInt)
test.erase(insecure_rand() % test.size());
}
if (((r >> 4) % 8) == 2) {
int new_size = std::max<int>(0, std::min<int>(30, test.size() + (insecure_rand() % 5) - 2));
int new_size = std::max<int>(0, std::min<int>(30, test.size() + (insecure_randrange(5)) - 2));
test.resize(new_size);
}
if (((r >> 7) % 8) == 3) {
test.insert(insecure_rand() % (test.size() + 1), 1 + (insecure_rand() % 2), insecure_rand());
test.insert(insecure_rand() % (test.size() + 1), 1 + (insecure_randrange(2)), insecure_rand());
}
if (((r >> 10) % 8) == 4) {
int del = std::min<int>(test.size(), 1 + (insecure_rand() % 2));
int del = std::min<int>(test.size(), 1 + (insecure_randrange(2)));
int beg = insecure_rand() % (test.size() + 1 - del);
test.erase(beg, beg + del);
}
@ -225,20 +225,20 @@ BOOST_AUTO_TEST_CASE(PrevectorTestInt)
}
if (((r >> 21) % 32) == 7) {
int values[4];
int num = 1 + (insecure_rand() % 4);
int num = 1 + (insecure_randrange(4));
for (int k = 0; k < num; k++) {
values[k] = insecure_rand();
}
test.insert_range(insecure_rand() % (test.size() + 1), values, values + num);
}
if (((r >> 26) % 32) == 8) {
int del = std::min<int>(test.size(), 1 + (insecure_rand() % 4));
int del = std::min<int>(test.size(), 1 + (insecure_randrange(4)));
int beg = insecure_rand() % (test.size() + 1 - del);
test.erase(beg, beg + del);
}
r = insecure_rand();
if (r % 32 == 9) {
test.reserve(insecure_rand() % 32);
test.reserve(insecure_randrange(32));
}
if ((r >> 5) % 64 == 10) {
test.shrink_to_fit();
@ -250,7 +250,7 @@ BOOST_AUTO_TEST_CASE(PrevectorTestInt)
test.clear();
}
if (((r >> 21) % 512) == 12) {
test.assign(insecure_rand() % 32, insecure_rand());
test.assign(insecure_randrange(32), insecure_rand());
}
if (((r >> 15) % 8) == 3) {
test.swap();

View File

@ -89,7 +89,7 @@ uint256 static SignatureHashOld(CScript scriptCode, const CTransaction& txTo, un
void static RandomScript(CScript &script) {
static const opcodetype oplist[] = {OP_FALSE, OP_1, OP_2, OP_3, OP_CHECKSIG, OP_IF, OP_VERIF, OP_RETURN, OP_CODESEPARATOR};
script = CScript();
int ops = (insecure_rand() % 10);
int ops = (insecure_randrange(10));
for (int i=0; i<ops; i++)
script << oplist[insecure_rand() % (sizeof(oplist)/sizeof(oplist[0]))];
}
@ -98,21 +98,21 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle) {
tx.nVersion = insecure_rand();
tx.vin.clear();
tx.vout.clear();
tx.nLockTime = (insecure_rand() % 2) ? insecure_rand() : 0;
int ins = (insecure_rand() % 4) + 1;
int outs = fSingle ? ins : (insecure_rand() % 4) + 1;
tx.nLockTime = (insecure_randrange(2)) ? insecure_rand() : 0;
int ins = (insecure_randrange(4)) + 1;
int outs = fSingle ? ins : (insecure_randrange(4)) + 1;
for (int in = 0; in < ins; in++) {
tx.vin.push_back(CTxIn());
CTxIn &txin = tx.vin.back();
txin.prevout.hash = GetRandHash();
txin.prevout.n = insecure_rand() % 4;
txin.prevout.hash = insecure_rand256();
txin.prevout.n = insecure_randrange(4);
RandomScript(txin.scriptSig);
txin.nSequence = (insecure_rand() % 2) ? insecure_rand() : (unsigned int)-1;
txin.nSequence = (insecure_randrange(2)) ? insecure_rand() : (unsigned int)-1;
}
for (int out = 0; out < outs; out++) {
tx.vout.push_back(CTxOut());
CTxOut &txout = tx.vout.back();
txout.nValue = insecure_rand() % 100000000;
txout.nValue = insecure_randrange(100000000);
RandomScript(txout.scriptPubKey);
}
}

View File

@ -77,7 +77,7 @@ BOOST_AUTO_TEST_CASE(getlocator_test)
// Test 100 random starting points for locators.
for (int n=0; n<100; n++) {
int r = insecure_rand() % 150000;
int r = insecure_randrange(150000);
CBlockIndex* tip = (r < 100000) ? &vBlocksMain[r] : &vBlocksSide[r - 100000];
CBlockLocator locator = chain.GetLocator(tip);

View File

@ -59,7 +59,7 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha
RegisterAllCoreRPCCommands(tableRPC);
ClearDatadirCache();
pathTemp = GetTempPath() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000)));
pathTemp = GetTempPath() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(insecure_randrange(100000)));
fs::create_directories(pathTemp);
ForceSetArg("-datadir", pathTemp.string());
mempool.setSanityCheck(1.0);