Skip to content

Commit

Permalink
Lint, test structure, error case checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim committed Dec 20, 2023
1 parent 8787fdf commit 6b5ada0
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 7 deletions.
84 changes: 84 additions & 0 deletions modules/core/04-channel/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
})
}
}
11 changes: 4 additions & 7 deletions modules/core/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2018,9 +2018,7 @@ func (suite *KeeperTestSuite) TestUpdateConnectionParams() {
}

func (suite *KeeperTestSuite) TestPruneAcknowledgements() {
var (
path *ibctesting.Path
)
var msg *channeltypes.MsgPruneAcknowledgements

testCases := []struct {
name string
Expand All @@ -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,
},
Expand All @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 6b5ada0

Please sign in to comment.