From 4d2e8201ccdc0fc335ae9f6e81dd3a23f8e24766 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Fri, 16 Dec 2022 09:42:14 +0000 Subject: [PATCH 1/2] adding defensive check to v7 migrations --- modules/core/02-client/migrations/v7/store.go | 4 ++++ 1 file changed, 4 insertions(+) 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") } From 7a850eaf7ee9bbb4b5b903173ec92358e21bd887 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Fri, 16 Dec 2022 09:50:30 +0000 Subject: [PATCH 2/2] adding test coverage for absence of tendermint clients --- .../core/02-client/migrations/v7/store_test.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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