Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: adding defensive check to v7 migrations #2948

Merged
merged 4 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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