Port anchors_flush_test to gtest suite CoinsTests

This commit is contained in:
sasha 2022-04-26 15:10:22 -07:00
parent b558046cd3
commit c055777839
2 changed files with 52 additions and 44 deletions

View File

@ -666,4 +666,55 @@ TEST(CoinsTests, NullifiersTest)
CCoinsViewCacheTest cache3(&base);
checkNullifierCache(cache3, txWithNullifiers, false);
}
}
template<typename Tree> void anchorsFlushImpl(ShieldedType type)
{
CCoinsViewTest base;
uint256 newrt;
{
CCoinsViewCacheTest cache(&base);
Tree tree;
EXPECT_TRUE(GetAnchorAt(cache, cache.GetBestAnchor(type), tree));
AppendRandomLeaf(tree);
newrt = tree.root();
cache.PushAnchor(tree);
cache.Flush();
}
{
CCoinsViewCacheTest cache(&base);
Tree tree;
EXPECT_TRUE(GetAnchorAt(cache, cache.GetBestAnchor(type), tree));
// Get the cached entry.
EXPECT_TRUE(GetAnchorAt(cache, cache.GetBestAnchor(type), tree));
uint256 check_rt = tree.root();
EXPECT_TRUE(check_rt == newrt);
}
}
TEST(CoinsTests,AnchorsFlushTest)
{
LoadProofParameters();
{
SCOPED_TRACE("Sprout");
anchorsFlushImpl<SproutMerkleTree>(SPROUT);
}
{
SCOPED_TRACE("Sapling");
anchorsFlushImpl<SaplingMerkleTree>(SAPLING);
}
{
SCOPED_TRACE("Orchard");
anchorsFlushImpl<OrchardMerkleFrontier>(ORCHARD);
}
}

View File

@ -350,49 +350,6 @@ void checkNullifierCache(const CCoinsViewCacheTest &cache, const TxWithNullifier
BOOST_CHECK(containsOrchardNullifier == shouldBeInCache);
}
template<typename Tree> void anchorsFlushImpl(ShieldedType type)
{
CCoinsViewTest base;
uint256 newrt;
{
CCoinsViewCacheTest cache(&base);
Tree tree;
BOOST_CHECK(GetAnchorAt(cache, cache.GetBestAnchor(type), tree));
AppendRandomLeaf(tree);
newrt = tree.root();
cache.PushAnchor(tree);
cache.Flush();
}
{
CCoinsViewCacheTest cache(&base);
Tree tree;
BOOST_CHECK(GetAnchorAt(cache, cache.GetBestAnchor(type), tree));
// Get the cached entry.
BOOST_CHECK(GetAnchorAt(cache, cache.GetBestAnchor(type), tree));
uint256 check_rt = tree.root();
BOOST_CHECK(check_rt == newrt);
}
}
BOOST_AUTO_TEST_CASE(anchors_flush_test)
{
BOOST_TEST_CONTEXT("Sprout") {
anchorsFlushImpl<SproutMerkleTree>(SPROUT);
}
BOOST_TEST_CONTEXT("Sapling") {
anchorsFlushImpl<SaplingMerkleTree>(SAPLING);
}
BOOST_TEST_CONTEXT("Orchard") {
anchorsFlushImpl<OrchardMerkleFrontier>(ORCHARD);
}
}
BOOST_AUTO_TEST_CASE(chained_joinsplits)
{
// TODO update this or add a similar test when the SaplingNote class exist