Skip to content

Commit

Permalink
test: adding test for crossing hello trys with historical proofs (#5143)
Browse files Browse the repository at this point in the history
* test: adding test for crossing hello trys with historical proofs

* chore: make format

* chore: address TODO in test case with switch of proof query endpoint
  • Loading branch information
damiannolan authored Nov 27, 2023
1 parent ee240e2 commit 690e885
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions modules/core/04-channel/keeper/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2186,3 +2186,78 @@ func (suite *KeeperTestSuite) TestSyncUpgradeSequence() {
})
}
}

func (suite *KeeperTestSuite) TestChanUpgradeCrossingHelloWithHistoricalProofs() {
var path *ibctesting.Path

testCases := []struct {
name string
malleate func()
expError error
}{
{
"success",
func() {},
nil,
},
{
"counterparty (chain B) has already progressed to ACK step",
func() {
err := path.EndpointB.ChanUpgradeAck()
suite.Require().NoError(err)
},
types.ErrInvalidChannelState,
},
}

for _, tc := range testCases {
tc := tc
suite.Run(tc.name, func() {
suite.SetupTest()

path = ibctesting.NewPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path)

path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = mock.UpgradeVersion
path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = mock.UpgradeVersion

err := path.EndpointA.ChanUpgradeInit()
suite.Require().NoError(err)

err = path.EndpointB.ChanUpgradeInit()
suite.Require().NoError(err)

suite.coordinator.CommitBlock(suite.chainA, suite.chainB)

err = path.EndpointB.UpdateClient()
suite.Require().NoError(err)

historicalChannelProof, historicalUpgradeProof, proofHeight := path.EndpointA.QueryChannelUpgradeProof()

err = path.EndpointA.ChanUpgradeTry()
suite.Require().NoError(err)

tc.malleate()

upgrade, err := suite.chainB.GetSimApp().GetIBCKeeper().ChannelKeeper.ChanUpgradeTry(
suite.chainB.GetContext(),
path.EndpointB.ChannelConfig.PortID,
path.EndpointB.ChannelID,
path.EndpointB.GetChannelUpgrade().Fields.ConnectionHops,
path.EndpointA.GetChannelUpgrade().Fields,
1,
historicalChannelProof,
historicalUpgradeProof,
proofHeight,
)

expPass := tc.expError == nil
if expPass {
suite.Require().NoError(err)
suite.Require().NotEmpty(upgrade)
} else {
suite.Require().ErrorIs(err, tc.expError)
}
})
}
}

0 comments on commit 690e885

Please sign in to comment.