Skip to content

Commit

Permalink
Merge #31: Update Go tests
Browse files Browse the repository at this point in the history
91bd873 Update Go tests (Pieter Wuille)

Pull request description:

Tree-SHA512: e908de38f7a40bf9c0738012134ed2e8c42d18d9608b2cd335d6f08c0fc1166701ab47c363329e3a6a2fd354a00e112cfee52d50bfd7317064d8751cbbd28868
  • Loading branch information
sipa committed Sep 13, 2017
2 parents 2528acd + 91bd873 commit 9d37d88
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion ref/go/src/bech32/bech32_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ var validChecksum = []string{
"split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w",
}

var invalidChecksum = []string{
" 1nwldj5",
"\x7F" + "1axkwrx",
"an84characterslonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1569pvx",
"pzry9x0s0muk",
"1pzry9x0s0muk",
"x1b4n0q5v",
"li1dgmt3",
"de1lg7wt\xFF",
}

type item struct {
address string
scriptpubkey []int
Expand Down Expand Up @@ -98,8 +109,9 @@ var invalidAddress = []string{
"bc10w508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7kw5rljs90",
"BC1QR508D6QEJXTDG4Y5R3ZARVARYV98GJ9P",
"tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sL5k7",
"tb1pw508d6qejxtdg4y5r3zarqfsj6c3",
"bc1zw508d6qejxtdg4y5r3zarvaryvqyzf3du",
"tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3pjxtptv",
"bc1gmk9yu",
}

func TestValidChecksum(t *testing.T) {
Expand All @@ -113,6 +125,17 @@ func TestValidChecksum(t *testing.T) {
}
}

func TestInvalidChecksum(t *testing.T) {
for _, test := range invalidChecksum {
hrp, data, err := bech32.Decode(test)
if err != nil {
t.Logf("Invalid checksum for %s : ok / hrp : %+v , data : %+v\n", test, hrp, data)
} else {
t.Errorf("Invalid checksum for %s : FAIL\n", test)
}
}
}

func TestValidAddress(t *testing.T) {
for _, test := range validAddress {
hrp := "bc"
Expand Down

0 comments on commit 9d37d88

Please sign in to comment.