Skip to content

Commit

Permalink
refactor: simplify OnChanUpgradeTry transfer testing to call module c…
Browse files Browse the repository at this point in the history
…bs directly (#4221)

* feat: implement onChanUpgradeAck for transfer module

* Update modules/apps/transfer/ibc_module_test.go

* refactor: call OnChanUpgradeTry transfer callback directly in favour of full Endpoint call

* refactor: simplify OnChanUpgradeTry transfer testing to call module cbs directly

* lint me

* rm duplicate test from merge
  • Loading branch information
damiannolan authored Aug 2, 2023
1 parent 4c3e57e commit c862d24
Showing 1 changed file with 21 additions and 35 deletions.
56 changes: 21 additions & 35 deletions modules/apps/transfer/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,10 @@ func (suite *TransferTestSuite) TestOnChanUpgradeInit() {
}

func (suite *TransferTestSuite) TestOnChanUpgradeTry() {
var path *ibctesting.Path
var (
counterpartyUpgrade channeltypes.Upgrade
path *ibctesting.Path
)

testCases := []struct {
name string
Expand All @@ -326,37 +329,19 @@ func (suite *TransferTestSuite) TestOnChanUpgradeTry() {
func() {}, // successful happy path for a standalone transfer app is swapping out the underlying connection
nil,
},
{
"invalid upgrade connection",
func() {
path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.ConnectionHops = []string{"connection-100"}
path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.ConnectionHops = []string{"connection-100"}
},
connectiontypes.ErrConnectionNotFound,
},
{
"invalid upgrade ordering",
func() {
// NOTE: counterpartyUpgrade is queried by Endpoint.ChanUpgradeTry() so retrieve and mutate fields here appropriately to force failure
counterpartyUpgrade := path.EndpointA.GetChannelUpgrade()
counterpartyUpgrade.Fields.Ordering = channeltypes.ORDERED
path.EndpointA.SetChannelUpgrade(counterpartyUpgrade)

suite.coordinator.CommitBlock(suite.chainA)
},
channeltypes.NewUpgradeError(1, channeltypes.ErrInvalidChannelOrdering),
channeltypes.ErrInvalidChannelOrdering,
},
{
"invalid upgrade version",
func() {
// NOTE: counterpartyUpgrade is queried by Endpoint.ChanUpgradeTry() so retrieve and mutate fields here appropriately to force failure
counterpartyUpgrade := path.EndpointA.GetChannelUpgrade()
counterpartyUpgrade.Fields.Version = "invalid-version"
path.EndpointA.SetChannelUpgrade(counterpartyUpgrade)

suite.coordinator.CommitBlock(suite.chainA)
},
channeltypes.NewUpgradeError(1, types.ErrInvalidVersion),
types.ErrInvalidVersion,
},
}

Expand All @@ -378,27 +363,28 @@ func (suite *TransferTestSuite) TestOnChanUpgradeTry() {
err := path.EndpointA.ChanUpgradeInit()
suite.Require().NoError(err)

counterpartyUpgrade = path.EndpointA.GetChannelUpgrade()

tc.malleate()

err = path.EndpointB.ChanUpgradeTry()
module, _, err := suite.chainB.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainB.GetContext(), types.PortID)
suite.Require().NoError(err)

cbs, ok := suite.chainB.App.GetIBCKeeper().Router.GetRoute(module)
suite.Require().True(ok)

version, err := cbs.OnChanUpgradeTry(
suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID,
counterpartyUpgrade.Fields.Ordering, counterpartyUpgrade.Fields.ConnectionHops, counterpartyUpgrade.Fields.Version,
)

expPass := tc.expError == nil
if expPass {
suite.Require().NoError(err)

upgrade := path.EndpointB.GetChannelUpgrade()
suite.Require().Equal(upgradePath.EndpointB.ConnectionID, upgrade.Fields.ConnectionHops[0])
suite.Require().Equal(types.Version, version)
} else {
// 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)
} else {
// NOTE: application callback is not reached and instead an error is returned directly to the client
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expError)
}
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expError)
}
})
}
Expand Down

0 comments on commit c862d24

Please sign in to comment.