PIVX Core  5.6.99
P2P Digital Currency
libsapling_utils_tests.cpp
Go to the documentation of this file.
1 // Copyright (c) 2016-2020 The ZCash developers
2 // Copyright (c) 2020 The PIVX Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "test/test_pivx.h"
7 
8 #include "sapling/sapling_util.h"
9 #include <boost/test/unit_test.hpp>
10 
11 
12 BOOST_FIXTURE_TEST_SUITE(sapling_utils_tests, BasicTestingSetup)
13 
14 BOOST_AUTO_TEST_CASE(saplingConvertBytesVectorToVector) {
15  std::vector<unsigned char> bytes = {0x00, 0x01, 0x03, 0x12, 0xFF};
16  std::vector<bool> expected_bits = {
17  // 0x00
18  0, 0, 0, 0, 0, 0, 0, 0,
19  // 0x01
20  0, 0, 0, 0, 0, 0, 0, 1,
21  // 0x03
22  0, 0, 0, 0, 0, 0, 1, 1,
23  // 0x12
24  0, 0, 0, 1, 0, 0, 1, 0,
25  // 0xFF
26  1, 1, 1, 1, 1, 1, 1, 1
27  };
28  BOOST_CHECK(convertBytesVectorToVector(bytes) == expected_bits);
29 }
30 
31 BOOST_AUTO_TEST_CASE(saplingConvertVectorToInt) {
32 
35  BOOST_CHECK(convertVectorToInt({0,1}) == 1);
36  BOOST_CHECK(convertVectorToInt({1,0}) == 2);
37  BOOST_CHECK(convertVectorToInt({1,1}) == 3);
38  BOOST_CHECK(convertVectorToInt({1,0,0}) == 4);
39  BOOST_CHECK(convertVectorToInt({1,0,1}) == 5);
40  BOOST_CHECK(convertVectorToInt({1,1,0}) == 6);
41 
42  BOOST_CHECK_THROW(convertVectorToInt(std::vector<bool>(100)), std::length_error);
43 
44  {
45  std::vector<bool> v(63, 1);
46  BOOST_CHECK(convertVectorToInt(v) == 0x7fffffffffffffff);
47  }
48 
49  {
50  std::vector<bool> v(64, 1);
51  BOOST_CHECK(convertVectorToInt(v) == 0xffffffffffffffff);
52  }
53 
54 }
55 
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(saplingConvertBytesVectorToVector)
#define BOOST_CHECK_THROW(stmt, excMatch)
Definition: object.cpp:19
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
#define BOOST_CHECK(expr)
Definition: object.cpp:17
uint64_t convertVectorToInt(const std::vector< bool > &v)
std::vector< bool > convertBytesVectorToVector(const std::vector< unsigned char > &bytes)
Basic testing setup.
Definition: test_pivx.h:51