Skip to content

Commit 2609281

Browse files
committed
[Sapling] Back port: sapling utils unit test.
1 parent 99577fd commit 2609281

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/Makefile.test.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ BITCOIN_TESTS =\
4040
test/zerocoin_bignum_tests.cpp \
4141
test/addrman_tests.cpp \
4242
test/allocator_tests.cpp \
43+
test/librust/libsapling_utils_tests.cpp \
4344
test/librust/pedersen_hash_tests.cpp \
4445
test/librust/noteencryption_tests.cpp \
4546
test/base32_tests.cpp \
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) 2016-2020 The ZCash developers
2+
// Copyright (c) 2020 The PIVX 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/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+
33+
BOOST_CHECK(convertVectorToInt({0}) == 0);
34+
BOOST_CHECK(convertVectorToInt({1}) == 1);
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+
56+
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)