Merge #12001: [RPC] Adding ::minRelayTxFee amount to getmempoolinfo and updating...
[bitcoinplatinum.git] / src / test / bech32_tests.cpp
blob495290c8d963af451b9e58855cbc1cb76f76604f
1 // Copyright (c) 2017 Pieter Wuille
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #include <bech32.h>
6 #include <test/test_bitcoin.h>
8 #include <boost/test/unit_test.hpp>
10 BOOST_FIXTURE_TEST_SUITE(bech32_tests, BasicTestingSetup)
12 bool CaseInsensitiveEqual(const std::string &s1, const std::string &s2)
14 if (s1.size() != s2.size()) return false;
15 for (size_t i = 0; i < s1.size(); ++i) {
16 char c1 = s1[i];
17 if (c1 >= 'A' && c1 <= 'Z') c1 -= ('A' - 'a');
18 char c2 = s2[i];
19 if (c2 >= 'A' && c2 <= 'Z') c2 -= ('A' - 'a');
20 if (c1 != c2) return false;
22 return true;
25 BOOST_AUTO_TEST_CASE(bip173_testvectors_valid)
27 static const std::string CASES[] = {
28 "A12UEL5L",
29 "a12uel5l",
30 "an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs",
31 "abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw",
32 "11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j",
33 "split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w",
34 "?1ezyfcl",
36 for (const std::string& str : CASES) {
37 auto ret = bech32::Decode(str);
38 BOOST_CHECK(!ret.first.empty());
39 std::string recode = bech32::Encode(ret.first, ret.second);
40 BOOST_CHECK(!recode.empty());
41 BOOST_CHECK(CaseInsensitiveEqual(str, recode));
45 BOOST_AUTO_TEST_CASE(bip173_testvectors_invalid)
47 static const std::string CASES[] = {
48 " 1nwldj5",
49 "\x7f""1axkwrx",
50 "\x80""1eym55h",
51 "an84characterslonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1569pvx",
52 "pzry9x0s0muk",
53 "1pzry9x0s0muk",
54 "x1b4n0q5v",
55 "li1dgmt3",
56 "de1lg7wt\xff",
57 "A1G7SGD8",
58 "10a06t8",
59 "1qzzfhee",
61 for (const std::string& str : CASES) {
62 auto ret = bech32::Decode(str);
63 BOOST_CHECK(ret.first.empty());
67 BOOST_AUTO_TEST_SUITE_END()