From 6b5ada08dee414047760ce6dd0fb43ee8f0e8371 Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Wed, 20 Dec 2023 19:13:54 +0200 Subject: [PATCH] Lint, test structure, error case checking. --- modules/core/04-channel/keeper/keeper_test.go | 84 +++++++++++++++++++ modules/core/keeper/msg_server_test.go | 11 +-- 2 files changed, 88 insertions(+), 7 deletions(-) diff --git a/modules/core/04-channel/keeper/keeper_test.go b/modules/core/04-channel/keeper/keeper_test.go index 9cba14d9059..636b963b0d9 100644 --- a/modules/core/04-channel/keeper/keeper_test.go +++ b/modules/core/04-channel/keeper/keeper_test.go @@ -10,6 +10,7 @@ import ( transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + host "github.com/cosmos/ibc-go/v8/modules/core/24-host" "github.com/cosmos/ibc-go/v8/modules/core/exported" ibctesting "github.com/cosmos/ibc-go/v8/testing" ibcmock "github.com/cosmos/ibc-go/v8/testing/mock" @@ -541,3 +542,86 @@ func (suite *KeeperTestSuite) TestUnsetParams() { suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetParams(ctx) }) } + +func (suite *KeeperTestSuite) TestPruneStalePacketData() { + var ( + path *ibctesting.Path + limit uint64 + ) + + testCases := []struct { + name string + pre func() + malleate func() + post func() + expError error + }{ + { + "failure: packet sequence start not set", + func() {}, + func() { + path.EndpointA.ChannelConfig.PortID = "portidone" + }, + func() {}, + types.ErrPruningSequenceStartNotFound, + }, + { + "failure: packet sequence end not set", + func() {}, + func() { + store := suite.chainA.GetContext().KVStore(suite.chainA.GetSimApp().GetKey(exported.StoreKey)) + store.Delete(host.PruningSequenceEndKey(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) + }, + func() {}, + types.ErrPruningSequenceEndNotFound, + }, + } + + for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { + suite.SetupTest() // reset + + path = ibctesting.NewPath(suite.chainA, suite.chainB) + suite.coordinator.Setup(path) + + // TODO(jim): setup.coordinator.UpgradeChannel() wen? + // configure the channel upgrade version on testing endpoints + path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = ibcmock.UpgradeVersion + path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = ibcmock.UpgradeVersion + + err := path.EndpointA.ChanUpgradeInit() + suite.Require().NoError(err) + + err = path.EndpointB.ChanUpgradeTry() + suite.Require().NoError(err) + + err = path.EndpointA.ChanUpgradeAck() + suite.Require().NoError(err) + + err = path.EndpointB.ChanUpgradeConfirm() + suite.Require().NoError(err) + + err = path.EndpointA.ChanUpgradeOpen() + suite.Require().NoError(err) + + err = path.EndpointA.UpdateClient() + suite.Require().NoError(err) + + limit = 10 + + tc.malleate() + + err = suite.chainA.App.GetIBCKeeper().ChannelKeeper.PruneAcknowledgements( + suite.chainA.GetContext(), + path.EndpointA.ChannelConfig.PortID, + path.EndpointA.ChannelID, + limit, + ) + + suite.Require().ErrorIs(err, tc.expError) + + tc.post() + }) + } +} diff --git a/modules/core/keeper/msg_server_test.go b/modules/core/keeper/msg_server_test.go index 81520dd335b..ee8444514e5 100644 --- a/modules/core/keeper/msg_server_test.go +++ b/modules/core/keeper/msg_server_test.go @@ -2018,9 +2018,7 @@ func (suite *KeeperTestSuite) TestUpdateConnectionParams() { } func (suite *KeeperTestSuite) TestPruneAcknowledgements() { - var ( - path *ibctesting.Path - ) + var msg *channeltypes.MsgPruneAcknowledgements testCases := []struct { name string @@ -2035,8 +2033,7 @@ func (suite *KeeperTestSuite) TestPruneAcknowledgements() { { "failure: core keeper function fails, pruning sequence end not found", func() { - store := suite.chainA.GetContext().KVStore(suite.chainA.GetSimApp().GetKey(exported.ModuleName)) - store.Delete(host.PruningSequenceEndKey(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) + msg.PortId = "portidone" }, channeltypes.ErrPruningSequenceEndNotFound, }, @@ -2047,7 +2044,7 @@ func (suite *KeeperTestSuite) TestPruneAcknowledgements() { suite.Run(tc.name, func() { suite.SetupTest() - path = ibctesting.NewPath(suite.chainA, suite.chainB) + path := ibctesting.NewPath(suite.chainA, suite.chainB) suite.coordinator.Setup(path) // configure the channel upgrade version on testing endpoints @@ -2072,7 +2069,7 @@ func (suite *KeeperTestSuite) TestPruneAcknowledgements() { err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - msg := channeltypes.NewMsgPruneAcknowledgements( + msg = channeltypes.NewMsgPruneAcknowledgements( path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, 10,