9#include <boost/test/unit_test.hpp>
13BOOST_AUTO_TEST_SUITE(bech32_tests)
17 static const std::string CASES[] = {
20 "an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs",
21 "abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw",
22 "11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j",
23 "split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w",
26 for (
const std::string& str : CASES) {
37 static const std::string CASES[] = {
40 "an83characterlonghumanreadablepartthatcontainsthetheexcludedcharactersbioandnumber11sg7hg6",
41 "abcdef1l7aum6echk45nj3s0wdvt2fg8x9yrzpqzd3ryx",
42 "11llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllludsr8",
43 "split1checkupstagehandshakeupstreamerranterredcaperredlc445v",
46 for (
const std::string& str : CASES) {
57 static const std::string CASES[] = {
61 "an84characterslonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1569pvx",
72 "abcdef1qpzrz9x8gf2tvdw0s3jn54khce6mua7lmqqqxw",
73 "test1zg69w7y6hn0aqy352euf40x77qddq3dc",
74 std::string(100,
'q'),
76 static const std::pair<std::string, std::vector<int>> ERRORS[] = {
77 {
"Invalid character or mixed case", {0}},
78 {
"Invalid character or mixed case", {0}},
79 {
"Invalid character or mixed case", {0}},
80 {
"Bech32 string too long", {90}},
81 {
"Missing separator", {}},
82 {
"Invalid separator position", {0}},
83 {
"Invalid Base 32 character", {2}},
84 {
"Invalid separator position", {2}},
85 {
"Invalid character or mixed case", {8}},
86 {
"Invalid checksum", {}},
87 {
"Invalid separator position", {0}},
88 {
"Invalid separator position", {0}},
89 {
"Invalid character or mixed case", {3, 4, 5, 7}},
90 {
"Invalid character or mixed case", {3}},
91 {
"Invalid Bech32 checksum", {11}},
92 {
"Invalid Bech32 checksum", {9, 16}},
93 {
"Bech32 string too long", {90}},
95 static_assert(std::size(CASES) == std::size(ERRORS),
"Bech32 CASES and ERRORS should have the same length");
98 for (
const std::string& str : CASES) {
99 const auto& err = ERRORS[i];
111 static const std::string CASES[] = {
115 "an84characterslonghumanreadablepartthatcontainsthetheexcludedcharactersbioandnumber11d6pts4",
126 "abcdef1l7aum6echk45nj2s0wdvt2fg8x9yrzpqzd3ryx",
127 "test1zg69v7y60n00qy352euf40x77qcusag6",
129 static const std::pair<std::string, std::vector<int>> ERRORS[] = {
130 {
"Invalid character or mixed case", {0}},
131 {
"Invalid character or mixed case", {0}},
132 {
"Invalid character or mixed case", {0}},
133 {
"Bech32 string too long", {90}},
134 {
"Missing separator", {}},
135 {
"Invalid separator position", {0}},
136 {
"Invalid Base 32 character", {2}},
137 {
"Invalid Base 32 character", {3}},
138 {
"Invalid separator position", {2}},
139 {
"Invalid Base 32 character", {8}},
140 {
"Invalid Base 32 character", {7}},
141 {
"Invalid checksum", {}},
142 {
"Invalid separator position", {0}},
143 {
"Invalid separator position", {0}},
144 {
"Invalid Bech32m checksum", {21}},
145 {
"Invalid Bech32m checksum", {13, 32}},
147 static_assert(std::size(CASES) == std::size(ERRORS),
"Bech32m CASES and ERRORS should have the same length");
150 for (
const std::string& str : CASES) {
151 const auto& err = ERRORS[i];
BOOST_AUTO_TEST_CASE(bech32_testvectors_valid)
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(headers.FindFirst("key"), "value")
std::pair< std::string, std::vector< int > > LocateErrors(const std::string &str, CharLimit limit)
Find index of an incorrect character in a Bech32 string.
@ INVALID
Failed decoding.
@ BECH32
Bech32 encoding as defined in BIP173.
@ BECH32M
Bech32m encoding as defined in BIP350.
DecodeResult Decode(const std::string &str, CharLimit limit)
Decode a Bech32 or Bech32m string.
std::string Encode(Encoding encoding, const std::string &hrp, const data &values)
Encode a Bech32 or Bech32m string.
#define BOOST_CHECK(expr)
bool CaseInsensitiveEqual(std::string_view s1, std::string_view s2)
Locale-independent, ASCII-only comparator.