Skip to content

Commit

Permalink
adding mockSdkMsg message type for failing codec test scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed Nov 2, 2021
1 parent b19b590 commit 2218408
Showing 1 changed file with 44 additions and 5 deletions.
49 changes: 44 additions & 5 deletions modules/apps/27-interchain-accounts/types/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,39 @@ import (
"github.com/cosmos/ibc-go/v2/testing/simapp"
)

// caseRawBytes defines a helper struct, used for testing codec operations
type caseRawBytes struct {
name string
bz []byte
expPass bool
}

// mockSdkMsg defines a mock struct for testing codec error scenarios
type mockSdkMsg struct{}

// Reset implements sdk.Msg
func (mockSdkMsg) Reset() {
}

// String implements sdk.Msg
func (mockSdkMsg) String() string {
return ""
}

// ProtoMessage implements sdk.Msg
func (mockSdkMsg) ProtoMessage() {
}

// ValidateBasic implements sdk.Msg
func (mockSdkMsg) ValidateBasic() error {
return nil
}

// GetSigners implements sdk.Msg
func (mockSdkMsg) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{}
}

func (suite *TypesTestSuite) TestSerializeCosmosTx() {

testCases := []struct {
Expand Down Expand Up @@ -64,17 +91,29 @@ func (suite *TypesTestSuite) TestSerializeCosmosTx() {
},
true,
},
{
"unregistered msg type",
[]sdk.Msg{
&mockSdkMsg{},
},
false,
},
{
"multiple unregistered msg types",
[]sdk.Msg{
&mockSdkMsg{},
&mockSdkMsg{},
&mockSdkMsg{},
},
false,
},
}

testCasesAny := []caseRawBytes{}

for _, tc := range testCases {
bz, err := types.SerializeCosmosTx(simapp.MakeTestEncodingConfig().Marshaler, tc.msgs)
if tc.expPass {
suite.Require().NoError(err, tc.name)
} else {
suite.Require().Error(err, tc.name)
}
suite.Require().NoError(err, tc.name)

testCasesAny = append(testCasesAny, caseRawBytes{tc.name, bz, tc.expPass})
}
Expand Down

0 comments on commit 2218408

Please sign in to comment.