-
Notifications
You must be signed in to change notification settings - Fork 655
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
feat: adding OnChanUpgradeAck
handler implementation to 29-fee
#4028
Merged
damiannolan
merged 25 commits into
04-channel-upgrades
from
damian/1900-fee-chanupgradeack
Jul 18, 2023
Merged
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
3765d93
WIP: adding fee upgrade cbs and testing
damiannolan 79cb7f8
imp: allow failure expectations when using chain.SendMsgs
damiannolan 64563e8
fixing import errors from cherry-pick
damiannolan e951cc1
updating tests and rm try code
damiannolan 9907ea9
Merge branch '04-channel-upgrades' into damian/fee-upgrade-cbs
damiannolan 391d44b
rm diff onChanUpgradeTry
damiannolan 66ad804
Update modules/apps/29-fee/ibc_middleware.go
damiannolan e277493
adding OnChanUpgradeTry implementation for 29-fee, adding tests
damiannolan 60a1482
rm CR in test expectation
damiannolan e084894
remove goconst linter as discussed async
damiannolan 965efdc
adding onChanUpgradeAck implementation to 29-fee, adding tests
damiannolan 09fbbac
Merge branch '04-channel-upgrades' into damian/fee-upgrade-cbs
damiannolan b19b53b
adding MetadataFromVersion func to pkg types
damiannolan 1f53cd6
addressing pr feedback, disable fees on err, rename args, adding test…
damiannolan db256b2
Update modules/apps/29-fee/ibc_middleware_test.go
damiannolan ae1ea37
abstract out expIsFeeEnabled check in tests
damiannolan fb6a42a
adding additional error context to MetadataFromVersion
damiannolan 28a7db2
Merge branch 'damian/fee-upgrade-cbs' into damian/1900-fee-chanupgrad…
damiannolan e3b75b4
Merge branch '04-channel-upgrades' into damian/1900-fee-chanupgradetry
damiannolan 2ec1e73
propagate changes from onChanUpgradeInit PR
damiannolan 98a9dfd
addressing test assertion feedback
damiannolan 57016ef
Merge branch 'damian/1900-fee-chanupgradetry' into damian/1900-fee-ch…
damiannolan 8047e3a
Merge branch '04-channel-upgrades' into damian/1900-fee-chanupgradeack
damiannolan ff3f639
updating to use types.MetadataFromVersion in OnChanUpgradeAck
damiannolan 12c2b32
updating tests to add additional checks
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ linters: | |
- dogsled | ||
- exportloopref | ||
- errcheck | ||
- goconst | ||
- gocritic | ||
- gofumpt | ||
- gosec | ||
|
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 |
---|---|---|
|
@@ -1004,6 +1004,292 @@ func (suite *FeeTestSuite) TestOnTimeoutPacket() { | |
} | ||
} | ||
|
||
func (suite *FeeTestSuite) TestOnChanUpgradeInit() { | ||
var path *ibctesting.Path | ||
|
||
testCases := []struct { | ||
name string | ||
malleate func() | ||
expError error | ||
}{ | ||
{ | ||
"success", | ||
func() {}, | ||
nil, | ||
}, | ||
{ | ||
"invalid upgrade version", | ||
func() { | ||
path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = "invalid-version" | ||
path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = "invalid-version" | ||
|
||
suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeInit = func(_ sdk.Context, _, _ string, _ channeltypes.Order, _ []string, _ uint64, _, _ string) (string, error) { | ||
return "", ibcmock.MockApplicationCallbackError | ||
} | ||
}, | ||
ibcmock.MockApplicationCallbackError, | ||
}, | ||
{ | ||
"invalid fee version", | ||
func() { | ||
upgradeVersion := string(types.ModuleCdc.MustMarshalJSON(&types.Metadata{FeeVersion: "invalid-version", AppVersion: ibcmock.Version})) | ||
path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = upgradeVersion | ||
path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = upgradeVersion | ||
}, | ||
types.ErrInvalidVersion, | ||
}, | ||
{ | ||
"underlying app callback returns error", | ||
func() { | ||
suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeInit = func(_ sdk.Context, _, _ string, _ channeltypes.Order, _ []string, _ uint64, _, _ string) (string, error) { | ||
return "", ibcmock.MockApplicationCallbackError | ||
} | ||
}, | ||
ibcmock.MockApplicationCallbackError, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
suite.Run(tc.name, func() { | ||
suite.SetupTest() | ||
|
||
path = ibctesting.NewPath(suite.chainA, suite.chainB) | ||
|
||
// configure the initial path to create an unincentivized mock channel | ||
path.EndpointA.ChannelConfig.PortID = ibctesting.MockFeePort | ||
path.EndpointB.ChannelConfig.PortID = ibctesting.MockFeePort | ||
path.EndpointA.ChannelConfig.Version = ibcmock.Version | ||
path.EndpointB.ChannelConfig.Version = ibcmock.Version | ||
|
||
suite.coordinator.Setup(path) | ||
|
||
// configure the channel upgrade version to enabled ics29 fee middleware | ||
upgradeVersion := string(types.ModuleCdc.MustMarshalJSON(&types.Metadata{FeeVersion: types.Version, AppVersion: ibcmock.Version})) | ||
path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = upgradeVersion | ||
path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = upgradeVersion | ||
|
||
tc.malleate() | ||
|
||
err := path.EndpointA.ChanUpgradeInit() | ||
|
||
isFeeEnabled := suite.chainA.GetSimApp().IBCFeeKeeper.IsFeeEnabled(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) | ||
|
||
expPass := tc.expError == nil | ||
if expPass { | ||
suite.Require().True(isFeeEnabled) | ||
suite.Require().NoError(err) | ||
} else { | ||
suite.Require().False(isFeeEnabled) | ||
suite.Require().Error(err) | ||
suite.Require().ErrorIs(err, tc.expError) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func (suite *FeeTestSuite) TestOnChanUpgradeTry() { | ||
var path *ibctesting.Path | ||
|
||
testCases := []struct { | ||
name string | ||
malleate func() | ||
expError error | ||
}{ | ||
{ | ||
"success", | ||
func() {}, | ||
nil, | ||
}, | ||
{ | ||
"invalid upgrade version", | ||
func() { | ||
counterpartyUpgrade := path.EndpointA.GetChannelUpgrade() | ||
counterpartyUpgrade.Fields.Version = "invalid-version" | ||
path.EndpointA.SetChannelUpgrade(counterpartyUpgrade) | ||
|
||
suite.coordinator.CommitBlock(suite.chainA) | ||
|
||
suite.chainB.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeTry = func(_ sdk.Context, _, _ string, _ channeltypes.Order, _ []string, _ string) (string, error) { | ||
return "", ibcmock.MockApplicationCallbackError | ||
} | ||
}, | ||
channeltypes.NewUpgradeError(1, ibcmock.MockApplicationCallbackError), | ||
}, | ||
{ | ||
"invalid fee version", | ||
func() { | ||
upgradeVersion := string(types.ModuleCdc.MustMarshalJSON(&types.Metadata{FeeVersion: "invalid-version", AppVersion: ibcmock.Version})) | ||
|
||
counterpartyUpgrade := path.EndpointA.GetChannelUpgrade() | ||
counterpartyUpgrade.Fields.Version = upgradeVersion | ||
path.EndpointA.SetChannelUpgrade(counterpartyUpgrade) | ||
|
||
suite.coordinator.CommitBlock(suite.chainA) | ||
}, | ||
channeltypes.NewUpgradeError(1, types.ErrInvalidVersion), | ||
}, | ||
{ | ||
"underlying app callback returns error", | ||
func() { | ||
suite.chainB.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeTry = func(_ sdk.Context, _, _ string, _ channeltypes.Order, _ []string, _ string) (string, error) { | ||
return "", ibcmock.MockApplicationCallbackError | ||
} | ||
}, | ||
channeltypes.NewUpgradeError(1, ibcmock.MockApplicationCallbackError), | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
suite.Run(tc.name, func() { | ||
suite.SetupTest() | ||
|
||
path = ibctesting.NewPath(suite.chainA, suite.chainB) | ||
|
||
// configure the initial path to create an unincentivized mock channel | ||
path.EndpointA.ChannelConfig.PortID = ibctesting.MockFeePort | ||
path.EndpointB.ChannelConfig.PortID = ibctesting.MockFeePort | ||
path.EndpointA.ChannelConfig.Version = ibcmock.Version | ||
path.EndpointB.ChannelConfig.Version = ibcmock.Version | ||
|
||
suite.coordinator.Setup(path) | ||
|
||
// configure the channel upgrade version to enabled ics29 fee middleware | ||
upgradeVersion := string(types.ModuleCdc.MustMarshalJSON(&types.Metadata{FeeVersion: types.Version, AppVersion: ibcmock.Version})) | ||
path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = upgradeVersion | ||
path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = upgradeVersion | ||
|
||
err := path.EndpointA.ChanUpgradeInit() | ||
suite.Require().NoError(err) | ||
|
||
tc.malleate() | ||
|
||
err = path.EndpointB.ChanUpgradeTry() | ||
|
||
isFeeEnabled := suite.chainB.GetSimApp().IBCFeeKeeper.IsFeeEnabled(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) | ||
|
||
expPass := tc.expError == nil | ||
if expPass { | ||
suite.Require().True(isFeeEnabled) | ||
suite.Require().NoError(err) | ||
} else { | ||
suite.Require().False(isFeeEnabled) | ||
suite.Require().NoError(err) | ||
|
||
// NOTE: application callback failure in OnChanUpgradeTry results in an ErrorReceipt being written to state signaling for cancellation | ||
if expUpgradeError, ok := tc.expError.(*channeltypes.UpgradeError); ok { | ||
errorReceipt, found := suite.chainB.GetSimApp().GetIBCKeeper().ChannelKeeper.GetUpgradeErrorReceipt(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) | ||
suite.Require().True(found) | ||
suite.Require().Equal(expUpgradeError.GetErrorReceipt(), errorReceipt) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func (suite *FeeTestSuite) TestOnChanUpgradeAck() { | ||
var path *ibctesting.Path | ||
|
||
testCases := []struct { | ||
name string | ||
malleate func() | ||
expError error | ||
}{ | ||
{ | ||
"success", | ||
func() {}, | ||
nil, | ||
}, | ||
{ | ||
"success with fee middleware disabled", | ||
func() { | ||
suite.chainA.GetSimApp().IBCFeeKeeper.DeleteFeeEnabled(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) | ||
}, | ||
nil, | ||
}, | ||
{ | ||
"invalid upgrade version", | ||
func() { | ||
counterpartyUpgrade := path.EndpointB.GetChannelUpgrade() | ||
counterpartyUpgrade.Fields.Version = "invalid-version" | ||
path.EndpointB.SetChannelUpgrade(counterpartyUpgrade) | ||
|
||
suite.coordinator.CommitBlock(suite.chainB) | ||
}, | ||
channeltypes.NewUpgradeError(1, types.ErrInvalidVersion), | ||
}, | ||
{ | ||
"invalid fee version", | ||
func() { | ||
upgradeVersion := string(types.ModuleCdc.MustMarshalJSON(&types.Metadata{FeeVersion: "invalid-version", AppVersion: ibcmock.Version})) | ||
|
||
counterpartyUpgrade := path.EndpointB.GetChannelUpgrade() | ||
counterpartyUpgrade.Fields.Version = upgradeVersion | ||
path.EndpointB.SetChannelUpgrade(counterpartyUpgrade) | ||
|
||
suite.coordinator.CommitBlock(suite.chainB) | ||
}, | ||
channeltypes.NewUpgradeError(1, types.ErrInvalidVersion), | ||
}, | ||
{ | ||
"underlying app callback returns error", | ||
func() { | ||
suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeAck = func(_ sdk.Context, _, _, _ string) error { | ||
return ibcmock.MockApplicationCallbackError | ||
} | ||
}, | ||
channeltypes.NewUpgradeError(1, ibcmock.MockApplicationCallbackError), | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
suite.Run(tc.name, func() { | ||
suite.SetupTest() | ||
|
||
path = ibctesting.NewPath(suite.chainA, suite.chainB) | ||
|
||
// configure the initial path to create an unincentivized mock channel | ||
path.EndpointA.ChannelConfig.PortID = ibctesting.MockFeePort | ||
path.EndpointB.ChannelConfig.PortID = ibctesting.MockFeePort | ||
path.EndpointA.ChannelConfig.Version = ibcmock.Version | ||
path.EndpointB.ChannelConfig.Version = ibcmock.Version | ||
|
||
suite.coordinator.Setup(path) | ||
|
||
// configure the channel upgrade version to enabled ics29 fee middleware | ||
upgradeVersion := string(types.ModuleCdc.MustMarshalJSON(&types.Metadata{FeeVersion: types.Version, AppVersion: ibcmock.Version})) | ||
path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = upgradeVersion | ||
path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = upgradeVersion | ||
|
||
err := path.EndpointA.ChanUpgradeInit() | ||
suite.Require().NoError(err) | ||
|
||
err = path.EndpointB.ChanUpgradeTry() | ||
suite.Require().NoError(err) | ||
|
||
tc.malleate() | ||
|
||
err = path.EndpointA.ChanUpgradeAck() | ||
|
||
expPass := tc.expError == nil | ||
if expPass { | ||
suite.Require().NoError(err) | ||
} else { | ||
suite.Require().NoError(err) | ||
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. should we see if the |
||
|
||
// NOTE: application callback failure in OnChanUpgradeAck results in an ErrorReceipt being written to state signaling for cancellation | ||
if expUpgradeError, ok := tc.expError.(*channeltypes.UpgradeError); ok { | ||
errorReceipt, found := suite.chainA.GetSimApp().GetIBCKeeper().ChannelKeeper.GetUpgradeErrorReceipt(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) | ||
suite.Require().True(found) | ||
suite.Require().Equal(expUpgradeError.GetErrorReceipt(), errorReceipt) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func (suite *FeeTestSuite) TestGetAppVersion() { | ||
var ( | ||
portID string | ||
|
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.
should we check the
feeEnabled
bool here to see if it's been enabled?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.
yeah totally, I'll update these tests like what I've done in #4019 and #4023