If the random coin in this test has a non-null scriptpubkey, cache->SanityCheck();
fails an assertion because the BOOST_CHECK_THROW
line leaves CCoinsViewCache::cachedCoinsUsage
in a corrupted state: the erroring AddCoin
call decrements the value to 0 even though the coin is still in the cache, then the next SpendCoin
call decrements the value again causing a size_t
underflow.
Move the BOOST_CHECK_THROW
test to its own suite, so that other flush tests are not affected by the caches’s inconsistent state