-
Notifications
You must be signed in to change notification settings - Fork 13
/
ethereum_test.go
77 lines (71 loc) · 1.71 KB
/
ethereum_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
76
77
package coincodec
import (
"errors"
"testing"
"github.com/wealdtech/go-slip44"
)
func TestEtherToBytes(t *testing.T) {
tests := []TestcaseEncode{
{
name: "Empty",
input: "",
err: errors.New("Ethereum address must have 40 characters"),
},
{
name: "Blank",
input: "0x",
err: errors.New("Ethereum address must have 40 characters"),
},
{
name: "Short",
input: "0x0102030405060708090a0b0c0d0e0f10111213",
err: errors.New("Ethereum address must have 40 characters"),
},
{
name: "Long",
input: "0x0102030405060708090a0b0c0d0e0f101112131415",
err: errors.New("Ethereum address must have 40 characters"),
},
{
name: "Odd",
input: "0x0102030405060708090a0b0c0d0e0f10111213141",
err: errors.New("Ethereum address must have 40 characters"),
},
{
name: "InvalidChars",
input: "0xabcdefghijklmnopqrstuvwxyzabcdefghijklmn",
err: errors.New("invalid hex string"),
},
{
name: "BadChecksum",
input: "0x0102030405060708090A0b0c0d0e0f1011121314",
err: errors.New("invalid checksum"),
},
{
name: "Good",
input: "0x0102030405060708090a0B0c0d0e0f1011121314",
output: "0102030405060708090a0b0c0d0e0f1011121314",
},
}
RunTestsEncode(t, slip44.ETHER, tests)
}
func TestEtherToString(t *testing.T) {
tests := []TestcaseDecode{
{
name: "Empty",
input: "",
err: errors.New("Ethereum address must have 20 bytes"),
},
{
name: "Too short",
input: "0102030405",
err: errors.New("Ethereum address must have 20 bytes"),
},
{
name: "Good",
input: "0102030405060708090a0b0c0d0e0f1011121314",
output: "0x0102030405060708090a0B0c0d0e0f1011121314",
},
}
RunTestsDecode(t, slip44.ETHER, tests)
}