-
Notifications
You must be signed in to change notification settings - Fork 627
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
refactor: use explicit checks in ica controller upgrade handlers #5472
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6fe19e1
refactor: explicit checks in upgrade init and upgrade ack for ica con…
colin-axner 36020cf
test: complete upgrade ack tests
colin-axner 574ec32
test: add code cov
colin-axner c69b26a
lint appease
colin-axner 90c1fc4
nit: use correct error type
colin-axner f5c1936
Merge branch 'main' into colin/5462-controller-cbs
chatton a633ab4
Merge branch 'main' into colin/5462-controller-cbs
chatton 9f70cff
nit comment change
79a81ae
Merge branch 'main' into colin/5462-controller-cbs
93fc242
fix typo
4226d8c
Merge branch 'main' into colin/5462-controller-cbs
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" | ||
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" | ||
host "github.com/cosmos/ibc-go/v8/modules/core/24-host" | ||
ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" | ||
ibctesting "github.com/cosmos/ibc-go/v8/testing" | ||
) | ||
|
||
|
@@ -478,12 +479,26 @@ func (suite *KeeperTestSuite) TestOnChanCloseConfirm() { | |
} | ||
|
||
func (suite *KeeperTestSuite) TestOnChanUpgradeInit() { | ||
const ( | ||
invalidVersion = "invalid-version" | ||
) | ||
|
||
var ( | ||
path *ibctesting.Path | ||
metadata icatypes.Metadata | ||
version string | ||
order channeltypes.Order | ||
) | ||
|
||
// updateMetadata is a helper function which modifies the metadata stored in the channel version | ||
// and marshals it into a string to pass to OnChanUpgradeInit as the counterpartyVersion string. | ||
updateMetadata := func(modificationFn func(*icatypes.Metadata)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated to match upgrade ack |
||
metadata, err := icatypes.MetadataFromVersion(path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version) | ||
suite.Require().NoError(err) | ||
modificationFn(&metadata) | ||
version = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) | ||
} | ||
|
||
testCases := []struct { | ||
name string | ||
malleate func() | ||
|
@@ -495,48 +510,104 @@ func (suite *KeeperTestSuite) TestOnChanUpgradeInit() { | |
nil, | ||
}, | ||
{ | ||
name: "failure: change ICA address", | ||
name: "failure: invalid order", | ||
malleate: func() { | ||
metadata.Address = TestOwnerAddress | ||
order = channeltypes.UNORDERED | ||
}, | ||
expError: icatypes.ErrInvalidAccountAddress, | ||
expError: channeltypes.ErrInvalidChannelOrdering, | ||
}, | ||
{ | ||
name: "failure: change controller connection id", | ||
name: "failure: connectionID not found", | ||
malleate: func() { | ||
metadata.ControllerConnectionId = differentConnectionID | ||
// channelID is provided via the endpoint channelID | ||
path.EndpointA.ChannelID = "invalid channel" | ||
}, | ||
expError: connectiontypes.ErrInvalidConnection, | ||
expError: channeltypes.ErrChannelNotFound, | ||
}, | ||
{ | ||
name: "failure: change host connection id", | ||
name: "failure: invalid proposed connectionHops", | ||
malleate: func() { | ||
metadata.HostConnectionId = differentConnectionID | ||
// connection hops is provided via endpoint connectionID | ||
path.EndpointA.ConnectionID = differentConnectionID | ||
}, | ||
expError: connectiontypes.ErrInvalidConnection, | ||
expError: channeltypes.ErrInvalidUpgrade, | ||
}, | ||
{ | ||
name: "failure: empty version", | ||
malleate: func() { | ||
version = "" | ||
}, | ||
expError: icatypes.ErrInvalidVersion, | ||
}, | ||
{ | ||
name: "failure: cannot decode version string", | ||
malleate: func() { | ||
channel := path.EndpointA.GetChannel() | ||
channel.Version = "invalid-metadata-string" | ||
path.EndpointA.SetChannel(channel) | ||
version = invalidVersion | ||
}, | ||
expError: icatypes.ErrUnknownDataType, | ||
}, | ||
{ | ||
name: "failure: invalid connection hops", | ||
name: "failure: cannot decode self version string", | ||
malleate: func() { | ||
path.EndpointA.ConnectionID = differentConnectionID | ||
ch := path.EndpointA.GetChannel() | ||
ch.Version = invalidVersion | ||
path.EndpointA.SetChannel(ch) | ||
}, | ||
expError: connectiontypes.ErrConnectionNotFound, | ||
expError: icatypes.ErrUnknownDataType, | ||
}, | ||
{ | ||
name: "failure: invalid order", | ||
name: "failure: failed controller metadata validation, invalid encoding", | ||
malleate: func() { | ||
order = channeltypes.UNORDERED | ||
updateMetadata(func(metadata *icatypes.Metadata) { | ||
metadata.Encoding = "invalid-encoding" | ||
}) | ||
}, | ||
expError: channeltypes.ErrInvalidChannelOrdering, | ||
expError: icatypes.ErrInvalidCodec, | ||
}, | ||
{ | ||
name: "failure: failed controller metadata validation, invalid tx type", | ||
malleate: func() { | ||
updateMetadata(func(metadata *icatypes.Metadata) { | ||
metadata.TxType = "invalid-tx-type" | ||
}) | ||
}, | ||
expError: icatypes.ErrUnknownDataType, | ||
}, | ||
{ | ||
name: "failure: failed controller metadata validation, invalid interchain account version", | ||
malleate: func() { | ||
updateMetadata(func(metadata *icatypes.Metadata) { | ||
metadata.Version = "invalid-interchain-account-version" | ||
}) | ||
}, | ||
expError: icatypes.ErrInvalidVersion, | ||
}, | ||
{ | ||
name: "failure: interchain account address changed", | ||
malleate: func() { | ||
updateMetadata(func(metadata *icatypes.Metadata) { | ||
metadata.Address = TestOwnerAddress // use valid address | ||
}) | ||
}, | ||
expError: icatypes.ErrInvalidAccountAddress, | ||
}, | ||
{ | ||
name: "failure: controller connection ID has changed", | ||
malleate: func() { | ||
updateMetadata(func(metadata *icatypes.Metadata) { | ||
metadata.ControllerConnectionId = differentConnectionID | ||
}) | ||
}, | ||
expError: connectiontypes.ErrInvalidConnection, // the explicit checks on the controller connection identifier are unreachable | ||
}, | ||
{ | ||
name: "failure: host connection ID has changed", | ||
malleate: func() { | ||
updateMetadata(func(metadata *icatypes.Metadata) { | ||
metadata.HostConnectionId = differentConnectionID | ||
}) | ||
}, | ||
expError: connectiontypes.ErrInvalidConnection, // the explicit checks on the host connection identifier are unreachable | ||
}, | ||
} | ||
|
||
|
@@ -563,9 +634,12 @@ func (suite *KeeperTestSuite) TestOnChanUpgradeInit() { | |
// this is the actual change to the version. | ||
metadata.Encoding = icatypes.EncodingProto3JSON | ||
|
||
tc.malleate() // malleate mutates test data | ||
path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) | ||
path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) | ||
|
||
version := string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)) | ||
version = path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version | ||
|
||
tc.malleate() // malleate mutates test data | ||
|
||
upgradeVersion, err := path.EndpointA.Chain.GetSimApp().ICAControllerKeeper.OnChanUpgradeInit( | ||
path.EndpointA.Chain.GetContext(), | ||
|
@@ -642,7 +716,24 @@ func (suite *KeeperTestSuite) TestOnChanUpgradeAck() { | |
expError: icatypes.ErrUnknownDataType, | ||
}, | ||
{ | ||
name: "failure: invalid tx type", | ||
name: "failure: channel not found", | ||
malleate: func() { | ||
// channelID is provided via the endpoint channelID | ||
path.EndpointA.ChannelID = "invalid channel" | ||
}, | ||
expError: ibcerrors.ErrNotFound, // GetChannel error is unreachable | ||
}, | ||
{ | ||
name: "failure: failed controller metadata validation, invalid encoding", | ||
malleate: func() { | ||
updateMetadata(func(metadata *icatypes.Metadata) { | ||
metadata.Encoding = "invalid-encoding" | ||
}) | ||
}, | ||
expError: icatypes.ErrInvalidCodec, | ||
}, | ||
{ | ||
name: "failure: failed controller metadata validation, invalid tx type", | ||
malleate: func() { | ||
updateMetadata(func(metadata *icatypes.Metadata) { | ||
metadata.TxType = "invalid-tx-type" | ||
|
@@ -651,10 +742,19 @@ func (suite *KeeperTestSuite) TestOnChanUpgradeAck() { | |
expError: icatypes.ErrUnknownDataType, | ||
}, | ||
{ | ||
name: "failure: interchain account address has changed", | ||
name: "failure: failed controller metadata validation, invalid interchain account version", | ||
malleate: func() { | ||
updateMetadata(func(metadata *icatypes.Metadata) { | ||
metadata.Version = "invalid-interchain-account-version" | ||
}) | ||
}, | ||
expError: icatypes.ErrInvalidVersion, | ||
}, | ||
{ | ||
name: "failure: interchain account address changed", | ||
malleate: func() { | ||
updateMetadata(func(metadata *icatypes.Metadata) { | ||
metadata.Address = "different-address" | ||
metadata.Address = TestOwnerAddress // use valid address | ||
}) | ||
}, | ||
expError: icatypes.ErrInvalidAccountAddress, | ||
|
@@ -663,19 +763,19 @@ func (suite *KeeperTestSuite) TestOnChanUpgradeAck() { | |
name: "failure: controller connection ID has changed", | ||
malleate: func() { | ||
updateMetadata(func(metadata *icatypes.Metadata) { | ||
metadata.ControllerConnectionId = "different-connection-id" | ||
metadata.ControllerConnectionId = differentConnectionID | ||
}) | ||
}, | ||
expError: connectiontypes.ErrInvalidConnectionIdentifier, | ||
expError: connectiontypes.ErrInvalidConnection, // the explicit checks on the controller identifier are unreachable | ||
}, | ||
{ | ||
name: "failure: host connection ID has changed", | ||
malleate: func() { | ||
updateMetadata(func(metadata *icatypes.Metadata) { | ||
metadata.HostConnectionId = "different-host-id" | ||
metadata.HostConnectionId = differentConnectionID | ||
}) | ||
}, | ||
expError: connectiontypes.ErrInvalidConnectionIdentifier, | ||
expError: connectiontypes.ErrInvalidConnection, // the explicit checks on the host identifier are unreachable | ||
}, | ||
} | ||
|
||
|
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 don't feel too strongly about it, but if these checks are not reachable in either
OnChanUpgradeInit
andOnChanUpgradeAck
, couldn't we just remove them and add a comment above the call toValidateControllerMetadata
to explain that this function protects against these changes?