From d0041599dddcdcf90797f1e1751ce8a235b5b439 Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Tue, 22 Oct 2024 09:10:47 +0300 Subject: [PATCH] tests: fix ProvideCounterparty test. --- .../04-channel/v2/keeper/msg_server_test.go | 66 +++++++++++-------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/modules/core/04-channel/v2/keeper/msg_server_test.go b/modules/core/04-channel/v2/keeper/msg_server_test.go index 028489c8315..58587d44b89 100644 --- a/modules/core/04-channel/v2/keeper/msg_server_test.go +++ b/modules/core/04-channel/v2/keeper/msg_server_test.go @@ -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) + } + }) } }