PIVX Core  5.6.99
P2P Digital Currency
zerocoindb_tests.cpp
Go to the documentation of this file.
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 BOOST_FIXTURE_TEST_CASE(accumulator_checksums_db, TestingSetup)
15 {
16  // create random checksums map and write it in the DB
17  std::map<std::pair<uint32_t, libzerocoin::CoinDenomination>, int> rand_map;
18  for (const auto& d : libzerocoin::zerocoinDenomList) {
19  for (int i = 0; i < 20; i++) {
20  uint32_t rand_checksum = InsecureRand32();
21  int rand_height = InsecureRandRange(2000000);
22  rand_map[std::make_pair(rand_checksum, d)] = rand_height;
23  zerocoinDB->WriteAccChecksum(rand_checksum, d, rand_height);
24  }
25  }
26 
27  // test ReadAll
28  std::map<std::pair<uint32_t, libzerocoin::CoinDenomination>, int> new_map;
29  BOOST_CHECK(zerocoinDB->ReadAll(new_map));
30  BOOST_CHECK_EQUAL(new_map.size(), rand_map.size());
31  for (const auto& it : rand_map) {
32  const auto& h = new_map.find(it.first);
33  BOOST_CHECK(h != new_map.end());
34  BOOST_CHECK(h->second == it.second);
35  }
36 
37  // test WipeAccChecksums
38  zerocoinDB->WipeAccChecksums();
39  std::map<std::pair<uint32_t, libzerocoin::CoinDenomination>, int> empty_map;
40  BOOST_CHECK(zerocoinDB->ReadAll(empty_map));
41  BOOST_CHECK(empty_map.empty());
42 }
43 
BOOST_AUTO_TEST_SUITE(cuckoocache_tests)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
const std::vector< CoinDenomination > zerocoinDenomList
Definition: Denominations.h:27
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
#define BOOST_CHECK(expr)
Definition: object.cpp:17
std::unique_ptr< CZerocoinDB > zerocoinDB
Global variable that points to the zerocoin database (protected by cs_main)
Definition: validation.cpp:208
BOOST_FIXTURE_TEST_CASE(accumulator_checksums_db, TestingSetup)