Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix test TestSerializeAndDeserializeCosmosTx, use expected errors #7780

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions modules/apps/27-interchain-accounts/types/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (suite *TypesTestSuite) TestSerializeAndDeserializeCosmosTx() {
testCases := []struct {
name string
malleate func()
expPass bool
expErr error
}{
{
"single msg",
Expand All @@ -66,7 +66,7 @@ func (suite *TypesTestSuite) TestSerializeAndDeserializeCosmosTx() {
},
}
},
true,
nil,
},
{
"multiple msgs, same types",
Expand All @@ -84,7 +84,7 @@ func (suite *TypesTestSuite) TestSerializeAndDeserializeCosmosTx() {
},
}
},
true,
nil,
},
{
"success: multiple msgs, different types",
Expand All @@ -102,7 +102,7 @@ func (suite *TypesTestSuite) TestSerializeAndDeserializeCosmosTx() {
},
}
},
true,
nil,
},
{
"success: msg with nested any",
Expand All @@ -122,7 +122,7 @@ func (suite *TypesTestSuite) TestSerializeAndDeserializeCosmosTx() {
},
}
},
true,
nil,
},
{
"success: msg with nested array of any",
Expand Down Expand Up @@ -170,14 +170,14 @@ func (suite *TypesTestSuite) TestSerializeAndDeserializeCosmosTx() {

msgs = []proto.Message{propMsg}
},
true,
nil,
},
{
"success: empty messages",
func() {
msgs = []proto.Message{}
},
true,
nil,
},
{
"failure: unregistered msg type",
Expand All @@ -189,7 +189,7 @@ func (suite *TypesTestSuite) TestSerializeAndDeserializeCosmosTx() {
expSerializeErrorStrings = []string{"NO_ERROR_EXPECTED", "cannot marshal CosmosTx with proto3 json"}
expDeserializeErrorStrings = []string{"cannot unmarshal CosmosTx with protobuf", "cannot unmarshal CosmosTx with proto3 json"}
},
false,
ibcerrors.ErrInvalidType,
},
{
"failure: multiple unregistered msg types",
Expand All @@ -203,7 +203,7 @@ func (suite *TypesTestSuite) TestSerializeAndDeserializeCosmosTx() {
expSerializeErrorStrings = []string{"NO_ERROR_EXPECTED", "cannot marshal CosmosTx with proto3 json"}
expDeserializeErrorStrings = []string{"cannot unmarshal CosmosTx with protobuf", "cannot unmarshal CosmosTx with proto3 json"}
},
false,
ibcerrors.ErrInvalidType,
},
{
"failure: nested unregistered msg",
Expand All @@ -223,7 +223,7 @@ func (suite *TypesTestSuite) TestSerializeAndDeserializeCosmosTx() {
expSerializeErrorStrings = []string{"NO_ERROR_EXPECTED", "cannot marshal CosmosTx with proto3 json"}
expDeserializeErrorStrings = []string{"cannot unmarshal CosmosTx with protobuf", "cannot unmarshal CosmosTx with proto3 json"}
},
false,
ibcerrors.ErrInvalidType,
},
{
"failure: nested array of unregistered msg",
Expand All @@ -248,7 +248,7 @@ func (suite *TypesTestSuite) TestSerializeAndDeserializeCosmosTx() {
expSerializeErrorStrings = []string{"NO_ERROR_EXPECTED", "cannot marshal CosmosTx with proto3 json"}
expDeserializeErrorStrings = []string{"cannot unmarshal CosmosTx with protobuf", "cannot unmarshal CosmosTx with proto3 json"}
},
false,
ibcerrors.ErrInvalidType,
},
}

Expand All @@ -259,23 +259,25 @@ func (suite *TypesTestSuite) TestSerializeAndDeserializeCosmosTx() {
suite.Run(tc.name, func() {
tc.malleate()

expPass := tc.expErr == nil
bz, err := types.SerializeCosmosTx(suite.chainA.Codec, msgs, encoding)
if encoding == types.EncodingProto3JSON && !tc.expPass {
if encoding == types.EncodingProto3JSON && !expPass {
suite.Require().Error(err, tc.name)
suite.Require().Contains(err.Error(), expSerializeErrorStrings[1], tc.name)
} else {
suite.Require().NoError(err, tc.name)
}

deserializedMsgs, err := types.DeserializeCosmosTx(suite.chainA.Codec, bz, encoding)
if tc.expPass {
if expPass {
suite.Require().NoError(err, tc.name)
} else {
suite.Require().Error(err, tc.name)
suite.Require().Contains(err.Error(), expDeserializeErrorStrings[i], tc.name)
suite.Require().ErrorIs(err, tc.expErr)
}

if tc.expPass {
if expPass {
for i, msg := range msgs {
// We're using proto.CompactTextString() for comparison instead of suite.Require().Equal() or proto.Equal()
// for two main reasons:
Expand Down
Loading