mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-15 12:51:00 +02:00
Add unit test for the PolyMod method in b(l)ech32
This commit is contained in:
parent
2412d38015
commit
0de2b056d1
3 changed files with 53 additions and 1 deletions
|
|
@ -39,6 +39,7 @@ BITCOIN_TESTS =\
|
|||
test/base58_tests.cpp \
|
||||
test/base64_tests.cpp \
|
||||
test/bech32_tests.cpp \
|
||||
test/blech32_tests.cpp \
|
||||
test/bip32_tests.cpp \
|
||||
test/blockchain_tests.cpp \
|
||||
test/blockencodings_tests.cpp \
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
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()
|
||||
|
|
|
|||
33
src/test/blech32_tests.cpp
Normal file
33
src/test/blech32_tests.cpp
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// 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_SUITE_END()
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue