Changeset View
Changeset View
Standalone View
Standalone View
src/test/coins_tests.cpp
Show First 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(coins_cache_simulation_test) { | ||||
CCoinsViewTest base; | CCoinsViewTest base; | ||||
// A stack of CCoinsViewCaches on top. | // A stack of CCoinsViewCaches on top. | ||||
std::vector<CCoinsViewCacheTest *> stack; | std::vector<CCoinsViewCacheTest *> stack; | ||||
// Start with one cache. | // Start with one cache. | ||||
stack.push_back(new CCoinsViewCacheTest(&base)); | stack.push_back(new CCoinsViewCacheTest(&base)); | ||||
// Use a limited set of random transaction ids, so we do test overwriting | // Use a limited set of random transaction ids, so we do test overwriting | ||||
// entries. | // entries. | ||||
std::vector<uint256> txids; | std::vector<TxId> txids; | ||||
txids.resize(NUM_SIMULATION_ITERATIONS / 8); | txids.resize(NUM_SIMULATION_ITERATIONS / 8); | ||||
for (size_t i = 0; i < txids.size(); i++) { | for (size_t i = 0; i < txids.size(); i++) { | ||||
txids[i] = InsecureRand256(); | txids[i] = TxId(InsecureRand256()); | ||||
} | } | ||||
for (unsigned int i = 0; i < NUM_SIMULATION_ITERATIONS; i++) { | for (unsigned int i = 0; i < NUM_SIMULATION_ITERATIONS; i++) { | ||||
// Do a random modification. | // Do a random modification. | ||||
{ | { | ||||
// txid we're going to modify in this iteration. | // txid we're going to modify in this iteration. | ||||
uint256 txid = txids[InsecureRandRange(txids.size())]; | TxId txid = txids[InsecureRandRange(txids.size())]; | ||||
Coin &coin = result[COutPoint(txid, 0)]; | Coin &coin = result[COutPoint(txid, 0)]; | ||||
const Coin &entry = | const Coin &entry = | ||||
(InsecureRandRange(500) == 0) | (InsecureRandRange(500) == 0) | ||||
? AccessByTxid(*stack.back(), txid) | ? AccessByTxid(*stack.back(), txid) | ||||
: stack.back()->AccessCoin(COutPoint(txid, 0)); | : stack.back()->AccessCoin(COutPoint(txid, 0)); | ||||
BOOST_CHECK(coin == entry); | BOOST_CHECK(coin == entry); | ||||
if (InsecureRandRange(5) == 0 || coin.IsSpent()) { | if (InsecureRandRange(5) == 0 || coin.IsSpent()) { | ||||
▲ Show 20 Lines • Show All 741 Lines • Show Last 20 Lines |