@@ -2,17 +2,20 @@ package ante_test
22
33import (
44 "testing"
5+ "time"
56
67 "github.com/stretchr/testify/require"
78 "github.com/stretchr/testify/suite"
89
10+ codectypes "github.com/cosmos/cosmos-sdk/codec/types"
911 sdk "github.com/cosmos/cosmos-sdk/types"
1012
1113 clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
1214 channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
1315 host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
1416 "github.com/cosmos/ibc-go/v7/modules/core/ante"
1517 "github.com/cosmos/ibc-go/v7/modules/core/exported"
18+ ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
1619 ibctesting "github.com/cosmos/ibc-go/v7/testing"
1720)
1821
@@ -342,6 +345,64 @@ func (suite *AnteTestSuite) TestAnteDecoratorCheckTx() {
342345 },
343346 true ,
344347 },
348+ {
349+ "success on new UpdateClient messages: solomachine misbehaviour" ,
350+ func (suite * AnteTestSuite ) []sdk.Msg {
351+ solomachine := ibctesting .NewSolomachine (suite .T (), suite .chainB .Codec , "06-solomachine-0" , "testing" , 1 )
352+ suite .chainB .GetSimApp ().GetIBCKeeper ().ClientKeeper .SetClientState (suite .chainB .GetContext (), solomachine .ClientID , solomachine .ClientState ())
353+
354+ msgUpdateClient , err := clienttypes .NewMsgUpdateClient (solomachine .ClientID , solomachine .CreateMisbehaviour (), suite .chainB .SenderAccount .GetAddress ().String ())
355+ suite .Require ().NoError (err )
356+
357+ msgs := []sdk.Msg {msgUpdateClient }
358+
359+ return msgs
360+ },
361+ true ,
362+ },
363+ {
364+ "success on new UpdateClient messages: solomachine multisig misbehaviour" ,
365+ func (suite * AnteTestSuite ) []sdk.Msg {
366+ solomachine := ibctesting .NewSolomachine (suite .T (), suite .chainA .Codec , "06-solomachine-0" , "testing" , 4 )
367+ suite .chainB .GetSimApp ().GetIBCKeeper ().ClientKeeper .SetClientState (suite .chainB .GetContext (), solomachine .ClientID , solomachine .ClientState ())
368+
369+ msgUpdateClient , err := clienttypes .NewMsgUpdateClient (solomachine .ClientID , solomachine .CreateMisbehaviour (), suite .chainB .SenderAccount .GetAddress ().String ())
370+ suite .Require ().NoError (err )
371+
372+ msgs := []sdk.Msg {msgUpdateClient }
373+
374+ return msgs
375+ },
376+ true ,
377+ },
378+ {
379+ "success on new UpdateClient messages: tendermint misbehaviour" ,
380+ func (suite * AnteTestSuite ) []sdk.Msg {
381+ trustedHeight := suite .path .EndpointB .GetClientState ().GetLatestHeight ().(clienttypes.Height )
382+
383+ trustedVals , found := suite .chainA .GetValsAtHeight (int64 (trustedHeight .RevisionHeight ) + 1 )
384+ suite .Require ().True (found )
385+
386+ err := suite .path .EndpointB .UpdateClient ()
387+ suite .Require ().NoError (err )
388+
389+ height := suite .path .EndpointB .GetClientState ().GetLatestHeight ().(clienttypes.Height )
390+
391+ // construct valid fork misbehaviour: two headers at the same height with different time
392+ misbehaviour := & ibctm.Misbehaviour {
393+ Header1 : suite .chainA .CreateTMClientHeader (suite .chainA .ChainID , int64 (height .RevisionHeight ), trustedHeight , suite .chainA .CurrentHeader .Time .Add (time .Minute ), suite .chainA .Vals , suite .chainA .NextVals , trustedVals , suite .chainA .Signers ),
394+ Header2 : suite .chainA .CreateTMClientHeader (suite .chainA .ChainID , int64 (height .RevisionHeight ), trustedHeight , suite .chainA .CurrentHeader .Time , suite .chainA .Vals , suite .chainA .NextVals , trustedVals , suite .chainA .Signers ),
395+ }
396+
397+ msgUpdateClient , err := clienttypes .NewMsgUpdateClient (suite .path .EndpointB .ClientID , misbehaviour , suite .chainB .SenderAccount .GetAddress ().String ())
398+ suite .Require ().NoError (err )
399+
400+ msgs := []sdk.Msg {msgUpdateClient }
401+
402+ return msgs
403+ },
404+ true ,
405+ },
345406 {
346407 "no success on one redundant RecvPacket message" ,
347408 func (suite * AnteTestSuite ) []sdk.Msg {
@@ -387,6 +448,39 @@ func (suite *AnteTestSuite) TestAnteDecoratorCheckTx() {
387448 },
388449 false ,
389450 },
451+ {
452+ "no success on one new UpdateClient message: invalid client identifier" ,
453+ func (suite * AnteTestSuite ) []sdk.Msg {
454+ clientMsg , err := codectypes .NewAnyWithValue (& ibctm.Header {})
455+ suite .Require ().NoError (err )
456+
457+ msgs := []sdk.Msg {& clienttypes.MsgUpdateClient {ClientId : ibctesting .InvalidID , ClientMessage : clientMsg }}
458+ return msgs
459+ },
460+ false ,
461+ },
462+ {
463+ "no success on one new UpdateClient message: client module not found" ,
464+ func (suite * AnteTestSuite ) []sdk.Msg {
465+ clientMsg , err := codectypes .NewAnyWithValue (& ibctm.Header {})
466+ suite .Require ().NoError (err )
467+
468+ msgs := []sdk.Msg {& clienttypes.MsgUpdateClient {ClientId : clienttypes .FormatClientIdentifier ("08-wasm" , 1 ), ClientMessage : clientMsg }}
469+ return msgs
470+ },
471+ false ,
472+ },
473+ {
474+ "no success on one new UpdateClient message: no consensus state for trusted height" ,
475+ func (suite * AnteTestSuite ) []sdk.Msg {
476+ clientMsg , err := codectypes .NewAnyWithValue (& ibctm.Header {TrustedHeight : clienttypes .NewHeight (1 , 10000 )})
477+ suite .Require ().NoError (err )
478+
479+ msgs := []sdk.Msg {& clienttypes.MsgUpdateClient {ClientId : suite .path .EndpointA .ClientID , ClientMessage : clientMsg }}
480+ return msgs
481+ },
482+ false ,
483+ },
390484 {
391485 "no success on three new UpdateClient messages and three redundant messages of each type" ,
392486 func (suite * AnteTestSuite ) []sdk.Msg {
0 commit comments