Skip to content

Commit

Permalink
Bech32Test: Sync test vectors with current version of BIP173.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Schildbach committed Mar 2, 2018
1 parent 15a15ac commit 64aa2ec
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions core/src/test/java/org/bitcoinj/core/Bech32Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

public class Bech32Test {
@Test
public void validChecksum() {
for (String valid : VALID_CHECKSUMS) {
public void valid() {
for (String valid : VALID) {
Bech32.Bech32Data bechData = Bech32.decode(valid);
String recode = Bech32.encode(bechData);
assertEquals(String.format("Failed to roundtrip '%s' -> '%s'", valid, recode),
Expand All @@ -38,9 +38,19 @@ public void validChecksum() {
}
}

private static final String[] VALID = {
"A12UEL5L",
"a12uel5l",
"an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs",
"abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw",
"11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j",
"split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w",
"?1ezyfcl",
};

@Test
public void invalidChecksum() {
for (String invalid : INVALID_CHECKSUMS) {
public void invalid() {
for (String invalid : INVALID) {
try {
Bech32.decode(invalid);
fail(String.format("Parsed an invalid code: '%s'", invalid));
Expand All @@ -50,25 +60,19 @@ public void invalidChecksum() {
}
}

// test vectors

private static String[] VALID_CHECKSUMS = {
"A12UEL5L",
"an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs",
"abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw",
"11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j",
"split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w"
};

private static String[] INVALID_CHECKSUMS = {
" 1nwldj5",
new String(new char[] { 0x7f }) + "1axkwrx",
"an84characterslonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1569pvx",
"pzry9x0s0muk",
"1pzry9x0s0muk",
"x1b4n0q5v",
"li1dgmt3",
"de1lg7wt" + new String(new char[] { 0xff }),
private static final String[] INVALID = {
" 1nwldj5", // HRP character out of range
new String(new char[] { 0x7f }) + "1axkwrx", // HRP character out of range
new String(new char[] { 0x80 }) + "1eym55h", // HRP character out of range
"an84characterslonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1569pvx", // overall max length exceeded
"pzry9x0s0muk", // No separator character
"1pzry9x0s0muk", // Empty HRP
"x1b4n0q5v", // Invalid data character
"li1dgmt3", // Too short checksum
"de1lg7wt" + new String(new char[] { 0xff }), // Invalid character in checksum
"A1G7SGD8", // checksum calculated with uppercase form of HRP
"10a06t8", // empty HRP
"1qzzfhee", // empty HRP
};

@Test(expected = AddressFormatException.InvalidCharacter.class)
Expand Down

0 comments on commit 64aa2ec

Please sign in to comment.