Skip to content

Commit

Permalink
Add tests for msg_server.
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim committed Jun 29, 2023
1 parent 53ce5a5 commit 3d87b55
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions modules/core/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,95 @@ func (suite *KeeperTestSuite) TestChannelUpgradeAck() {
}
}

func (suite *KeeperTestSuite) TestChannelUpgradeOpen() {
var (
path *ibctesting.Path
msg *channeltypes.MsgChannelUpgradeOpen
)

cases := []struct {
name string
malleate func()
expResult func(res *channeltypes.MsgChannelUpgradeOpenResponse, err error)
}{
{
"success",
func() {},
func(res *channeltypes.MsgChannelUpgradeOpenResponse, err error) {
suite.Require().NoError(err)
suite.Require().NotNil(res)

channel := path.EndpointA.GetChannel()
suite.Require().Equal(channeltypes.OPEN, channel.State)
suite.Require().Equal(channeltypes.NOTINFLUSH, channel.FlushStatus)
},
},
{
"module capability not found",
func() {
msg.PortId = ibctesting.InvalidID
msg.ChannelId = ibctesting.InvalidID
},
func(res *channeltypes.MsgChannelUpgradeOpenResponse, err error) {
suite.Require().Error(err)
suite.Require().Nil(res)

suite.Require().ErrorIs(err, capabilitytypes.ErrCapabilityNotFound)
},
},
}

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

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

// configure the channel upgrade version on testing endpoints
path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = ibcmock.UpgradeVersion

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

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

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

// Pending update of FlushStatus in WriteUpgradeAck. See issue #3928
counterpartyChannel := path.EndpointB.GetChannel()
counterpartyChannel.FlushStatus = channeltypes.FLUSHCOMPLETE
path.EndpointB.SetChannel(counterpartyChannel)

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

suite.coordinator.CommitBlock(suite.chainA, suite.chainB)
suite.Require().NoError(path.EndpointA.UpdateClient())

counterpartyChannel = path.EndpointB.GetChannel()
proofChannel, _, proofHeight := path.EndpointA.QueryChannelUpgradeProof()

msg = &channeltypes.MsgChannelUpgradeOpen{
PortId: path.EndpointA.ChannelConfig.PortID,
ChannelId: path.EndpointA.ChannelID,
CounterpartyChannelState: counterpartyChannel.State,
ProofChannel: proofChannel,
ProofHeight: proofHeight,
Signer: suite.chainA.SenderAccount.GetAddress().String(),
}

tc.malleate()
res, err := suite.chainA.GetSimApp().GetIBCKeeper().ChannelUpgradeOpen(suite.chainA.GetContext(), msg)

tc.expResult(res, err)
})
}
}

func (suite *KeeperTestSuite) TestChannelUpgradeCancel() {
var (
path *ibctesting.Path
Expand Down

0 comments on commit 3d87b55

Please sign in to comment.