forked from ten-protocol/go-ten
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serialisation_test.go
64 lines (57 loc) · 1.24 KB
/
serialisation_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
package core
import (
"sync/atomic"
"testing"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ten-protocol/go-ten/go/common"
"github.com/ten-protocol/go-ten/integration/datagenerator"
)
func TestSerialiseL2Tx(t *testing.T) {
tx := datagenerator.CreateL2Tx()
bytes, err := rlp.EncodeToBytes(tx)
if err != nil {
panic(err)
}
tx1 := common.L2Tx{}
err2 := rlp.DecodeBytes(bytes, &tx1)
if err2 != nil {
panic(err2)
}
if tx1.Hash() != tx.Hash() {
t.Errorf("tx deserialized incorrectly\n")
}
}
func TestSerialiseRollup(t *testing.T) {
height := atomic.Value{}
height.Store(1)
rollup := datagenerator.RandomRollup(nil)
_, read, err := rlp.EncodeToReader(&rollup)
if err != nil {
panic(err)
}
r1 := common.ExtRollup{}
err = rlp.Decode(read, &r1)
if err != nil {
panic(err)
}
if r1.Hash() != rollup.Hash() {
t.Errorf("rollup deserialized incorrectly\n")
}
}
func TestSerialiseBatch(t *testing.T) {
height := atomic.Value{}
height.Store(1)
batch := datagenerator.RandomBatch(nil)
_, read, err := rlp.EncodeToReader(&batch)
if err != nil {
panic(err)
}
r1 := common.ExtBatch{}
err = rlp.Decode(read, &r1)
if err != nil {
panic(err)
}
if r1.Hash() != batch.Hash() {
t.Errorf("batch deserialized incorrectly\n")
}
}