OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / tendermint / go-wire / data / base58 / encoder_test.go
1 package base58_test
2
3 import (
4         "testing"
5
6         "github.com/stretchr/testify/assert"
7         data "github.com/tendermint/go-wire/data"
8         "github.com/tendermint/go-wire/data/base58"
9 )
10
11 func TestEncoders(t *testing.T) {
12         assert := assert.New(t)
13
14         // TODO: also test other alphabets???
15         btc := base58.BTCEncoder
16
17         cases := []struct {
18                 encoder         data.ByteEncoder
19                 input, expected []byte
20         }{
21                 {btc, []byte(`"3mJr7AoUXx2Wqd"`), []byte("1234598760")},
22                 {btc, []byte(`"3yxU3u1igY8WkgtjK92fbJQCd4BZiiT1v25f"`), []byte("abcdefghijklmnopqrstuvwxyz")},
23                 // these are errors
24                 {btc, []byte(`0123`), nil},    // not in quotes
25                 {btc, []byte(`"3mJr0"`), nil}, // invalid chars
26         }
27
28         for _, tc := range cases {
29                 var output []byte
30                 err := tc.encoder.Unmarshal(&output, tc.input)
31                 if tc.expected == nil {
32                         assert.NotNil(err, tc.input)
33                 } else if assert.Nil(err, "%s: %+v", tc.input, err) {
34                         assert.Equal(tc.expected, output, tc.input)
35                 }
36         }
37 }