-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgas_priority_test.go
More file actions
96 lines (87 loc) · 1.58 KB
/
gas_priority_test.go
File metadata and controls
96 lines (87 loc) · 1.58 KB
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
package crosschain_test
import (
"fmt"
"testing"
xc "github.com/cordialsys/crosschain"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/require"
)
func TestPriority(t *testing.T) {
require.True(t, true)
type testcase struct {
input string
custom bool
decimal decimal.Decimal
err string
valid bool
}
vectors := []testcase{
{
input: "low",
custom: false,
valid: true,
},
{
input: "market",
custom: false,
valid: true,
},
{
input: "aggressive",
custom: false,
valid: true,
},
{
input: "very-aggressive",
custom: false,
valid: true,
},
{
input: "random",
custom: true,
decimal: decimal.Decimal{},
err: "invalid",
valid: false,
},
{
input: "1.2",
custom: true,
decimal: decimal.NewFromFloat(1.2),
err: "",
valid: true,
},
{
input: "1.2.3",
custom: true,
decimal: decimal.Decimal{},
err: "invalid",
valid: false,
},
{
input: "11.0",
custom: true,
decimal: decimal.NewFromFloat(11.0),
valid: true,
},
}
for i, v := range vectors {
fmt.Println("== testcase", i)
priority := xc.GasFeePriority(v.input)
require.Equal(t, v.custom, !priority.IsEnum())
if !priority.IsEnum() {
dec, err := priority.AsCustom()
if v.err != "" {
require.ErrorContains(t, err, v.err)
} else {
require.NoError(t, err)
}
require.Equal(t, v.decimal.String(), dec.String())
}
_, valid := xc.NewPriority(v.input)
if v.valid {
require.NoError(t, valid)
} else {
require.Error(t, valid)
}
}
}