Skip to content

Commit

Permalink
fix: upgrade handler and updateZoneProposal (#459)
Browse files Browse the repository at this point in the history
* added migration in upgrade handler

* lint

* handle is_118 update prop
  • Loading branch information
ajansari95 authored Jun 14, 2023
1 parent f7603b2 commit 7464fad
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 11 deletions.
20 changes: 11 additions & 9 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions app/upgrades/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}
}

Expand Down Expand Up @@ -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,
Expand Down
28 changes: 26 additions & 2 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
//
Expand Down
7 changes: 7 additions & 0 deletions x/interchainstaking/keeper/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 7464fad

Please sign in to comment.