-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ica: move Serialize/DeserializeCosmosTx to package types (#493)
* moving SerializeCosmosTx and DeserializeCosmosTx to types pkg * removing dead code * adding mockSdkMsg message type for failing codec test scenarios * Update modules/apps/27-interchain-accounts/types/codec_test.go
- Loading branch information
1 parent
bd10403
commit 03ada27
Showing
7 changed files
with
186 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
modules/apps/27-interchain-accounts/types/codec_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package types_test | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
|
||
"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types" | ||
"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, used 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 { | ||
name string | ||
msgs []sdk.Msg | ||
expPass bool | ||
}{ | ||
{ | ||
"single msg", | ||
[]sdk.Msg{ | ||
&banktypes.MsgSend{ | ||
FromAddress: TestOwnerAddress, | ||
ToAddress: TestOwnerAddress, | ||
Amount: sdk.NewCoins(sdk.NewCoin("bananas", sdk.NewInt(100))), | ||
}, | ||
}, | ||
true, | ||
}, | ||
{ | ||
"multiple msgs, same types", | ||
[]sdk.Msg{ | ||
&banktypes.MsgSend{ | ||
FromAddress: TestOwnerAddress, | ||
ToAddress: TestOwnerAddress, | ||
Amount: sdk.NewCoins(sdk.NewCoin("bananas", sdk.NewInt(100))), | ||
}, | ||
&banktypes.MsgSend{ | ||
FromAddress: TestOwnerAddress, | ||
ToAddress: TestOwnerAddress, | ||
Amount: sdk.NewCoins(sdk.NewCoin("bananas", sdk.NewInt(200))), | ||
}, | ||
}, | ||
true, | ||
}, | ||
{ | ||
"multiple msgs, different types", | ||
[]sdk.Msg{ | ||
&banktypes.MsgSend{ | ||
FromAddress: TestOwnerAddress, | ||
ToAddress: TestOwnerAddress, | ||
Amount: sdk.NewCoins(sdk.NewCoin("bananas", sdk.NewInt(100))), | ||
}, | ||
&govtypes.MsgSubmitProposal{ | ||
InitialDeposit: sdk.NewCoins(sdk.NewCoin("bananas", sdk.NewInt(100))), | ||
Proposer: TestOwnerAddress, | ||
}, | ||
}, | ||
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) | ||
suite.Require().NoError(err, tc.name) | ||
|
||
testCasesAny = append(testCasesAny, caseRawBytes{tc.name, bz, tc.expPass}) | ||
} | ||
|
||
for i, tc := range testCasesAny { | ||
msgs, err := types.DeserializeCosmosTx(simapp.MakeTestEncodingConfig().Marshaler, tc.bz) | ||
if tc.expPass { | ||
suite.Require().NoError(err, tc.name) | ||
suite.Require().Equal(testCases[i].msgs, msgs, tc.name) | ||
} else { | ||
suite.Require().Error(err, tc.name) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.