-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase58_test.go
61 lines (55 loc) · 1.27 KB
/
base58_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
package radix
import (
"reflect"
"testing"
)
var base58Tests = []struct {
Bytes []byte
String string
}{
{Bytes: []byte{255, 255, 255, 255}, String: "7YXq9G"},
{Bytes: []byte{0, 0, 0, 0, 255, 255, 255, 255}, String: "11117YXq9G"},
{Bytes: []byte{0, 1, 2, 3, 4}, String: "12VfUX"},
}
func TestBase58Encode(t *testing.T) {
for _, tt := range base58Tests {
output, err := Base58Encode(tt.Bytes, AlphabetBitcoin)
if err != nil {
t.Fatal(err)
}
if output != tt.String {
t.Errorf("got: %v; want: %v", output, tt.String)
}
}
}
func TestBase58EncodeErrors(t *testing.T) {
_, err := Base58Encode([]byte{}, "1234")
if err != nil {
if err != ErrBase58BadAlphabet {
t.Errorf("got: %v; want: ErrBase58BadAlphabet", err)
}
} else {
t.Error("want not nit err")
}
}
func TestBase58Decode(t *testing.T) {
for _, tt := range base58Tests {
output, err := Base58Decode(tt.String, AlphabetBitcoin)
if err != nil {
t.Fatal(err)
}
if reflect.DeepEqual(output, tt.Bytes) {
t.Errorf("got: %v; want: %v", output, tt.Bytes)
}
}
}
func TestBase58DecodeErrors(t *testing.T) {
_, err := Base58Decode("", "1234")
if err != nil {
if err != ErrBase58BadAlphabet {
t.Errorf("got: %v; want: ErrBase58BadAlphabet", err)
}
} else {
t.Error("want not nit err")
}
}