diff options
author | Pieter Wuille <pieter@wuille.net> | 2023-02-01 18:28:08 -0500 |
---|---|---|
committer | Pieter Wuille <pieter@wuille.net> | 2023-02-01 23:14:12 -0500 |
commit | b0ff31084006ac7d4a7afba3190ca75f5f8441af (patch) | |
tree | 909dc06de479080bab43ca090efaa8ea2b359b9c /src/test | |
parent | 3c9cea1340fd1358d6854209d782922864945eb0 (diff) |
Add CCoinsViewCache::SanityCheck() and use it in fuzz test
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/fuzz/coinscache_sim.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/test/fuzz/coinscache_sim.cpp b/src/test/fuzz/coinscache_sim.cpp index c3f732f075..b794888ca2 100644 --- a/src/test/fuzz/coinscache_sim.cpp +++ b/src/test/fuzz/coinscache_sim.cpp @@ -51,7 +51,8 @@ struct PrecomputedData const uint8_t ser[4] = {uint8_t(i), uint8_t(i >> 8), uint8_t(i >> 16), uint8_t(i >> 24)}; uint256 hash; CSHA256().Write(PREFIX_S, 1).Write(ser, sizeof(ser)).Finalize(hash.begin()); - /* Convert hash to scriptPubkeys. */ + /* Convert hash to scriptPubkeys (of different lengths, so SanityCheck's cached memory + * usage check has a chance to detect mismatches). */ switch (i % 5U) { case 0: /* P2PKH */ coins[i].out.scriptPubKey.resize(25); @@ -381,6 +382,7 @@ FUZZ_TARGET(coinscache_sim) [&]() { // Remove a cache level. // Apply to real caches (this reduces caches.size(), implicitly doing the same on the simulation data). + caches.back()->SanityCheck(); caches.pop_back(); }, @@ -420,6 +422,11 @@ FUZZ_TARGET(coinscache_sim) ); } + // Sanity check all the remaining caches + for (const auto& cache : caches) { + cache->SanityCheck(); + } + // Full comparison between caches and simulation data, from bottom to top, // as AccessCoin on a higher cache may affect caches below it. for (unsigned sim_idx = 1; sim_idx <= caches.size(); ++sim_idx) { |