@@ -68,10 +68,36 @@ BOOST_AUTO_TEST_CASE(bech32_testvectors_invalid)
68
68
" 1qzzfhee" ,
69
69
" a12UEL5L" ,
70
70
" A12uEL5L" ,
71
+ " abcdef1qpzrz9x8gf2tvdw0s3jn54khce6mua7lmqqqxw" ,
71
72
};
73
+ static const std::pair<std::string, int > ERRORS[] = {
74
+ {" Invalid character or mixed case" , 0 },
75
+ {" Invalid character or mixed case" , 0 },
76
+ {" Invalid character or mixed case" , 0 },
77
+ {" Bech32 string too long" , 90 },
78
+ {" Missing separator" , -1 },
79
+ {" Invalid separator position" , 0 },
80
+ {" Invalid Base 32 character" , 2 },
81
+ {" Invalid separator position" , 2 },
82
+ {" Invalid character or mixed case" , 8 },
83
+ {" Invalid checksum" , -1 }, // The checksum is calculated using the uppercase form so the entire string is invalid, not just a few characters
84
+ {" Invalid separator position" , 0 },
85
+ {" Invalid separator position" , 0 },
86
+ {" Invalid character or mixed case" , 3 },
87
+ {" Invalid character or mixed case" , 3 },
88
+ {" Invalid checksum" , 11 }
89
+ };
90
+ int i = 0 ;
72
91
for (const std::string& str : CASES) {
92
+ const auto & err = ERRORS[i];
73
93
const auto dec = bech32::Decode (str);
74
94
BOOST_CHECK (dec.encoding == bech32::Encoding::INVALID);
95
+ std::vector<int > error_locations;
96
+ std::string error = bech32::LocateErrors (str, error_locations);
97
+ BOOST_CHECK_EQUAL (err.first , error);
98
+ if (err.second == -1 ) BOOST_CHECK (error_locations.empty ());
99
+ else BOOST_CHECK_EQUAL (err.second , error_locations[0 ]);
100
+ i++;
75
101
}
76
102
}
77
103
@@ -91,11 +117,37 @@ BOOST_AUTO_TEST_CASE(bech32m_testvectors_invalid)
91
117
" au1s5cgom" ,
92
118
" M1VUXWEZ" ,
93
119
" 16plkw9" ,
94
- " 1p2gdwpf"
120
+ " 1p2gdwpf" ,
121
+ " abcdef1l7aum6echk45nj2s0wdvt2fg8x9yrzpqzd3ryx" ,
122
+ };
123
+ static const std::pair<std::string, int > ERRORS[] = {
124
+ {" Invalid character or mixed case" , 0 },
125
+ {" Invalid character or mixed case" , 0 },
126
+ {" Invalid character or mixed case" , 0 },
127
+ {" Bech32 string too long" , 90 },
128
+ {" Missing separator" , -1 },
129
+ {" Invalid separator position" , 0 },
130
+ {" Invalid Base 32 character" , 2 },
131
+ {" Invalid Base 32 character" , 3 },
132
+ {" Invalid separator position" , 2 },
133
+ {" Invalid Base 32 character" , 8 },
134
+ {" Invalid Base 32 character" , 7 },
135
+ {" Invalid checksum" , -1 },
136
+ {" Invalid separator position" , 0 },
137
+ {" Invalid separator position" , 0 },
138
+ {" Invalid checksum" , 21 },
95
139
};
140
+ int i = 0 ;
96
141
for (const std::string& str : CASES) {
142
+ const auto & err = ERRORS[i];
97
143
const auto dec = bech32::Decode (str);
98
144
BOOST_CHECK (dec.encoding == bech32::Encoding::INVALID);
145
+ std::vector<int > error_locations;
146
+ std::string error = bech32::LocateErrors (str, error_locations);
147
+ BOOST_CHECK_EQUAL (err.first , error);
148
+ if (err.second == -1 ) BOOST_CHECK (error_locations.empty ());
149
+ else BOOST_CHECK_EQUAL (err.second , error_locations[0 ]);
150
+ i++;
99
151
}
100
152
}
101
153
0 commit comments