-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
minor channel fixes #8665
Merged
colin-axner
merged 10 commits into
cosmos:master
from
damiannolan:damiannolan/7949-minor-channel-fixes
Mar 1, 2021
Merged
minor channel fixes #8665
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
45e9c96
Consolidating codec.go registrations. Moving Acknowledgement result/e…
damiannolan 3054481
Merge branch 'master' into damiannolan/7949-minor-channel-fixes
colin-axner 2a2cae8
Updating CHANGELOG.md with #7949 improvement as requested
damiannolan e1179b4
Merge branch 'master' into damiannolan/7949-minor-channel-fixes
damiannolan 438bb4b
Merge branch 'master' into damiannolan/7949-minor-channel-fixes
colin-axner 4510638
Merge branch 'master' into damiannolan/7949-minor-channel-fixes
colin-axner 3d6912d
revert removing acknowledgement proto to its own file
colin-axner 4e660db
update changelog
colin-axner ba666f4
remove unnecessary pb.go file
colin-axner cb00cbb
Merge branch 'master' into damiannolan/7949-minor-channel-fixes
colin-axner 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package types | ||
|
||
import ( | ||
"strings" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
// NewResultAcknowledgement returns a new instance of Acknowledgement using an Acknowledgement_Result | ||
// type in the Response field. | ||
func NewResultAcknowledgement(result []byte) Acknowledgement { | ||
return Acknowledgement{ | ||
Response: &Acknowledgement_Result{ | ||
Result: result, | ||
}, | ||
} | ||
} | ||
|
||
// NewErrorAcknowledgement returns a new instance of Acknowledgement using an Acknowledgement_Error | ||
// type in the Response field. | ||
func NewErrorAcknowledgement(err string) Acknowledgement { | ||
return Acknowledgement{ | ||
Response: &Acknowledgement_Error{ | ||
Error: err, | ||
}, | ||
} | ||
} | ||
|
||
// GetBytes is a helper for serialising acknowledgements | ||
func (ack Acknowledgement) GetBytes() []byte { | ||
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&ack)) | ||
} | ||
|
||
// ValidateBasic performs a basic validation of the acknowledgement | ||
func (ack Acknowledgement) ValidateBasic() error { | ||
switch resp := ack.Response.(type) { | ||
case *Acknowledgement_Result: | ||
if len(resp.Result) == 0 { | ||
return sdkerrors.Wrap(ErrInvalidAcknowledgement, "acknowledgement result cannot be empty") | ||
} | ||
case *Acknowledgement_Error: | ||
if strings.TrimSpace(resp.Error) == "" { | ||
return sdkerrors.Wrap(ErrInvalidAcknowledgement, "acknowledgement error cannot be empty") | ||
} | ||
default: | ||
return sdkerrors.Wrapf(ErrInvalidAcknowledgement, "unsupported acknowledgement response field type %T", resp) | ||
} | ||
return nil | ||
} |
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,63 @@ | ||
package types_test | ||
|
||
import "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types" | ||
|
||
// tests acknowledgement.ValidateBasic and acknowledgement.GetBytes | ||
func (suite TypesTestSuite) TestAcknowledgement() { | ||
testCases := []struct { | ||
name string | ||
ack types.Acknowledgement | ||
expPass bool | ||
}{ | ||
{ | ||
"valid successful ack", | ||
types.NewResultAcknowledgement([]byte("success")), | ||
true, | ||
}, | ||
{ | ||
"valid failed ack", | ||
types.NewErrorAcknowledgement("error"), | ||
true, | ||
}, | ||
{ | ||
"empty successful ack", | ||
types.NewResultAcknowledgement([]byte{}), | ||
false, | ||
}, | ||
{ | ||
"empty faied ack", | ||
types.NewErrorAcknowledgement(" "), | ||
false, | ||
}, | ||
{ | ||
"nil response", | ||
types.Acknowledgement{ | ||
Response: nil, | ||
}, | ||
false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
|
||
suite.Run(tc.name, func() { | ||
suite.SetupTest() | ||
|
||
err := tc.ack.ValidateBasic() | ||
|
||
if tc.expPass { | ||
suite.Require().NoError(err) | ||
} else { | ||
suite.Require().Error(err) | ||
} | ||
|
||
// expect all acks to be able to be marshaled | ||
suite.NotPanics(func() { | ||
bz := tc.ack.GetBytes() | ||
suite.Require().NotNil(bz) | ||
}) | ||
}) | ||
} | ||
|
||
} |
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
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.
Is this no longer needed @colin-axner ?
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.
Duplicate registration.
RegisterInterface
will register implementations as well