Skip to content

Commit 633aa16

Browse files
domob1812galpHub
authored andcommitted
Mempool tests for lookup.
This extends the mempool unit tests to explicitly verify lookup both by normal and bare txid, the two exists calls (with normal and bare txid) as well as the new lookupOutpoint method.
1 parent 782f37a commit 633aa16

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

divi/src/test/mempool_tests.cpp

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
163163
removed.clear();
164164
}
165165

166-
BOOST_AUTO_TEST_CASE(MempoolIndexByBareTxid)
166+
BOOST_AUTO_TEST_CASE(MempoolDirectLookup)
167167
{
168168
CTransaction tx;
169169
std::list<CTransaction> removed;
@@ -172,14 +172,62 @@ BOOST_AUTO_TEST_CASE(MempoolIndexByBareTxid)
172172

173173
BOOST_CHECK(testPool.lookupBareTxid(txParent.GetBareTxid(), tx));
174174
BOOST_CHECK(tx.GetHash() == txParent.GetHash());
175+
BOOST_CHECK(testPool.lookup(txParent.GetHash(), tx));
176+
BOOST_CHECK(tx.GetHash() == txParent.GetHash());
177+
178+
BOOST_CHECK(!testPool.lookup(txParent.GetBareTxid(), tx));
175179
BOOST_CHECK(!testPool.lookupBareTxid(txParent.GetHash(), tx));
176180

177181
testPool.remove(txParent, removed, true);
182+
BOOST_CHECK(!testPool.lookup(txParent.GetHash(), tx));
183+
BOOST_CHECK(!testPool.lookup(txChild[0].GetHash(), tx));
184+
BOOST_CHECK(!testPool.lookup(txGrandChild[0].GetHash(), tx));
178185
BOOST_CHECK(!testPool.lookupBareTxid(txParent.GetBareTxid(), tx));
179186
BOOST_CHECK(!testPool.lookupBareTxid(txChild[0].GetBareTxid(), tx));
180187
BOOST_CHECK(!testPool.lookupBareTxid(txGrandChild[0].GetBareTxid(), tx));
181188
}
182189

190+
BOOST_AUTO_TEST_CASE(MempoolOutpointLookup)
191+
{
192+
CTransaction tx;
193+
CCoins c;
194+
195+
AddAll();
196+
CCoinsViewMemPool viewPool(&coins, testPool);
197+
198+
BOOST_CHECK(testPool.lookupOutpoint(txParent.GetHash(), tx));
199+
BOOST_CHECK(!testPool.lookupOutpoint(txParent.GetBareTxid(), tx));
200+
BOOST_CHECK(testPool.lookupOutpoint(txChild[0].GetHash(), tx));
201+
BOOST_CHECK(!testPool.lookupOutpoint(txChild[0].GetBareTxid(), tx));
202+
203+
BOOST_CHECK(viewPool.HaveCoins(txParent.GetHash()));
204+
BOOST_CHECK(viewPool.GetCoins(txParent.GetHash(), c));
205+
BOOST_CHECK(!viewPool.HaveCoins(txParent.GetBareTxid()));
206+
BOOST_CHECK(!viewPool.GetCoins(txParent.GetBareTxid(), c));
207+
208+
BOOST_CHECK(viewPool.HaveCoins(txChild[0].GetHash()));
209+
BOOST_CHECK(viewPool.GetCoins(txChild[0].GetHash(), c));
210+
BOOST_CHECK(!viewPool.HaveCoins(txChild[0].GetBareTxid()));
211+
BOOST_CHECK(!viewPool.GetCoins(txChild[0].GetBareTxid(), c));
212+
}
213+
214+
BOOST_AUTO_TEST_CASE(MempoolExists)
215+
{
216+
CTransaction tx;
217+
std::list<CTransaction> removed;
218+
219+
AddAll();
220+
221+
BOOST_CHECK(testPool.exists(txParent.GetHash()));
222+
BOOST_CHECK(!testPool.exists(txParent.GetBareTxid()));
223+
BOOST_CHECK(!testPool.existsBareTxid(txParent.GetHash()));
224+
BOOST_CHECK(testPool.existsBareTxid(txParent.GetBareTxid()));
225+
226+
testPool.remove(txParent, removed, true);
227+
BOOST_CHECK(!testPool.exists(txParent.GetHash()));
228+
BOOST_CHECK(!testPool.existsBareTxid(txParent.GetBareTxid()));
229+
}
230+
183231
BOOST_AUTO_TEST_CASE(MempoolSpentIndex)
184232
{
185233
spentIndex = true;

0 commit comments

Comments
 (0)