-
Notifications
You must be signed in to change notification settings - Fork 2
/
u8_test.go
62 lines (51 loc) · 1.33 KB
/
u8_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
package goscale
import (
"bytes"
"math/big"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_EncodeU8(t *testing.T) {
var testExamples = []struct {
label string
input U8
expectation []byte
}{
{label: "uint8(255)", input: U8(255), expectation: []byte{0xff}},
{label: "uint8(0)", input: U8(0), expectation: []byte{0x00}},
}
for _, testExample := range testExamples {
t.Run(testExample.label, func(t *testing.T) {
buffer := &bytes.Buffer{}
err := testExample.input.Encode(buffer)
assert.NoError(t, err)
assert.Equal(t, testExample.expectation, buffer.Bytes())
assert.Equal(t, testExample.expectation, testExample.input.Bytes())
})
}
}
func Test_DecodeU8(t *testing.T) {
var testExamples = []struct {
label string
input []byte
expectation U8
}{
{label: "(0xff)", input: []byte{0xff}, expectation: U8(255)},
}
for _, testExample := range testExamples {
t.Run(testExample.label, func(t *testing.T) {
buffer := &bytes.Buffer{}
buffer.Write(testExample.input)
result, err := DecodeU8(buffer)
assert.NoError(t, err)
assert.Equal(t, testExample.expectation, result)
})
}
}
func Test_U8_ToBigInt(t *testing.T) {
n := U8(15)
nBigInt := n.ToBigInt()
expect, ok := new(big.Int).SetString("15", 10)
assert.True(t, ok)
assert.Equal(t, expect, nBigInt)
}