-
Notifications
You must be signed in to change notification settings - Fork 13
/
cosmos_test.go
70 lines (63 loc) · 1.64 KB
/
cosmos_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
package coincodec
import (
"testing"
"github.com/pkg/errors"
"github.com/wealdtech/go-slip44"
)
func TestCosmosEncodeToBytes(t *testing.T) {
tests := []TestcaseEncode {
{
name: "Normal",
input: "cosmos1hsk6jryyqjfhp5dhc55tc9jtckygx0eph6dd02",
output: "bc2da90c84049370d1b7c528bc164bc588833f21",
},
{
name: "Normal2",
input: "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27",
output: "6e436a571cec916167ba105160474b9c9cd132bd",
},
{
name: "Testnet",
input: "cosmosvaloper1sxx9mszve0gaedz5ld7qdkjkfv8z992ax69k08",
err: errors.New("decoded hrp mismatch"),
},
{
name: "Wrong checksum",
input: "cosmos1hsk6jryyqjfhp5dhc55tc9jtckygx0eph6dd03",
err: errors.New("decoding bech32 failed: checksum failed. Expected h6dd02, got h6dd03."),
},
{
name: "Invalid public key hash",
input: "cosmos1vehk7cnpwgls32ra",
err: errors.New("A Bech32 address key hash must be 20 bytes"),
},
}
RunTestsEncode(t, slip44.ATOM, tests)
}
func TestCosmosDecodeToString(t *testing.T) {
keyhash := "bc2da90c84049370d1b7c528bc164bc588833f21"
keyhash2 := "6e436a571cec916167ba105160474b9c9cd132bd"
tests := []TestcaseDecode {
{
name: "Empty",
input: "",
err: errors.New("A Bech32 address key hash must be 20 bytes"),
},
{
name: "Too short",
input: "0102030405",
err: errors.New("A Bech32 address key hash must be 20 bytes"),
},
{
name: "Good",
input: keyhash,
output: "cosmos1hsk6jryyqjfhp5dhc55tc9jtckygx0eph6dd02",
},
{
name: "Good2",
input: keyhash2,
output: "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27",
},
}
RunTestsDecode(t, slip44.ATOM, tests)
}