Skip to content

Commit 8c6b9d3

Browse files
authored
Add tests for BanffBlock serialization (#2194)
1 parent d9460de commit 8c6b9d3

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
4+
package block
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"github.com/stretchr/testify/require"
11+
12+
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
13+
)
14+
15+
func TestBanffBlockSerialization(t *testing.T) {
16+
type test struct {
17+
block BanffBlock
18+
bytes []byte
19+
}
20+
21+
tests := []test{
22+
{
23+
block: &BanffProposalBlock{
24+
ApricotProposalBlock: ApricotProposalBlock{
25+
Tx: &txs.Tx{
26+
Unsigned: &txs.AdvanceTimeTx{},
27+
},
28+
},
29+
},
30+
bytes: []byte{
31+
// Codec version
32+
0x00, 0x00,
33+
// Type ID
34+
0x00, 0x00, 0x00, 0x1d,
35+
// Rest
36+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
37+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
38+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
39+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
41+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13,
43+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44+
0x00, 0x00, 0x00, 0x00,
45+
},
46+
},
47+
{
48+
block: &BanffCommitBlock{
49+
ApricotCommitBlock: ApricotCommitBlock{},
50+
},
51+
bytes: []byte{
52+
// Codec version
53+
0x00, 0x00,
54+
// Type ID
55+
0x00, 0x00, 0x00, 0x1f,
56+
// Rest
57+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
60+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63+
},
64+
},
65+
{
66+
block: &BanffAbortBlock{
67+
ApricotAbortBlock: ApricotAbortBlock{},
68+
},
69+
bytes: []byte{
70+
// Codec version
71+
0x00, 0x00,
72+
// Type ID
73+
0x00, 0x00, 0x00, 0x1e,
74+
// Rest
75+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
76+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
77+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
78+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
79+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
80+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81+
},
82+
},
83+
{
84+
block: &BanffStandardBlock{
85+
ApricotStandardBlock: ApricotStandardBlock{
86+
Transactions: []*txs.Tx{},
87+
},
88+
},
89+
bytes: []byte{
90+
// Codec version
91+
0x00, 0x00,
92+
// Type ID
93+
0x00, 0x00, 0x00, 0x20,
94+
// Rest
95+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
96+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
97+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
98+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
99+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
100+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
101+
0x00, 0x00, 0x00, 0x00,
102+
},
103+
},
104+
}
105+
106+
for _, test := range tests {
107+
testName := fmt.Sprintf("%T", test.block)
108+
t.Run(testName, func(t *testing.T) {
109+
require := require.New(t)
110+
111+
require.NoError(initialize(test.block))
112+
require.Equal(test.bytes, test.block.Bytes())
113+
})
114+
}
115+
}

0 commit comments

Comments
 (0)