Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13115589
D8936.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
D8936.diff
View Options
diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp
--- a/src/test/coins_tests.cpp
+++ b/src/test/coins_tests.cpp
@@ -8,6 +8,7 @@
#include <clientversion.h>
#include <script/standard.h>
#include <streams.h>
+#include <txdb.h>
#include <undo.h>
#include <util/strencodings.h>
@@ -110,7 +111,12 @@
//
// During the process, booleans are kept to make sure that the randomized
// operation hits all branches.
-BOOST_AUTO_TEST_CASE(coins_cache_simulation_test) {
+//
+// If fake_best_block is true, assign a random BlockHash to mock the recording
+// of best block on flush. This is necessary when using CCoinsViewDB as the
+// base, otherwise we'll hit an assertion in BatchWrite.
+//
+void SimulationTest(CCoinsView *base, bool fake_best_block) {
// Various coverage trackers.
bool removed_all_caches = false;
bool reached_4_caches = false;
@@ -126,12 +132,10 @@
std::map<COutPoint, Coin> result;
// The cache stack.
- // A CCoinsViewTest at the bottom.
- CCoinsViewTest base;
// A stack of CCoinsViewCaches on top.
std::vector<CCoinsViewCacheTest *> stack;
// 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
// entries.
@@ -227,6 +231,10 @@
if (InsecureRandRange(100) == 0) {
if (stack.size() > 1 && InsecureRandBool() == 0) {
unsigned int flushIndex = InsecureRandRange(stack.size() - 1);
+ if (fake_best_block) {
+ stack[flushIndex]->SetBestBlock(
+ BlockHash(InsecureRand256()));
+ }
BOOST_CHECK(stack[flushIndex]->Flush());
}
}
@@ -234,13 +242,16 @@
// Every 100 iterations, change the cache stack.
if (stack.size() > 0 && InsecureRandBool() == 0) {
// Remove the top cache
+ if (fake_best_block) {
+ stack.back()->SetBestBlock(BlockHash(InsecureRand256()));
+ }
BOOST_CHECK(stack.back()->Flush());
delete stack.back();
stack.pop_back();
}
if (stack.size() == 0 || (stack.size() < 4 && InsecureRandBool())) {
// Add a new cache
- CCoinsView *tip = &base;
+ CCoinsView *tip = base;
if (stack.size() > 0) {
tip = stack.back();
} else {
@@ -272,6 +283,16 @@
BOOST_CHECK(uncached_an_entry);
}
+// Run the above simulation for multiple base types.
+BOOST_AUTO_TEST_CASE(coins_cache_simulation_test) {
+ CCoinsViewTest base;
+ SimulationTest(&base, false);
+
+ CCoinsViewDB db_base{"test", /*nCacheSize*/ 1 << 23, /*fMemory*/ true,
+ /*fWipe*/ false};
+ SimulationTest(&db_base, true);
+}
+
// Store of all necessary tx and undo data for next test
typedef std::map<COutPoint, std::tuple<CTransaction, CTxUndo, Coin>> UtxoData;
UtxoData utxoData;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 1, 11:28 (8 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5185471
Default Alt Text
D8936.diff (3 KB)
Attached To
D8936: tests: have coins simulation test also use CCoinsViewDB
Event Timeline
Log In to Comment