-
Notifications
You must be signed in to change notification settings - Fork 0
/
base32_test.go
75 lines (71 loc) · 1.91 KB
/
base32_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package encoding
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestDecodeBase32(t *testing.T) {
type args struct {
in string
}
tests := []struct {
name string
args args
want []byte
wantErr bool
}{
{
"success",
args{
"BGDMM4KDVWLG7JLZZENTBRT7SXTUXTHDYXWLSXEWX62YFB3FMTSJYCB7DQ",
},
[]byte{0x9, 0x86, 0xc6, 0x71, 0x43, 0xad, 0x96, 0x6f, 0xa5, 0x79, 0xc9, 0x1b, 0x30, 0xc6, 0x7f, 0x95, 0xe7, 0x4b, 0xcc, 0xe3, 0xc5, 0xec, 0xb9, 0x5c, 0x96, 0xbf, 0xb5, 0x82, 0x87, 0x65, 0x64, 0xe4, 0x9c, 0x8, 0x3f, 0x1c},
false,
},
{
"algorand-address",
args{
"C7Z4NNMIMOGZW56JCILF6DVY4MBZJMHXUQ67W2WKVE6U5QJSIDPYUEAXQU",
},
[]byte{0x17, 0xf3, 0xc6, 0xb5, 0x88, 0x63, 0x8d, 0x9b, 0x77, 0xc9, 0x12, 0x16, 0x5f, 0xe, 0xb8, 0xe3, 0x3, 0x94, 0xb0, 0xf7, 0xa4, 0x3d, 0xfb, 0x6a, 0xca, 0xa9, 0x3d, 0x4e, 0xc1, 0x32, 0x40, 0xdf, 0x8a, 0x10, 0x17, 0x85},
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := DecodeBase32(tt.args.in)
if (err != nil) != tt.wantErr {
t.Errorf("DecodeBase32() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !assert.Equal(t, tt.want, got) {
t.Errorf("DecodeBase32() = %v, want %v", got, tt.want)
}
})
}
}
func TestEncodeBase32(t *testing.T) {
type args struct {
in []byte
}
tests := []struct {
name string
args args
want string
}{
{
"success",
args{
[]byte{0x9, 0x86, 0xc6, 0x71, 0x43, 0xad, 0x96, 0x6f, 0xa5, 0x79, 0xc9, 0x1b, 0x30, 0xc6, 0x7f, 0x95, 0xe7, 0x4b, 0xcc, 0xe3, 0xc5, 0xec, 0xb9, 0x5c, 0x96, 0xbf, 0xb5, 0x82, 0x87, 0x65, 0x64, 0xe4, 0x9c, 0x8, 0x3f, 0x1c},
},
"BGDMM4KDVWLG7JLZZENTBRT7SXTUXTHDYXWLSXEWX62YFB3FMTSJYCB7DQ",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := EncodeBase32(tt.args.in)
if !assert.Equal(t, tt.want, got) {
t.Errorf("EncodeBase32() = %v, want %v", got, tt.want)
}
})
}
}