From 7464fad1cc241f7c5833d6db27704f59fc7f9af0 Mon Sep 17 00:00:00 2001 From: Ajaz Ahmed Ansari Date: Wed, 14 Jun 2023 16:15:15 +0530 Subject: [PATCH] fix: upgrade handler and `updateZoneProposal` (#459) * added migration in upgrade handler * lint * handle is_118 update prop --- app/upgrades/types.go | 20 +++++++------ app/upgrades/upgrades.go | 20 +++++++++++++ app/upgrades_test.go | 28 +++++++++++++++++-- .../keeper/proposal_handler.go | 7 +++++ 4 files changed, 64 insertions(+), 11 deletions(-) diff --git a/app/upgrades/types.go b/app/upgrades/types.go index 2e7d40f65..8e08085f5 100644 --- a/app/upgrades/types.go +++ b/app/upgrades/types.go @@ -13,18 +13,20 @@ import ( const ( ProductionChainID = "quicksilver-2" RhyeChainID = "rhye-1" - DevnetChainID = "quicktest-1" + DevnetChainID = "magic-1" TestChainID = "testchain1" OsmosisTestnetChainID = "osmo-test-5" - V010402rc1UpgradeName = "v1.4.2-rc1" - V010402rc2UpgradeName = "v1.4.2-rc2" - V010402rc3UpgradeName = "v1.4.2-rc3" - V010402rc4UpgradeName = "v1.4.2-rc4" - V010402rc5UpgradeName = "v1.4.2-rc5" - V010402rc6UpgradeName = "v1.4.2-rc6" - V010402rc7UpgradeName = "v1.4.2-rc7" - V010403rc0UpgradeName = "v1.4.3-rc0" + V010402rc1UpgradeName = "v1.4.2-rc1" + V010402rc2UpgradeName = "v1.4.2-rc2" + V010402rc3UpgradeName = "v1.4.2-rc3" + V010402rc4UpgradeName = "v1.4.2-rc4" + V010402rc5UpgradeName = "v1.4.2-rc5" + V010402rc6UpgradeName = "v1.4.2-rc6" + V010402rc7UpgradeName = "v1.4.2-rc7" + V010403rc0UpgradeName = "v1.4.3-rc0" + V010404beta0UpgradeName = "v1.4.4-beta.0" + V010404beta1UpgradeName = "v1.4.4-beta.1" ) // Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal diff --git a/app/upgrades/upgrades.go b/app/upgrades/upgrades.go index 6cf15ee73..67150214e 100644 --- a/app/upgrades/upgrades.go +++ b/app/upgrades/upgrades.go @@ -26,6 +26,8 @@ func Upgrades() []Upgrade { {UpgradeName: V010402rc6UpgradeName, CreateUpgradeHandler: V010402rc6UpgradeHandler}, {UpgradeName: V010402rc7UpgradeName, CreateUpgradeHandler: NoOpHandler}, {UpgradeName: V010403rc0UpgradeName, CreateUpgradeHandler: V010403rc0UpgradeHandler}, + {UpgradeName: V010404beta0UpgradeName, CreateUpgradeHandler: V010404beta0UpgradeHandler}, + {UpgradeName: V010404beta1UpgradeName, CreateUpgradeHandler: NoOpHandler}, } } @@ -275,6 +277,24 @@ func V010403rc0UpgradeHandler( } } +func V010404beta0UpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + appKeepers *keepers.AppKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + if isTestnet(ctx) || isTest(ctx) { + appKeepers.InterchainstakingKeeper.IterateZones(ctx, func(index int64, zone *types.Zone) (stop bool) { + zone.Is_118 = true + appKeepers.InterchainstakingKeeper.SetZone(ctx, zone) + return false + }) + } + + return mm.RunMigrations(ctx, configurator, fromVM) + } +} + // func V010400UpgradeHandler( // mm *module.Manager, // configurator module.Configurator, diff --git a/app/upgrades_test.go b/app/upgrades_test.go index 98f5c9242..75acc0cea 100644 --- a/app/upgrades_test.go +++ b/app/upgrades_test.go @@ -9,14 +9,13 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/cosmos/cosmos-sdk/x/upgrade/types" ibctesting "github.com/cosmos/ibc-go/v5/testing" - "github.com/stretchr/testify/suite" - "github.com/ingenuity-build/quicksilver/app/upgrades" "github.com/ingenuity-build/quicksilver/utils/addressutils" icskeeper "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" prtypes "github.com/ingenuity-build/quicksilver/x/participationrewards/types" tokenfactorytypes "github.com/ingenuity-build/quicksilver/x/tokenfactory/types" + "github.com/stretchr/testify/suite" ) func init() { @@ -330,6 +329,31 @@ func (s *AppTestSuite) TestV010402rc3UpgradeHandler() { s.Require().Equal(0, len(vals)) } +func (s *AppTestSuite) TestV010404beta0UpgradeHandler() { + app := s.GetQuicksilverApp(s.chainA) + // osmosis zone + zone := icstypes.Zone{ + ConnectionId: "connection-77002", + ChainId: upgrades.OsmosisTestnetChainID, + AccountPrefix: "osmo", + LocalDenom: "uqosmo", + BaseDenom: "uosmo", + MultiSend: false, + LiquidityModule: true, + } + s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone) + handler := upgrades.V010404beta0UpgradeHandler(app.mm, app.configurator, &app.AppKeepers) + ctx := s.chainA.GetContext() + + zone, _ = app.InterchainstakingKeeper.GetZone(ctx, upgrades.OsmosisTestnetChainID) + s.Require().False(zone.Is_118) + + _, err := handler(ctx, types.Plan{}, app.mm.GetVersionMap()) + s.Require().NoError(err) + zone, _ = app.InterchainstakingKeeper.GetZone(ctx, upgrades.OsmosisTestnetChainID) + s.Require().True(zone.Is_118) +} + // func (s *AppTestSuite) TestV010400rc6UpgradeHandler() { // app := s.GetQuicksilverApp(s.chainA) // diff --git a/x/interchainstaking/keeper/proposal_handler.go b/x/interchainstaking/keeper/proposal_handler.go index 77e63455d..80ac4ae7f 100644 --- a/x/interchainstaking/keeper/proposal_handler.go +++ b/x/interchainstaking/keeper/proposal_handler.go @@ -197,6 +197,13 @@ func (k *Keeper) HandleUpdateZoneProposal(ctx sdk.Context, p *types.UpdateZonePr case "account_prefix": zone.AccountPrefix = change.Value + case "is_118": + boolValue, err := strconv.ParseBool(change.Value) + if err != nil { + return err + } + zone.Is_118 = boolValue + case "connection_id": if !strings.HasPrefix(change.Value, "connection-") { return errors.New("unexpected connection format")