Description
This PR improves unit test coverage for the bech32 encoding implementation by adding 9 new test cases based on the BIP-173 specification.
Motivation
The existing bech32 tests cover the standard test vectors from BIP-173/350 but don’t extensively test edge cases and error detection properties. Since bech32 is used for SegWit and Taproot addresses, comprehensive testing is important to catch potential regressions.
Changes
New test cases added to src/test/bech32_tests.cpp:
| Test | Description |
|---|---|
bech32_charset_encoding |
Verifies all 32 valid characters encode and decode correctly |
bech32_roundtrip_encoding |
Tests encode/decode round-trip for data sizes 0-40 bytes |
bech32_length_limits |
Tests the 90-character maximum length boundary |
bech32_hrp_limits |
Tests HRP edge cases: minimum length, boundary ASCII chars (33, 126), separator in HRP |
bech32_single_error_detection |
Verifies single-character errors are detected at every position |
bech32_transposition_detection |
Verifies adjacent character transpositions are detected |
bech32_multiple_error_detection |
Tests guaranteed detection of 2, 3, and 4 errors |
bech32_case_sensitivity |
Tests uppercase, lowercase, and mixed case handling per BIP-173 |
bech32_checksum_properties |
Verifies checksum is exactly 6 characters and deterministic |
These tests cover the following BIP-173 specification requirements:
- Character set validation (32-character alphabet)
- Maximum length enforcement (90 characters)
- Error detection guarantees (up to 4 errors)
- Case sensitivity rules (reject mixed case)
- Checksum properties (6-character BCH code)
References
- BIP-173: Base32 address format for native v0-16 witness outputs
- BIP-350: Bech32m format for v1+ witness addresses
PR Checklist
- Tests pass locally:
ctest --test-dir build -R bech32 - Code follows existing style in
bech32_tests.cpp - Comments reference BIP-173 sections where applicable
- No new dependencies introduced