@@ -3,7 +3,6 @@ package types_test
33import (
44 "errors"
55 "testing"
6- "time"
76
87 "github.com/golang/protobuf/proto" //nolint:staticcheck
98 "github.com/stretchr/testify/require"
@@ -470,155 +469,6 @@ func (suite *TypesTestSuite) TestMsgUpgradeClient_ValidateBasic() {
470469 }
471470}
472471
473- // tests that different misbehaviours within MsgSubmitMisbehaviour can be marshaled
474- // and unmarshaled.
475- func (suite * TypesTestSuite ) TestMarshalMsgSubmitMisbehaviour () {
476- var (
477- msg * types.MsgSubmitMisbehaviour
478- err error
479- )
480-
481- testCases := []struct {
482- name string
483- malleate func ()
484- }{
485- {
486- "solo machine client" , func () {
487- soloMachine := ibctesting .NewSolomachine (suite .T (), suite .chainA .Codec , "solomachine" , "" , 2 )
488- msg , err = types .NewMsgSubmitMisbehaviour (soloMachine .ClientID , soloMachine .CreateMisbehaviour (), suite .chainA .SenderAccount .GetAddress ().String ())
489- suite .Require ().NoError (err )
490- },
491- },
492- {
493- "tendermint client" , func () {
494- height := types .NewHeight (0 , uint64 (suite .chainA .ProposedHeader .Height ))
495- heightMinus1 := types .NewHeight (0 , uint64 (suite .chainA .ProposedHeader .Height )- 1 )
496- header1 := suite .chainA .CreateTMClientHeader (suite .chainA .ChainID , int64 (height .RevisionHeight ), heightMinus1 , suite .chainA .ProposedHeader .Time , suite .chainA .Vals , suite .chainA .Vals , suite .chainA .Vals , suite .chainA .Signers )
497- header2 := suite .chainA .CreateTMClientHeader (suite .chainA .ChainID , int64 (height .RevisionHeight ), heightMinus1 , suite .chainA .ProposedHeader .Time .Add (time .Minute ), suite .chainA .Vals , suite .chainA .Vals , suite .chainA .Vals , suite .chainA .Signers )
498-
499- misbehaviour := ibctm .NewMisbehaviour ("tendermint" , header1 , header2 )
500- msg , err = types .NewMsgSubmitMisbehaviour ("tendermint" , misbehaviour , suite .chainA .SenderAccount .GetAddress ().String ())
501- suite .Require ().NoError (err )
502- },
503- },
504- }
505-
506- for _ , tc := range testCases {
507- suite .Run (tc .name , func () {
508- suite .SetupTest ()
509-
510- tc .malleate ()
511-
512- cdc := suite .chainA .App .AppCodec ()
513-
514- // marshal message
515- bz , err := cdc .MarshalJSON (msg )
516- suite .Require ().NoError (err )
517-
518- // unmarshal message
519- newMsg := & types.MsgSubmitMisbehaviour {}
520- err = cdc .UnmarshalJSON (bz , newMsg )
521- suite .Require ().NoError (err )
522-
523- suite .Require ().True (proto .Equal (msg , newMsg ))
524- })
525- }
526- }
527-
528- func (suite * TypesTestSuite ) TestMsgSubmitMisbehaviour_ValidateBasic () {
529- var (
530- msg = & types.MsgSubmitMisbehaviour {}
531- err error
532- )
533-
534- cases := []struct {
535- name string
536- malleate func ()
537- expErr error
538- }{
539- {
540- "invalid client-id" ,
541- func () {
542- msg .ClientId = ""
543- },
544- errorsmod .Wrapf (ibcerrors .ErrInvalidAddress , "string could not be parsed as address: empty address string is not allowed" ),
545- },
546- {
547- "valid - tendermint misbehaviour" ,
548- func () {
549- height := types .NewHeight (0 , uint64 (suite .chainA .ProposedHeader .Height ))
550- heightMinus1 := types .NewHeight (0 , uint64 (suite .chainA .ProposedHeader .Height )- 1 )
551- header1 := suite .chainA .CreateTMClientHeader (suite .chainA .ChainID , int64 (height .RevisionHeight ), heightMinus1 , suite .chainA .ProposedHeader .Time , suite .chainA .Vals , suite .chainA .Vals , suite .chainA .Vals , suite .chainA .Signers )
552- header2 := suite .chainA .CreateTMClientHeader (suite .chainA .ChainID , int64 (height .RevisionHeight ), heightMinus1 , suite .chainA .ProposedHeader .Time .Add (time .Minute ), suite .chainA .Vals , suite .chainA .Vals , suite .chainA .Vals , suite .chainA .Signers )
553-
554- misbehaviour := ibctm .NewMisbehaviour ("tendermint" , header1 , header2 )
555- msg , err = types .NewMsgSubmitMisbehaviour ("tendermint" , misbehaviour , suite .chainA .SenderAccount .GetAddress ().String ())
556- suite .Require ().NoError (err )
557- },
558- nil ,
559- },
560- {
561- "invalid tendermint misbehaviour" ,
562- func () {
563- msg , err = types .NewMsgSubmitMisbehaviour ("tendermint" , & ibctm.Misbehaviour {}, suite .chainA .SenderAccount .GetAddress ().String ())
564- suite .Require ().NoError (err )
565- },
566- errorsmod .Wrap (ibctm .ErrInvalidHeader , "misbehaviour Header1 cannot be nil" ),
567- },
568- {
569- "failed to unpack misbehaviourt" ,
570- func () {
571- msg .Misbehaviour = nil
572- },
573- errorsmod .Wrap (ibcerrors .ErrUnpackAny , "protobuf Any message cannot be nil" ),
574- },
575- {
576- "invalid signer" ,
577- func () {
578- msg .Signer = ""
579- },
580- errorsmod .Wrapf (ibcerrors .ErrInvalidAddress , "string could not be parsed as address: empty address string is not allowed" ),
581- },
582- {
583- "valid - solomachine misbehaviour" ,
584- func () {
585- soloMachine := ibctesting .NewSolomachine (suite .T (), suite .chainA .Codec , "solomachine" , "" , 2 )
586- msg , err = types .NewMsgSubmitMisbehaviour (soloMachine .ClientID , soloMachine .CreateMisbehaviour (), suite .chainA .SenderAccount .GetAddress ().String ())
587- suite .Require ().NoError (err )
588- },
589- nil ,
590- },
591- {
592- "invalid solomachine misbehaviour" ,
593- func () {
594- msg , err = types .NewMsgSubmitMisbehaviour ("solomachine" , & solomachine.Misbehaviour {}, suite .chainA .SenderAccount .GetAddress ().String ())
595- suite .Require ().NoError (err )
596- },
597- errorsmod .Wrapf (types .ErrInvalidMisbehaviour , "sequence cannot be 0" ),
598- },
599- {
600- "client-id too short" ,
601- func () {
602- soloMachineMisbehaviour := ibctesting .NewSolomachine (suite .T (), suite .chainA .Codec , "solomachine" , "" , 2 ).CreateMisbehaviour ()
603- msg , err = types .NewMsgSubmitMisbehaviour ("ext" , soloMachineMisbehaviour , suite .chainA .SenderAccount .GetAddress ().String ())
604- suite .Require ().NoError (err )
605- },
606- errorsmod .Wrapf (host .ErrInvalidID , "identifier external has invalid length: 3, must be between 4-64 characters" ),
607- },
608- }
609-
610- for _ , tc := range cases {
611- tc .malleate ()
612- err = msg .ValidateBasic ()
613- if tc .expErr == nil {
614- suite .Require ().NoError (err , tc .name )
615- } else {
616- suite .Require ().Error (err , tc .name )
617- suite .Require ().ErrorIs (err , tc .expErr )
618- }
619- }
620- }
621-
622472// TestMsgRecoverClientValidateBasic tests ValidateBasic for MsgRecoverClient
623473func (suite * TypesTestSuite ) TestMsgRecoverClientValidateBasic () {
624474 var msg * types.MsgRecoverClient
0 commit comments