forked from vedhavyas/go-subkey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hex_test.go
39 lines (35 loc) · 1.03 KB
/
hex_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
package subkey
import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDecodeHex(t *testing.T) {
tests := []struct {
hex string
bytes []byte
valid bool
}{
{
hex: "0xb69355deefa7a8f33e9297f5af22e680f03597a99d4f4b1c44be47e7a2275802",
bytes: []byte{0xb6, 0x93, 0x55, 0xde, 0xef, 0xa7, 0xa8, 0xf3, 0x3e, 0x92, 0x97, 0xf5, 0xaf, 0x22, 0xe6, 0x80, 0xf0, 0x35, 0x97, 0xa9, 0x9d, 0x4f, 0x4b, 0x1c, 0x44, 0xbe, 0x47, 0xe7, 0xa2, 0x27, 0x58, 0x2},
valid: true,
},
{
hex: "46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a",
bytes: []byte{0x46, 0xeb, 0xdd, 0xef, 0x8c, 0xd9, 0xbb, 0x16, 0x7d, 0xc3, 0x8, 0x78, 0xd7, 0x11, 0x3b, 0x7e, 0x16, 0x8e, 0x6f, 0x6, 0x46, 0xbe, 0xff, 0xd7, 0x7d, 0x69, 0xd3, 0x9b, 0xad, 0x76, 0xb4, 0x7a},
valid: true,
},
{
hex: "invalidhex",
valid: false,
},
}
for _, c := range tests {
t.Run(c.hex, func(t *testing.T) {
res, valid := DecodeHex(c.hex)
assert.Equal(t, c.valid, valid)
assert.True(t, bytes.Equal(c.bytes, res))
})
}
}