-
Notifications
You must be signed in to change notification settings - Fork 676
/
fee_test_setup.go
125 lines (102 loc) · 3.68 KB
/
fee_test_setup.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
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
package antetest
import (
"fmt"
"github.com/stretchr/testify/suite"
tmrand "github.com/tendermint/tendermint/libs/rand"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
xauthsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/cosmos/cosmos-sdk/x/params/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
gaiaapp "github.com/cosmos/gaia/v14/app"
gaiahelpers "github.com/cosmos/gaia/v14/app/helpers"
"github.com/cosmos/gaia/v14/x/globalfee"
gaiafeeante "github.com/cosmos/gaia/v14/x/globalfee/ante"
globfeetypes "github.com/cosmos/gaia/v14/x/globalfee/types"
)
type IntegrationTestSuite struct {
suite.Suite
app *gaiaapp.GaiaApp
ctx sdk.Context
clientCtx client.Context
txBuilder client.TxBuilder
}
var testBondDenom = "uatom"
func (s *IntegrationTestSuite) SetupTest() {
app := gaiahelpers.Setup(s.T())
ctx := app.BaseApp.NewContext(false, tmproto.Header{
ChainID: fmt.Sprintf("test-chain-%s", tmrand.Str(4)),
Height: 1,
})
encodingConfig := gaiaapp.MakeTestEncodingConfig()
encodingConfig.Amino.RegisterConcrete(&testdata.TestMsg{}, "testdata.TestMsg", nil)
testdata.RegisterInterfaces(encodingConfig.InterfaceRegistry)
s.app = app
s.ctx = ctx
s.clientCtx = client.Context{}.WithTxConfig(encodingConfig.TxConfig)
}
func (s *IntegrationTestSuite) SetupTestGlobalFeeStoreAndMinGasPrice(minGasPrice []sdk.DecCoin, globalFeeParams *globfeetypes.Params) (gaiafeeante.FeeDecorator, sdk.AnteHandler) {
subspace := s.app.GetSubspace(globalfee.ModuleName)
subspace.SetParamSet(s.ctx, globalFeeParams)
s.ctx = s.ctx.WithMinGasPrices(minGasPrice).WithIsCheckTx(true)
// set staking params
stakingParam := stakingtypes.DefaultParams()
stakingParam.BondDenom = testBondDenom
stakingSubspace := s.SetupTestStakingSubspace(stakingParam)
// build fee decorator
feeDecorator := gaiafeeante.NewFeeDecorator(subspace, stakingSubspace)
// chain fee decorator to antehandler
antehandler := sdk.ChainAnteDecorators(feeDecorator)
return feeDecorator, antehandler
}
// SetupTestStakingSubspace sets uatom as bond denom for the fee tests.
func (s *IntegrationTestSuite) SetupTestStakingSubspace(params stakingtypes.Params) types.Subspace {
s.app.GetSubspace(stakingtypes.ModuleName).SetParamSet(s.ctx, ¶ms)
return s.app.GetSubspace(stakingtypes.ModuleName)
}
func (s *IntegrationTestSuite) CreateTestTx(privs []cryptotypes.PrivKey, accNums []uint64, accSeqs []uint64, chainID string) (xauthsigning.Tx, error) {
var sigsV2 []signing.SignatureV2
for i, priv := range privs {
sigV2 := signing.SignatureV2{
PubKey: priv.PubKey(),
Data: &signing.SingleSignatureData{
SignMode: s.clientCtx.TxConfig.SignModeHandler().DefaultMode(),
Signature: nil,
},
Sequence: accSeqs[i],
}
sigsV2 = append(sigsV2, sigV2)
}
if err := s.txBuilder.SetSignatures(sigsV2...); err != nil {
return nil, err
}
sigsV2 = []signing.SignatureV2{}
for i, priv := range privs {
signerData := xauthsigning.SignerData{
ChainID: chainID,
AccountNumber: accNums[i],
Sequence: accSeqs[i],
}
sigV2, err := tx.SignWithPrivKey(
s.clientCtx.TxConfig.SignModeHandler().DefaultMode(),
signerData,
s.txBuilder,
priv,
s.clientCtx.TxConfig,
accSeqs[i],
)
if err != nil {
return nil, err
}
sigsV2 = append(sigsV2, sigV2)
}
if err := s.txBuilder.SetSignatures(sigsV2...); err != nil {
return nil, err
}
return s.txBuilder.GetTx(), nil
}