Changeset View
Changeset View
Standalone View
Standalone View
src/test/coins_tests.cpp
Show First 20 Lines • Show All 176 Lines • ▼ Show 20 Lines | for (unsigned int i = 0; i < NUM_SIMULATION_ITERATIONS; i++) { | ||||
} else { | } else { | ||||
removed_an_entry = true; | removed_an_entry = true; | ||||
coin.Clear(); | coin.Clear(); | ||||
stack.back()->SpendCoin(COutPoint(txid, 0)); | stack.back()->SpendCoin(COutPoint(txid, 0)); | ||||
} | } | ||||
} | } | ||||
// One every 10 iterations, remove a random entry from the cache | // One every 10 iterations, remove a random entry from the cache | ||||
if (InsecureRandRange(10)) { | if (InsecureRandRange(10) == 0) { | ||||
COutPoint out(txids[insecure_rand() % txids.size()], 0); | COutPoint out(txids[insecure_rand() % txids.size()], 0); | ||||
int cacheid = insecure_rand() % stack.size(); | int cacheid = insecure_rand() % stack.size(); | ||||
stack[cacheid]->Uncache(out); | stack[cacheid]->Uncache(out); | ||||
uncached_an_entry |= !stack[cacheid]->HaveCoinInCache(out); | uncached_an_entry |= !stack[cacheid]->HaveCoinInCache(out); | ||||
} | } | ||||
// Once every 1000 iterations and at the end, verify the full cache. | // Once every 1000 iterations and at the end, verify the full cache. | ||||
if (InsecureRandRange(1000) == 1 || | if (InsecureRandRange(1000) == 1 || | ||||
▲ Show 20 Lines • Show All 248 Lines • ▼ Show 20 Lines | for (int64_t i = 0; i < NUM_SIMULATION_ITERATIONS; i++) { | ||||
bool have = stack.back()->HaveCoin(entry.first); | bool have = stack.back()->HaveCoin(entry.first); | ||||
const Coin &coin = stack.back()->AccessCoin(entry.first); | const Coin &coin = stack.back()->AccessCoin(entry.first); | ||||
BOOST_CHECK(have == !coin.IsSpent()); | BOOST_CHECK(have == !coin.IsSpent()); | ||||
BOOST_CHECK(coin == entry.second); | BOOST_CHECK(coin == entry.second); | ||||
} | } | ||||
} | } | ||||
// One every 10 iterations, remove a random entry from the cache | // One every 10 iterations, remove a random entry from the cache | ||||
if (utxoset.size() > 1 && InsecureRandRange(30)) { | if (utxoset.size() > 1 && InsecureRandRange(30) == 0) { | ||||
stack[insecure_rand() % stack.size()]->Uncache( | stack[insecure_rand() % stack.size()]->Uncache( | ||||
FindRandomFrom(utxoset)->first); | FindRandomFrom(utxoset)->first); | ||||
} | } | ||||
if (disconnected_coins.size() > 1 && InsecureRandRange(30)) { | if (disconnected_coins.size() > 1 && InsecureRandRange(30) == 0) { | ||||
stack[insecure_rand() % stack.size()]->Uncache( | stack[insecure_rand() % stack.size()]->Uncache( | ||||
FindRandomFrom(disconnected_coins)->first); | FindRandomFrom(disconnected_coins)->first); | ||||
} | } | ||||
if (duplicate_coins.size() > 1 && InsecureRandRange(30)) { | if (duplicate_coins.size() > 1 && InsecureRandRange(30) == 0) { | ||||
stack[insecure_rand() % stack.size()]->Uncache( | stack[insecure_rand() % stack.size()]->Uncache( | ||||
FindRandomFrom(duplicate_coins)->first); | FindRandomFrom(duplicate_coins)->first); | ||||
} | } | ||||
if (InsecureRandRange(100) == 0) { | if (InsecureRandRange(100) == 0) { | ||||
// Every 100 iterations, flush an intermediate cache | // Every 100 iterations, flush an intermediate cache | ||||
if (stack.size() > 1 && InsecureRandBool() == 0) { | if (stack.size() > 1 && InsecureRandBool() == 0) { | ||||
unsigned int flushIndex = InsecureRandRange(stack.size() - 1); | unsigned int flushIndex = InsecureRandRange(stack.size() - 1); | ||||
▲ Show 20 Lines • Show All 434 Lines • Show Last 20 Lines |