From 64aa2ecac604eb512a47a827dcdfa4434f23a5c6 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Fri, 2 Mar 2018 10:55:39 +0100 Subject: [PATCH] Bech32Test: Sync test vectors with current version of BIP173. --- .../java/org/bitcoinj/core/Bech32Test.java | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/core/src/test/java/org/bitcoinj/core/Bech32Test.java b/core/src/test/java/org/bitcoinj/core/Bech32Test.java index e18842a8..5848bd58 100644 --- a/core/src/test/java/org/bitcoinj/core/Bech32Test.java +++ b/core/src/test/java/org/bitcoinj/core/Bech32Test.java @@ -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)