-
Notifications
You must be signed in to change notification settings - Fork 56
/
abi_internal_test.go
98 lines (77 loc) · 2.35 KB
/
abi_internal_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
package xchain
import (
"encoding/hex"
"testing"
"github.com/omni-network/omni/contracts/bindings"
"github.com/omni-network/omni/lib/tutil"
"github.com/ethereum/go-ethereum/common"
fuzz "github.com/google/gofuzz"
"github.com/stretchr/testify/require"
)
//go:generate go test . -golden -clean
func TestEncodeMsg(t *testing.T) {
t.Parallel()
msg := Msg{
MsgID: MsgID{
StreamID: StreamID{
SourceChainID: 1,
DestChainID: 2,
ShardID: 1,
},
StreamOffset: 100,
},
SourceMsgSender: common.HexToAddress("0xcbbc5Da52ea2728279560Dca8f4ec08d5F829985"),
DestAddress: common.HexToAddress("0x9CC971e84FE5d09d0967f15AE05dfd553C5A1FA6"),
Data: common.Hex2Bytes("d09de08a"),
DestGasLimit: 250_000,
TxHash: common.Hash{},
}
packed, err := encodeMsg(msg)
require.NoError(t, err)
tutil.RequireGoldenBytes(t, []byte(hex.EncodeToString(packed)))
}
func TestEncodeHeader(t *testing.T) {
t.Parallel()
aHeader := AttestHeader{
ConsensusChainID: 1,
ChainVersion: ChainVersion{ID: 1, ConfLevel: ConfLatest},
AttestOffset: 100,
}
bHeader := BlockHeader{
ChainID: 1,
BlockHeight: 99,
BlockHash: common.HexToHash("0x412d62a6a3115ab5a0e0cae9d63082ff8dfb002a98cc889d06dc986a9461586b"),
}
packed, err := encodeSubmissionHeader(aHeader, bHeader)
require.NoError(t, err)
tutil.RequireGoldenBytes(t, []byte(hex.EncodeToString(packed)))
}
func TestSubmissionToFromBinding(t *testing.T) {
t.Parallel()
var sub Submission
fuzz.New().NilChance(0).Fuzz(&sub)
sub.AttHeader.ChainVersion.ID = sub.BlockHeader.ChainID // Align headers
xsub := SubmissionToBinding(sub)
reversedSub, err := SubmissionFromBinding(xsub, sub.DestChainID)
require.NoError(t, err)
// Zero TxHash, ChainID, Fees, and LogIndex for comparison since they aren't translated.
for i := range sub.Msgs {
sub.Msgs[i].TxHash = common.Hash{}
sub.Msgs[i].SourceChainID = 0
sub.Msgs[i].Fees = nil
sub.Msgs[i].LogIndex = 0
}
// Zero BlockHeight as we only submit AttestOffset
sub.BlockHeader.BlockHeight = 0
require.Equal(t, sub, reversedSub)
}
func TestXSubmitEncodeDecode(t *testing.T) {
t.Parallel()
var sub bindings.XSubmission
fuzz.New().NilChance(0).Fuzz(&sub)
calldata, err := EncodeXSubmit(sub)
require.NoError(t, err)
decoded, err := DecodeXSubmit(calldata)
require.NoError(t, err)
require.Equal(t, sub, decoded)
}