-
Notifications
You must be signed in to change notification settings - Fork 9
/
serializer_test.go
103 lines (85 loc) · 2.88 KB
/
serializer_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package hivego
import (
"bytes"
"testing"
)
func TestOpIdB(t *testing.T) {
got := opIdB("custom_json")
expected := byte(18)
if got != expected {
t.Error("Expected", expected, "got")
}
}
func TestRefBlockNumB(t *testing.T) {
got := refBlockNumB(36029)
expected := []byte{189, 140}
if !bytes.Equal(got, expected) {
t.Error("Expected", expected, "got", got)
}
}
func TestRefBlockPrefixB(t *testing.T) {
got := refBlockPrefixB(1164960351)
expected := []byte{95, 226, 111, 69}
if !bytes.Equal(got, expected) {
t.Error("Expected", expected, "got", got)
}
}
func TestExpTimeB(t *testing.T) {
got, _ := expTimeB("2016-08-08T12:24:17")
expected := []byte{241, 121, 168, 87}
if !bytes.Equal(got, expected) {
t.Error("Expected", expected, "got", got)
}
}
func TestCountOpsB(t *testing.T) {
got := countOpsB(getTwoTestOps())
expected := []byte{2}
if !bytes.Equal(got, expected) {
t.Error("Expected", expected, "got", got)
}
}
//func TestExtensionsB
func TestAppendVString(t *testing.T) {
var buf bytes.Buffer
got := appendVString("xeroc", &buf)
expected := []byte{5, 120, 101, 114, 111, 99}
if !bytes.Equal(got.Bytes(), expected) {
t.Error("Expected", expected, "got", got)
}
}
func TestAppendVStringArray(t *testing.T) {
var buf bytes.Buffer
got := appendVStringArray([]string{"xeroc", "piston"}, &buf).Bytes()
expected := []byte{2, 5, 120, 101, 114, 111, 99, 6, 112, 105, 115, 116, 111, 110}
if !bytes.Equal(got, expected) {
t.Error("Expected", expected, "got", got)
}
}
func TestSerializeTx(t *testing.T) {
got, _ := serializeTx(getTestVoteTx())
expected := []byte{189, 140, 95, 226, 111, 69, 241, 121, 168, 87, 1, 0, 5, 120, 101, 114, 111, 99, 5, 120, 101, 114, 111, 99, 6, 112, 105, 115, 116, 111, 110, 16, 39, 0}
if !bytes.Equal(got, expected) {
t.Error("Expected", expected, "got", got)
}
}
func TestSerializeOps(t *testing.T) {
got, _ := serializeOps(getTwoTestOps())
expected := []byte{2, 0, 5, 120, 101, 114, 111, 99, 5, 120, 101, 114, 111, 99, 6, 112, 105, 115, 116, 111, 110, 16, 39, 18, 0, 1, 5, 120, 101, 114, 111, 99, 7, 116, 101, 115, 116, 45, 105, 100, 17, 123, 34, 116, 101, 115, 116, 107, 34, 58, 34, 116, 101, 115, 116, 118, 34, 125}
if !bytes.Equal(got, expected) {
t.Error("Expected", expected, "got", got)
}
}
func TestSerializeOpVoteOperation(t *testing.T) {
got, _ := getTestVoteOp().serializeOp()
expected := []byte{0, 5, 120, 101, 114, 111, 99, 5, 120, 101, 114, 111, 99, 6, 112, 105, 115, 116, 111, 110, 16, 39}
if !bytes.Equal(got, expected) {
t.Error("Expected", expected, "got", got)
}
}
func TestSerializeOpCustomJsonOperation(t *testing.T) {
got, _ := getTestCustomJsonOp().serializeOp()
expected := []byte{18, 0, 1, 5, 120, 101, 114, 111, 99, 7, 116, 101, 115, 116, 45, 105, 100, 17, 123, 34, 116, 101, 115, 116, 107, 34, 58, 34, 116, 101, 115, 116, 118, 34, 125}
if !bytes.Equal(got, expected) {
t.Error("Expected", expected, "got", got)
}
}