-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathheaders_test.go
65 lines (57 loc) · 2.53 KB
/
headers_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
package common
import (
"crypto/rand"
"encoding/json"
"testing"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)
func TestBatchHeader_MarshalJSON(t *testing.T) {
batchHeader := &BatchHeader{
ParentHash: randomHash(),
Root: randomHash(),
TxHash: randomHash(),
ReceiptHash: randomHash(),
Number: gethcommon.Big1,
SequencerOrderNo: gethcommon.Big1,
GasLimit: 100,
GasUsed: 200,
Time: 300,
Extra: []byte("123"),
BaseFee: gethcommon.Big2,
L1Proof: randomHash(),
Signature: gethcommon.Big3.Bytes(),
CrossChainMessages: nil,
LatestInboundCrossChainHash: gethcommon.Hash{},
LatestInboundCrossChainHeight: nil,
}
jsonMarshalled, err := json.Marshal(batchHeader)
require.NoError(t, err)
batchUnmarshalled := BatchHeader{}
err = json.Unmarshal(jsonMarshalled, &batchUnmarshalled)
require.NoError(t, err)
require.Equal(t, batchHeader.ParentHash, batchUnmarshalled.ParentHash)
require.Equal(t, batchHeader.Root, batchUnmarshalled.Root)
require.Equal(t, batchHeader.TxHash, batchUnmarshalled.TxHash)
require.Equal(t, batchHeader.ReceiptHash, batchUnmarshalled.ReceiptHash)
require.Equal(t, batchHeader.Number, batchUnmarshalled.Number)
require.Equal(t, batchHeader.SequencerOrderNo, batchUnmarshalled.SequencerOrderNo)
require.Equal(t, batchHeader.GasLimit, batchUnmarshalled.GasLimit)
require.Equal(t, batchHeader.GasUsed, batchUnmarshalled.GasUsed)
require.Equal(t, batchHeader.Time, batchUnmarshalled.Time)
require.Equal(t, batchHeader.Extra, batchUnmarshalled.Extra)
require.Equal(t, batchHeader.BaseFee, batchUnmarshalled.BaseFee)
require.Equal(t, batchHeader.L1Proof, batchUnmarshalled.L1Proof)
require.Equal(t, batchHeader.Signature, batchUnmarshalled.Signature)
require.Equal(t, batchHeader.CrossChainMessages, batchUnmarshalled.CrossChainMessages)
require.Equal(t, batchHeader.LatestInboundCrossChainHash, batchUnmarshalled.LatestInboundCrossChainHash)
require.Equal(t, batchHeader.LatestInboundCrossChainHeight, batchUnmarshalled.LatestInboundCrossChainHeight)
require.Equal(t, batchHeader.Hash(), batchUnmarshalled.Hash())
}
func randomHash() gethcommon.Hash {
byteArr := make([]byte, 32)
if _, err := rand.Read(byteArr); err != nil {
panic(err)
}
return gethcommon.BytesToHash(byteArr)
}