From 6ccd8f1859632a9df17e922476d90d5e126ff5ac Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 19 Dec 2022 15:17:07 +0000 Subject: [PATCH] chore: adding defensive check to v7 migrations (#2948) * adding defensive check to v7 migrations * adding test coverage for absence of tendermint clients --- modules/core/02-client/migrations/v7/store.go | 4 ++++ .../core/02-client/migrations/v7/store_test.go | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/modules/core/02-client/migrations/v7/store.go b/modules/core/02-client/migrations/v7/store.go index 20cb2ee2fd0..7d7d6c9cb15 100644 --- a/modules/core/02-client/migrations/v7/store.go +++ b/modules/core/02-client/migrations/v7/store.go @@ -91,6 +91,10 @@ func handleTendermintMigration(ctx sdk.Context, store sdk.KVStore, cdc codec.Bin return err } + if len(clients) == 0 { + return nil // no-op if no tm clients exist + } + if len(clients) > 1 { return sdkerrors.Wrap(sdkerrors.ErrLogic, "more than one Tendermint client collected") } diff --git a/modules/core/02-client/migrations/v7/store_test.go b/modules/core/02-client/migrations/v7/store_test.go index 006ab637531..e0c2ad35d17 100644 --- a/modules/core/02-client/migrations/v7/store_test.go +++ b/modules/core/02-client/migrations/v7/store_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/suite" - "github.com/cosmos/ibc-go/v6/modules/core/02-client/migrations/v7" + v7 "github.com/cosmos/ibc-go/v6/modules/core/02-client/migrations/v7" "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v6/modules/core/24-host" ibctesting "github.com/cosmos/ibc-go/v6/testing" @@ -65,6 +65,22 @@ func (suite *MigrationsV7TestSuite) TestMigrateStore() { suite.assertNoLocalhostClients() } +func (suite *MigrationsV7TestSuite) TestMigrateStoreNoTendermintClients() { + solomachines := []*ibctesting.Solomachine{ + ibctesting.NewSolomachine(suite.T(), suite.chainA.Codec, "06-solomachine-0", "testing", 1), + ibctesting.NewSolomachine(suite.T(), suite.chainA.Codec, "06-solomachine-1", "testing", 4), + } + + suite.createSolomachineClients(solomachines) + suite.createLocalhostClients() + + err := v7.MigrateStore(suite.chainA.GetContext(), suite.chainA.GetSimApp().GetKey(host.StoreKey), suite.chainA.App.AppCodec(), suite.chainA.GetSimApp().IBCKeeper.ClientKeeper) + suite.Require().NoError(err) + + suite.assertSolomachineClients(solomachines) + suite.assertNoLocalhostClients() +} + func (suite *MigrationsV7TestSuite) createSolomachineClients(solomachines []*ibctesting.Solomachine) { // manually generate old protobuf definitions and set in store // NOTE: we cannot use 'CreateClient' and 'UpdateClient' functions since we are