Skip to content

Commit

Permalink
tests: fix ProvideCounterparty test. (#7501)
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim authored Oct 22, 2024
1 parent 1462fd2 commit fb7509b
Showing 1 changed file with 37 additions and 29 deletions.
66 changes: 37 additions & 29 deletions modules/core/04-channel/v2/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,58 +272,66 @@ func (suite *KeeperTestSuite) TestProvideCounterparty() {
},
nil,
},
{
"failure: creator not set",
func() {
suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.DeleteCreator(suite.chainA.GetContext(), path.EndpointA.ChannelID)
},
ibcerrors.ErrUnauthorized,
},
{
"failure: signer does not match creator",
func() {
msg.Signer = path.EndpointB.Chain.SenderAccount.GetAddress().String()
suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetCreator(suite.chainA.GetContext(), path.EndpointA.ChannelID, ibctesting.TestAccAddress)
},
ibcerrors.ErrUnauthorized,
},
/* // Account sequence mismatch, expected 5, got 6. :thinking:
{
"failure: counterparty does not already exists",
"failure: channel must already exist",
func() {
suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.ChannelStore(suite.chainA.GetContext(), path.EndpointA.ChannelID).Delete([]byte(channeltypesv2.ChannelKey))
},
channeltypesv2.ErrInvalidChannel,
},
*/
}

for _, tc := range cases {
tc := tc
path = ibctesting.NewPath(suite.chainA, suite.chainB)
path.SetupClients()
suite.Run(tc.name, func() {
suite.SetupTest()

suite.Require().NoError(path.EndpointA.CreateChannel())
suite.Require().NoError(path.EndpointB.CreateChannel())
path = ibctesting.NewPath(suite.chainA, suite.chainB)
path.SetupClients()

signer := path.EndpointA.Chain.SenderAccount.GetAddress().String()
msg = channeltypesv2.NewMsgProvideCounterparty(path.EndpointA.ChannelID, path.EndpointB.ChannelID, signer)
suite.Require().NoError(path.EndpointA.CreateChannel())
suite.Require().NoError(path.EndpointB.CreateChannel())

tc.malleate()
signer := path.EndpointA.Chain.SenderAccount.GetAddress().String()
msg = channeltypesv2.NewMsgProvideCounterparty(path.EndpointA.ChannelID, path.EndpointB.ChannelID, signer)

res, err := path.EndpointA.Chain.SendMsgs(msg)
tc.malleate()

res, err := path.EndpointA.Chain.SendMsgs(msg)

expPass := tc.expError == nil
if expPass {
suite.Require().NotNil(res)
suite.Require().Nil(err)
expPass := tc.expError == nil
if expPass {
suite.Require().NotNil(res)
suite.Require().Nil(err)

// Assert counterparty channel id filled in and creator deleted
channel, found := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelID)
suite.Require().True(found)
suite.Require().Equal(channel.CounterpartyChannelId, path.EndpointB.ChannelID)
// Assert counterparty channel id filled in and creator deleted
channel, found := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelID)
suite.Require().True(found)
suite.Require().Equal(channel.CounterpartyChannelId, path.EndpointB.ChannelID)

_, found = suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetCreator(suite.chainA.GetContext(), path.EndpointA.ChannelID)
suite.Require().False(found)
_, found = suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetCreator(suite.chainA.GetContext(), path.EndpointA.ChannelID)
suite.Require().False(found)

seq, found := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetNextSequenceSend(suite.chainA.GetContext(), path.EndpointA.ChannelID)
suite.Require().True(found)
suite.Require().Equal(seq, uint64(1))
} else {
suite.Require().Error(err)
}
seq, found := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetNextSequenceSend(suite.chainA.GetContext(), path.EndpointA.ChannelID)
suite.Require().True(found)
suite.Require().Equal(seq, uint64(1))
} else {
ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expError, "expected error %q, got %q instead", tc.expError, err)
}
})
}
}

Expand Down

0 comments on commit fb7509b

Please sign in to comment.