-
Notifications
You must be signed in to change notification settings - Fork 879
Expand file tree
/
Copy pathprioritizer_test.go
More file actions
144 lines (131 loc) · 3.99 KB
/
prioritizer_test.go
File metadata and controls
144 lines (131 loc) · 3.99 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package app_test
import (
"testing"
cosmostypes "github.com/cosmos/cosmos-sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types"
xparamtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/tendermint/tendermint/libs/log"
"github.com/sei-protocol/sei-chain/app"
"github.com/sei-protocol/sei-chain/app/antedecorators"
"github.com/sei-protocol/sei-chain/app/apptesting"
oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types"
)
type PrioritizerTestSuite struct {
apptesting.KeeperTestHelper
prioritizer *app.SeiTxPrioritizer
}
func TestPrioritizerTestSuite(t *testing.T) {
suite.Run(t, new(PrioritizerTestSuite))
}
func (s *PrioritizerTestSuite) SetupTest() {
s.KeeperTestHelper.Setup()
logger, err := log.NewDefaultLogger(log.LogFormatPlain, "info")
require.NoError(s.T(), err)
s.prioritizer = app.NewSeiTxPrioritizer(logger, &s.App.EvmKeeper, &s.App.UpgradeKeeper, &s.App.ParamsKeeper)
}
var (
_ sdk.FeeTx = (*mockFeeTx)(nil)
_ sdk.Tx = (*mockTx)(nil)
)
type mockFeeTx struct {
sdk.Tx
fees sdk.Coins
gas uint64
msgs []sdk.Msg
}
func (tx *mockFeeTx) FeePayer() sdk.AccAddress { return nil }
func (tx *mockFeeTx) FeeGranter() sdk.AccAddress { return nil }
func (tx *mockFeeTx) GetFee() sdk.Coins { return tx.fees }
func (tx *mockFeeTx) GetGas() uint64 { return tx.gas }
func (tx *mockFeeTx) GetMsgs() []sdk.Msg { return tx.msgs }
type mockTx struct {
msgs []sdk.Msg
gasEstimate uint64
}
func (tx *mockTx) GetGasEstimate() uint64 { return tx.gasEstimate }
func (tx *mockTx) GetMsgs() []sdk.Msg { return tx.msgs }
func (*mockTx) ValidateBasic() error { return nil }
func (*mockTx) GetSigners() []sdk.AccAddress { return nil }
func (s *PrioritizerTestSuite) TestGetTxPriority() {
var (
zeroValueTx = func(*PrioritizerTestSuite) sdk.Tx { return &mockTx{} }
zeroValueFeeTx = func(*PrioritizerTestSuite) sdk.Tx { return &mockFeeTx{} }
zeroGasFeeTx = func(*PrioritizerTestSuite) sdk.Tx {
return &mockFeeTx{
gas: 0,
}
}
oracleVoteTx = func(s *PrioritizerTestSuite) sdk.Tx {
return &mockFeeTx{
msgs: []sdk.Msg{&oracletypes.MsgAggregateExchangeRateVote{}},
}
}
)
for _, tc := range []struct {
name string
givenTx func(s *PrioritizerTestSuite) sdk.Tx
givenContext func(sdk.Context) sdk.Context
wantPriority int64
wantErr string
expectedErrAs interface{}
}{
{
name: "unexpected Tx type is error",
givenTx: zeroValueTx,
wantErr: "must either be EVM or Fee",
},
{
name: "context with priority present is context priority",
givenTx: zeroValueFeeTx,
givenContext: func(ctx sdk.Context) sdk.Context {
return ctx.WithPriority(123)
},
wantPriority: 123,
},
{
name: "oracle Tx type is oracle priority",
givenTx: oracleVoteTx,
wantPriority: antedecorators.OraclePriority,
},
{
name: "zero gas FeeTx is zero priority",
givenTx: zeroGasFeeTx,
wantPriority: 0,
},
{
name: "cosmos tx with denominators is has priority of smallest demon multiplier",
givenTx: func(s *PrioritizerTestSuite) sdk.Tx {
s.App.ParamsKeeper.SetFeesParams(s.Ctx, xparamtypes.FeesParams{
AllowedFeeDenoms: []string{"fish", "lobster"},
})
return &mockFeeTx{
gas: 4_200,
fees: []sdk.Coin{
{Denom: "fish", Amount: sdk.NewInt(230_000_000)},
{Denom: "lobster", Amount: sdk.NewInt(290_000_000_000)},
},
}
},
wantPriority: cosmostypes.NewInt(230_000_000).QuoRaw(4_200).Int64(),
},
} {
s.T().Run(tc.name, func(t *testing.T) {
s.SetupTest()
tx := tc.givenTx(s)
ctx := s.Ctx
if tc.givenContext != nil {
ctx = tc.givenContext(ctx)
}
gotPriority, gotErr := s.prioritizer.GetTxPriorityHint(ctx, tx)
if tc.wantErr != "" {
require.Error(t, gotErr)
require.ErrorContains(t, gotErr, tc.wantErr)
} else {
require.NoError(t, gotErr)
require.Equal(t, tc.wantPriority, gotPriority)
}
})
}
}