forked from omni-network/omni
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreator_internal_test.go
88 lines (76 loc) · 2.13 KB
/
creator_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
package relayer
import (
"testing"
"github.com/omni-network/omni/lib/xchain"
"github.com/stretchr/testify/require"
)
func TestGroupingMsgsByCost(t *testing.T) {
t.Parallel()
// Constants defined in contracts/src/protocol/OmniPortalConstants.sol
const msgGasLimitMin uint64 = 21_000
const msgGasLimitMax uint64 = 5_000_000
tests := []struct {
name string
msgGas []uint64
expected []uint64
}{
{
name: "empty",
msgGas: nil,
expected: uints(subGasBase),
},
{
name: "one min",
msgGas: uints(msgGasLimitMin),
expected: uints(subGasBase + subGasXmsgOverhead + msgGasLimitMin),
},
{
name: "one max",
msgGas: uints(msgGasLimitMax),
expected: uints(subGasBase + subGasXmsgOverhead + msgGasLimitMax),
},
{
name: "two min",
msgGas: uints(msgGasLimitMin, msgGasLimitMin),
expected: uints(
subGasBase + ((subGasXmsgOverhead + msgGasLimitMin) * 2),
),
},
{
name: "two max",
msgGas: uints(msgGasLimitMax, msgGasLimitMax),
expected: uints(
subGasBase+subGasXmsgOverhead+msgGasLimitMax,
subGasBase+subGasXmsgOverhead+msgGasLimitMax,
),
},
{
name: "many",
msgGas: uints(msgGasLimitMin, msgGasLimitMax, msgGasLimitMin, msgGasLimitMax, msgGasLimitMin, msgGasLimitMax),
expected: uints(
subGasBase+(subGasXmsgOverhead+msgGasLimitMax)+(subGasXmsgOverhead+msgGasLimitMin)*2,
subGasBase+(subGasXmsgOverhead+msgGasLimitMax)+(subGasXmsgOverhead+msgGasLimitMin)*1,
subGasBase+(subGasXmsgOverhead+msgGasLimitMax)+(subGasXmsgOverhead+msgGasLimitMin)*0,
),
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
var xmsgs []xchain.Msg
for _, gas := range test.msgGas {
xmsgs = append(xmsgs, xchain.Msg{DestGasLimit: gas})
}
groups := groupMsgsByCost(xmsgs)
require.Len(t, groups, len(test.expected))
for i, group := range groups {
require.Equal(t, int(test.expected[i]), int(naiveSubmissionGas(group)))
// Ensure we never cross the max
require.LessOrEqual(t, int(naiveSubmissionGas(group)), int(subGasMax))
}
})
}
}
func uints(ii ...uint64) []uint64 {
return ii
}