Bech32Test: Sync test vectors with current version of BIP173.

This commit is contained in:
Andreas Schildbach
2018-03-02 10:55:39 +01:00
parent 15a15ac024
commit 64aa2ecac6

View File

@@ -25,8 +25,8 @@ import org.junit.Test;
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),
@@ -38,9 +38,19 @@ public class Bech32Test {
}
}
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));
@@ -50,25 +60,19 @@ public class Bech32Test {
}
}
// 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)