-
Notifications
You must be signed in to change notification settings - Fork 593
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
ica: move Serialize/DeserializeCosmosTx to package types #493
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
997115a
moving SerializeCosmosTx and DeserializeCosmosTx to types pkg
damiannolan b19b590
removing dead code
damiannolan 2218408
adding mockSdkMsg message type for failing codec test scenarios
damiannolan 8fe0101
Update modules/apps/27-interchain-accounts/types/codec_test.go
damiannolan 06bd2b3
Merge branch 'interchain-accounts' into damian/458-move-tx-serdes
damiannolan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've adapted these tests from the anys in 02-client. It covers the happy path successfully, but it's seemingly harder to trigger an error than you'd expect. Passing
nil
for example will just evaluate as an empty list and not failThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to create an unregistered sdk.Msg type. I think passing in a non pointer sdk.Msg might also work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried using a value type (non-pointer) sdk.Msg and it can't be done as
ProtoMessage()
only exists on pointer receiver structs.I've updated to include a private/unexported struct in the test file -
mockSdkMsg
and implemented thesdk.Msg
interface funcs with some empty boilerplate. This can trigger a failure scenario of an unregistered msg type.