-
Notifications
You must be signed in to change notification settings - Fork 385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unit test for the PolyMod method in b(l)ech32 #595
Merged
instagibbs
merged 4 commits into
ElementsProject:master
from
stevenroose:blech32-polymod-test
Apr 23, 2019
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <bech32.h> | ||
#include <bech32.cpp> | ||
#include <test/test_bitcoin.h> | ||
|
||
#include <boost/test/unit_test.hpp> | ||
|
@@ -66,4 +66,22 @@ BOOST_AUTO_TEST_CASE(bip173_testvectors_invalid) | |
} | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(bech32_polymod_sanity) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this a suitable upstream test? |
||
{ | ||
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 = PolyMod(base32); | ||
|
||
// Now add 1023 zeros. | ||
for (auto i = 0; i < 1023; i++) { | ||
base32.push_back(0); | ||
} | ||
uint64_t plm2 = PolyMod(base32); | ||
|
||
BOOST_CHECK_EQUAL(plm1, plm2); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |
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.cpp> | ||
#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 = PolyMod(base32); | ||
|
||
// Now add 1023 zeros. | ||
for (auto i = 0; i < 1023; i++) { | ||
base32.push_back(0); | ||
} | ||
uint64_t plm2 = 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 = 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() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yuck (including a .cpp file).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chants export export export
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
linter doesn't like it either :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah was to test the internal methods. Changed that meanwhile.