test: do not return spent coins from `CCoinsViewTest::GetCoin`
What changed, and why it matters
This is a test-only cleanup. It fixes a fake test helper so it no longer returns already-spent coins, matching how the real Bitcoin Core coin database works. It does not change production code, so it cannot directly affect live Bitcoin nodes or user funds.
No security action required. Treat as normal code-quality/test-maintenance review.
Security signals we found
No production code changed
Test-only mock behavior correction
Removes random return of spent coins that violated documented contract
Evidence from the diff
The commit modifies CCoinsViewTest::GetCoin() in src/test/coins_tests.cpp. Previously the mock implementation could return spent coins based on a random coin flip (m_rng.randbool()), with a TODO noting this was incorrect. The patch removes the random behavior and only returns unspent coins, aligning the test mock with production GetCoin() semantics in CCoinsViewCache and CCoinsViewDB. This is purely a test-harness correctness fix.
Changed components
src/test/coins_tests.cppCCoinsViewTest test mockInspect captured patch +1 / −5
diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp
index 6396fce6..63024054 100644
--- a/src/test/coins_tests.cpp
+++ b/src/test/coins_tests.cpp
@@ -48,11 +48,7 @@ public:
std::optional<Coin> GetCoin(const COutPoint& outpoint) const override
{
- if (auto it{map_.find(outpoint)}; it != map_.end()) {
- if (!it->second.IsSpent() || m_rng.randbool()) {
- return it->second; // TODO spent coins shouldn't be returned
- }
- }
+ if (auto it{map_.find(outpoint)}; it != map_.end() && !it->second.IsSpent()) return it->second;
return std::nullopt;
}
Why this scored 16/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.