-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #595: Add unit test for the PolyMod method in b(l)ech32
4a218cd Fix linter by exporting b(l)ech32 internals (Steven Roose) 99b047c Add additional blech32 unit test (Steven Roose) 6412970 Fix bug in blech32 (Steven Roose) 0de2b05 Add unit test for the PolyMod method in b(l)ech32 (Steven Roose) Pull request description: Tree-SHA512: 9d574376b6471742283d0d145359d8d674b7e95fd40f52396c6fc5f671dc262526624d1d15cb8ab7b4517a8b2501405dd0f680f69dfc41dabb0eb11d7bbbfe88
- Loading branch information
Showing
7 changed files
with
77 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) 2017 Pieter Wuille | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <blech32.h> | ||
#include <random.h> | ||
#include <utilstrencodings.h> | ||
#include <test/test_bitcoin.h> | ||
|
||
#include <boost/test/unit_test.hpp> | ||
|
||
BOOST_FIXTURE_TEST_SUITE(blech32_tests, BasicTestingSetup) | ||
|
||
BOOST_AUTO_TEST_CASE(blech32_polymod_sanity) | ||
{ | ||
std::vector<unsigned char> data(40); | ||
GetRandBytes(data.data(), data.size()); | ||
|
||
std::vector<unsigned char> base32; | ||
ConvertBits<8, 5, true>([&](unsigned char c) { base32.push_back(c); }, data.begin(), data.end()); | ||
uint64_t plm1 = blech32::PolyMod(base32); | ||
|
||
// Now add 1023 zeros. | ||
for (auto i = 0; i < 1023; i++) { | ||
base32.push_back(0); | ||
} | ||
uint64_t plm2 = blech32::PolyMod(base32); | ||
|
||
BOOST_CHECK_EQUAL(plm1, plm2); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(blech32_checksum) | ||
{ | ||
std::vector<unsigned char> vector{7,2,3,4,5,6,7,8,9,234,123,213,16}; | ||
std::vector<unsigned char> b32; | ||
ConvertBits<8, 5, true>([&](unsigned char c) { b32.push_back(c); }, vector.begin(), vector.end()); | ||
std::vector<unsigned char> cs = blech32::CreateChecksum("lq", b32); | ||
|
||
std::vector<unsigned char> expected_cs{22,13,13,5,4,4,23,7,28,21,30,12}; | ||
for (size_t i = 0; i < expected_cs.size(); i++) { | ||
BOOST_CHECK_EQUAL(expected_cs[i], cs[i]); | ||
} | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() | ||
|