Skip to content

Commit

Permalink
chore: adding defensive check to v7 migrations (#2948)
Browse files Browse the repository at this point in the history
* adding defensive check to v7 migrations

* adding test coverage for absence of tendermint clients
  • Loading branch information
damiannolan authored Dec 19, 2022
1 parent 01dbbca commit 6ccd8f1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions modules/core/02-client/migrations/v7/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
18 changes: 17 additions & 1 deletion modules/core/02-client/migrations/v7/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6ccd8f1

Please sign in to comment.