LCOV - code coverage report
Current view: top level - src/test - zerocoindb_tests.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 20 20 100.0 %
Date: 2025-02-23 09:33:43 Functions: 2 2 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2021 The PIVX Core developers
       2             : // Distributed under the MIT software license, see the accompanying
       3             : // file COPYING or https://www.opensource.org/licenses/mit-license.php.
       4             : 
       5             : #include "test/test_pivx.h"
       6             : 
       7             : #include "txdb.h"
       8             : #include "validation.h"
       9             : 
      10             : #include <boost/test/unit_test.hpp>
      11             : 
      12             : BOOST_AUTO_TEST_SUITE(zerocoindb_tests)
      13             : 
      14           2 : BOOST_FIXTURE_TEST_CASE(accumulator_checksums_db, TestingSetup)
      15             : {
      16             :     // create random checksums map and write it in the DB
      17           1 :     std::map<std::pair<uint32_t, libzerocoin::CoinDenomination>, int> rand_map;
      18           9 :     for (const auto& d : libzerocoin::zerocoinDenomList) {
      19         168 :         for (int i = 0; i < 20; i++) {
      20         160 :             uint32_t rand_checksum = InsecureRand32();
      21         160 :             int rand_height = InsecureRandRange(2000000);
      22         160 :             rand_map[std::make_pair(rand_checksum, d)] = rand_height;
      23         160 :             zerocoinDB->WriteAccChecksum(rand_checksum, d, rand_height);
      24             :         }
      25             :     }
      26             : 
      27             :     // test ReadAll
      28           2 :     std::map<std::pair<uint32_t, libzerocoin::CoinDenomination>, int> new_map;
      29           2 :     BOOST_CHECK(zerocoinDB->ReadAll(new_map));
      30           1 :     BOOST_CHECK_EQUAL(new_map.size(), rand_map.size());
      31         161 :     for (const auto& it : rand_map) {
      32         160 :         const auto& h = new_map.find(it.first);
      33         320 :         BOOST_CHECK(h != new_map.end());
      34         320 :         BOOST_CHECK(h->second == it.second);
      35             :     }
      36             : 
      37             :     // test WipeAccChecksums
      38           1 :     zerocoinDB->WipeAccChecksums();
      39           2 :     std::map<std::pair<uint32_t, libzerocoin::CoinDenomination>, int> empty_map;
      40           2 :     BOOST_CHECK(zerocoinDB->ReadAll(empty_map));
      41           2 :     BOOST_CHECK(empty_map.empty());
      42           1 : }
      43             : 
      44             : BOOST_AUTO_TEST_SUITE_END()

Generated by: LCOV version 1.14