Skip to content

Commit

Permalink
fix TestSerializeAndDeserializeCosmosTx (#7780)
Browse files Browse the repository at this point in the history
Co-authored-by: Gjermund Garaba <[email protected]>
  • Loading branch information
meoaka3 and gjermundgaraba authored Dec 21, 2024
1 parent a89fbf6 commit a3239a2
Showing 1 changed file with 16 additions and 14 deletions.
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

0 comments on commit a3239a2

Please sign in to comment.