7
7
"cosmossdk.io/math"
8
8
"github.com/classic-terra/core/v2/app"
9
9
core "github.com/classic-terra/core/v2/types"
10
+ "github.com/gogo/protobuf/proto"
10
11
"github.com/stretchr/testify/suite"
11
12
12
13
"github.com/cosmos/cosmos-sdk/client"
@@ -23,6 +24,9 @@ import (
23
24
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
24
25
authz "github.com/cosmos/cosmos-sdk/x/authz"
25
26
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
27
+ icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types"
28
+ clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types"
29
+ channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"
26
30
27
31
abci "github.com/tendermint/tendermint/abci/types"
28
32
)
@@ -174,7 +178,7 @@ func (suite *AnteTestSuite) TestAnte_EnsureDynCommissionIsMinComm() {
174
178
suite .CreateValidator (50_000_000_000 )
175
179
suite .App .DyncommKeeper .UpdateAllBondedValidatorRates (suite .Ctx )
176
180
177
- mfd := dyncommante .NewDyncommDecorator (suite .App .DyncommKeeper , suite .App .StakingKeeper )
181
+ mfd := dyncommante .NewDyncommDecorator (suite .App .AppCodec (), suite . App . DyncommKeeper , suite .App .StakingKeeper )
178
182
antehandler := sdk .ChainAnteDecorators (mfd )
179
183
180
184
dyncomm := suite .App .DyncommKeeper .CalculateDynCommission (suite .Ctx , val1 )
@@ -217,7 +221,7 @@ func (suite *AnteTestSuite) TestAnte_EnsureDynCommissionIsMinCommAuthz() {
217
221
suite .CreateValidator (50_000_000_000 )
218
222
suite .App .DyncommKeeper .UpdateAllBondedValidatorRates (suite .Ctx )
219
223
220
- mfd := dyncommante .NewDyncommDecorator (suite .App .DyncommKeeper , suite .App .StakingKeeper )
224
+ mfd := dyncommante .NewDyncommDecorator (suite .App .AppCodec (), suite . App . DyncommKeeper , suite .App .StakingKeeper )
221
225
antehandler := sdk .ChainAnteDecorators (mfd )
222
226
223
227
dyncomm := suite .App .DyncommKeeper .CalculateDynCommission (suite .Ctx , val1 )
@@ -254,6 +258,81 @@ func (suite *AnteTestSuite) TestAnte_EnsureDynCommissionIsMinCommAuthz() {
254
258
suite .Require ().NoError (err )
255
259
}
256
260
261
+ func (suite * AnteTestSuite ) TestAnte_EnsureDynCommissionIsMinCommICA () {
262
+ suite .SetupTest () // setup
263
+ suite .txBuilder = suite .clientCtx .TxConfig .NewTxBuilder ()
264
+ suite .txBuilder .SetGasLimit (400_000 )
265
+ suite .Ctx = suite .Ctx .WithIsCheckTx (false )
266
+
267
+ _ , _ , val1 , _ := suite .CreateValidator (50_000_000_000 )
268
+ priv2 , _ , _ := testdata .KeyTestPubAddr ()
269
+ suite .CreateValidator (50_000_000_000 )
270
+ suite .App .DyncommKeeper .UpdateAllBondedValidatorRates (suite .Ctx )
271
+
272
+ mfd := dyncommante .NewDyncommDecorator (suite .App .AppCodec (), suite .App .DyncommKeeper , suite .App .StakingKeeper )
273
+ antehandler := sdk .ChainAnteDecorators (mfd )
274
+
275
+ dyncomm := suite .App .DyncommKeeper .CalculateDynCommission (suite .Ctx , val1 )
276
+ invalidtarget := dyncomm .Mul (sdk .NewDecWithPrec (9 , 1 ))
277
+ validtarget := dyncomm .Mul (sdk .NewDecWithPrec (11 , 1 ))
278
+
279
+ // prepare invalid tx -> expect it fails
280
+ editmsg := stakingtypes .NewMsgEditValidator (
281
+ val1 .GetOperator (),
282
+ val1 .Description , & invalidtarget , & val1 .MinSelfDelegation ,
283
+ )
284
+ data , err := icatypes .SerializeCosmosTx (suite .App .AppCodec (), []proto.Message {editmsg })
285
+ suite .Require ().NoError (err )
286
+ icaPacketData := icatypes.InterchainAccountPacketData {
287
+ Type : icatypes .EXECUTE_TX ,
288
+ Data : data ,
289
+ }
290
+ packetData := icaPacketData .GetBytes ()
291
+ packet := channeltypes .NewPacket (
292
+ packetData , 1 , "source-port" , "source-channel" ,
293
+ "dest-port" , "dest-channel" ,
294
+ clienttypes .NewHeight (1 , 1 ), 0 ,
295
+ )
296
+ recvmsg := channeltypes .NewMsgRecvPacket (
297
+ packet , []byte {}, clienttypes .NewHeight (1 , 1 ), "signer" ,
298
+ )
299
+
300
+ err = suite .txBuilder .SetMsgs (recvmsg )
301
+ suite .Require ().NoError (err )
302
+ tx , err := suite .CreateTestTx ([]cryptotypes.PrivKey {priv2 }, []uint64 {0 }, []uint64 {0 }, suite .Ctx .ChainID ())
303
+ suite .Require ().NoError (err )
304
+ _ , err = antehandler (suite .Ctx , tx , false )
305
+ suite .Require ().Error (err )
306
+
307
+ // prepare valid tx -> expect it passes
308
+ editmsg = stakingtypes .NewMsgEditValidator (
309
+ val1 .GetOperator (),
310
+ val1 .Description , & validtarget , & val1 .MinSelfDelegation ,
311
+ )
312
+ data , err = icatypes .SerializeCosmosTx (suite .App .AppCodec (), []proto.Message {editmsg })
313
+ suite .Require ().NoError (err )
314
+ icaPacketData = icatypes.InterchainAccountPacketData {
315
+ Type : icatypes .EXECUTE_TX ,
316
+ Data : data ,
317
+ }
318
+ packetData = icaPacketData .GetBytes ()
319
+ packet = channeltypes .NewPacket (
320
+ packetData , 1 , "source-port" , "source-channel" ,
321
+ "dest-port" , "dest-channel" ,
322
+ clienttypes .NewHeight (1 , 1 ), 0 ,
323
+ )
324
+ recvmsg = channeltypes .NewMsgRecvPacket (
325
+ packet , []byte {}, clienttypes .NewHeight (1 , 1 ), "signer" ,
326
+ )
327
+
328
+ err = suite .txBuilder .SetMsgs (recvmsg )
329
+ suite .Require ().NoError (err )
330
+ tx , err = suite .CreateTestTx ([]cryptotypes.PrivKey {priv2 }, []uint64 {0 }, []uint64 {0 }, suite .Ctx .ChainID ())
331
+ suite .Require ().NoError (err )
332
+ _ , err = antehandler (suite .Ctx , tx , false )
333
+ suite .Require ().NoError (err )
334
+ }
335
+
257
336
// go test -v -run ^TestAnteTestSuite/TestAnte_EditValidatorAccountSequence$ github.com/classic-terra/core/v2/x/dyncomm/ante
258
337
// check that account keeper sequence no longer increases when editing validator unsuccessfully
259
338
func (suite * AnteTestSuite ) TestAnte_EditValidatorAccountSequence () {
0 commit comments