| 46 | }; |
| 47 | |
| 48 | BOOST_AUTO_TEST_CASE(PeginSpent_validity) |
| 49 | { |
| 50 | CCoinsViewTester coins; |
| 51 | CCoinsViewCache coinsCache(&coins); |
| 52 | Coin ret; |
| 53 | |
| 54 | //Basic insert of blank outpoint pair, blank COutPoint allows for checking coinsCache |
| 55 | |
| 56 | std::pair<uint256, COutPoint> outpoint = std::make_pair(GetRandHash(), COutPoint(GetRandHash(), 42)); |
| 57 | BOOST_CHECK(!coinsCache.GetCoin(outpoint.second, ret)); |
| 58 | |
| 59 | //Checking for pegin spentness should not create an entry |
| 60 | BOOST_CHECK(!coinsCache.IsPeginSpent(outpoint)); |
| 61 | BOOST_CHECK(coins.IsPeginSpentCalled); |
| 62 | coins.IsPeginSpentCalled = false; |
| 63 | BOOST_CHECK(!coinsCache.IsPeginSpent(outpoint)); |
| 64 | BOOST_CHECK(!coins.IsPeginSpentCalled); |
| 65 | |
| 66 | coinsCache.SetPeginSpent(outpoint, true); |
| 67 | BOOST_CHECK(coinsCache.IsPeginSpent(outpoint)); |
| 68 | coinsCache.SetPeginSpent(outpoint, false); |
| 69 | BOOST_CHECK(!coinsCache.IsPeginSpent(outpoint)); |
| 70 | coinsCache.SetPeginSpent(outpoint, true); |
| 71 | BOOST_CHECK(coinsCache.IsPeginSpent(outpoint)); |
| 72 | |
| 73 | //Check for slightly similar non-existent entries |
| 74 | std::pair<uint256, COutPoint> outpoint2(outpoint); |
| 75 | outpoint2.second.n = 0; |
| 76 | BOOST_CHECK(!coinsCache.IsPeginSpent(outpoint2)); |
| 77 | |
| 78 | CCoinsMap mapCoins; |
| 79 | CCoinsCacheEntry entry; |
| 80 | std::pair<uint256, COutPoint> outpoint3(std::make_pair(GetRandHash(), COutPoint(GetRandHash(), 42))); |
| 81 | |
| 82 | //Attempt batch write of non-dirty pegin, no effect |
| 83 | entry.flags = CCoinsCacheEntry::PEGIN; |
| 84 | entry.peginSpent = true; |
| 85 | mapCoins.insert(std::make_pair(outpoint3, entry)); |
| 86 | coinsCache.BatchWrite(mapCoins, uint256()); |
| 87 | //Check for effect |
| 88 | coins.IsPeginSpentCalled = false; |
| 89 | BOOST_CHECK(!coinsCache.IsPeginSpent(outpoint3)); |
| 90 | BOOST_CHECK(coins.IsPeginSpentCalled); |
| 91 | BOOST_CHECK(mapCoins.size() == 0); |
| 92 | |
| 93 | //Write again with pegin, dirty && fresh flags, but unspent. No effect. |
| 94 | entry.peginSpent = false; |
| 95 | entry.flags |= CCoinsCacheEntry::DIRTY | CCoinsCacheEntry::FRESH; |
| 96 | mapCoins.insert(std::make_pair(outpoint3, entry)); |
| 97 | coinsCache.BatchWrite(mapCoins, uint256()); |
| 98 | //Check for effect |
| 99 | coins.IsPeginSpentCalled = false; |
| 100 | BOOST_CHECK(!coinsCache.IsPeginSpent(outpoint3)); |
| 101 | BOOST_CHECK(coins.IsPeginSpentCalled); |
| 102 | BOOST_CHECK(mapCoins.size() == 0); |
| 103 | |
| 104 | //Re-mark as spent. It's super effective. |
| 105 | entry.peginSpent = true; |
nothing calls this directly
no test coverage detected