Skip to content

Commit

Permalink
feat: v6 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
hallazzang committed Dec 18, 2024
1 parent 8f63512 commit ab49b0c
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 71 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import (
milkywayabci "github.com/milkyway-labs/milkyway/v6/app/abci"
"github.com/milkyway-labs/milkyway/v6/app/keepers"
"github.com/milkyway-labs/milkyway/v6/app/upgrades"
v5 "github.com/milkyway-labs/milkyway/v6/app/upgrades/v5"
v6 "github.com/milkyway-labs/milkyway/v6/app/upgrades/v6"
_ "github.com/milkyway-labs/milkyway/v6/client/docs/statik"
liquidvestingtypes "github.com/milkyway-labs/milkyway/v6/x/liquidvesting/types"
)
Expand All @@ -78,7 +78,7 @@ var (
DefaultNodeHome string

Upgrades = []upgrades.Upgrade{
v5.Upgrade,
v6.Upgrade,
}
)

Expand Down
56 changes: 0 additions & 56 deletions app/upgrades/v5/upgrades.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v5
package v6

import (
storetypes "cosmossdk.io/store/types"
Expand Down
59 changes: 59 additions & 0 deletions app/upgrades/v6/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package v6

import (
"context"

upgradetypes "cosmossdk.io/x/upgrade/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
connecttypes "github.com/skip-mev/connect/v2/pkg/types"
oracletypes "github.com/skip-mev/connect/v2/x/oracle/types"

"github.com/milkyway-labs/milkyway/v6/app/keepers"
liquidvestingtypes "github.com/milkyway-labs/milkyway/v6/x/liquidvesting/types"
)

func CreateUpgradeHandler(
mm *module.Manager,
configuration module.Configurator,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
vm, err := mm.RunMigrations(ctx, configuration, fromVM)
if err != nil {
return nil, err
}

// Unwrap the context
sdkCtx := sdk.UnwrapSDKContext(ctx)

// Overwrite liquidvesting module account.
liquidVestingModuleAddr := keepers.AccountKeeper.GetModuleAddress(liquidvestingtypes.ModuleName)
acc := keepers.AccountKeeper.GetAccount(ctx, liquidVestingModuleAddr)
if acc != nil {
_, ok := acc.(sdk.ModuleAccountI)
if !ok {
keepers.AccountKeeper.RemoveAccount(ctx, acc)
keepers.AccountKeeper.GetModuleAccount(ctx, liquidvestingtypes.ModuleName)
}
}

// Delete all currency pairs. We use IterateCurrencyPairs instead of
// GetAllCurrencyPairs to check the returned error.
var currencyPairs []connecttypes.CurrencyPair
err = keepers.OracleKeeper.IterateCurrencyPairs(sdkCtx, func(cp connecttypes.CurrencyPair, _ oracletypes.CurrencyPairState) {
currencyPairs = append(currencyPairs, cp)
})
if err != nil {
return nil, err
}
for _, cp := range currencyPairs {
err = keepers.OracleKeeper.RemoveCurrencyPair(sdkCtx, cp)
if err != nil {
return nil, err
}
}

return vm, nil
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v5_test
package v6_test

import (
"testing"
Expand All @@ -9,11 +9,14 @@ import (
upgradetypes "cosmossdk.io/x/upgrade/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/stretchr/testify/suite"

milkywayapp "github.com/milkyway-labs/milkyway/v6/app"
"github.com/milkyway-labs/milkyway/v6/app/helpers"
v4 "github.com/milkyway-labs/milkyway/v6/app/upgrades/v5"
v4 "github.com/milkyway-labs/milkyway/v6/app/upgrades/v6"
"github.com/milkyway-labs/milkyway/v6/utils"
liquidvestingtypes "github.com/milkyway-labs/milkyway/v6/x/liquidvesting/types"
)

func TestUpgradeTestSuite(t *testing.T) {
Expand All @@ -35,7 +38,7 @@ func (suite *UpgradeTestSuite) SetupTest() {
suite.UpgradeModule = upgrade.NewAppModule(suite.App.UpgradeKeeper, suite.App.AccountKeeper.AddressCodec())
}

func (suite *UpgradeTestSuite) TestUpgradeV4() {
func (suite *UpgradeTestSuite) TestUpgradeV6() {
// Make sure the markets are set
markets, err := suite.App.MarketMapKeeper.GetAllMarkets(suite.Ctx)
suite.Require().NoError(err)
Expand All @@ -45,19 +48,31 @@ func (suite *UpgradeTestSuite) TestUpgradeV4() {
currencyPairs := suite.App.OracleKeeper.GetAllCurrencyPairs(suite.Ctx)
suite.Require().Len(currencyPairs, 63)

// In testnet v5, we have liquid vesting module account set as a BaseAccount.
liquidVestingModuleAddr := suite.App.AccountKeeper.GetModuleAddress(liquidvestingtypes.ModuleName)
acc := suite.App.AccountKeeper.GetAccount(suite.Ctx, liquidVestingModuleAddr)
suite.App.AccountKeeper.RemoveAccount(suite.Ctx, acc)
err = suite.App.BankKeeper.MintCoins(suite.Ctx, minttypes.ModuleName, utils.MustParseCoins("1utia"))
suite.Require().NoError(err)
err = suite.App.BankKeeper.SendCoinsFromModuleToAccount(
suite.Ctx,
minttypes.ModuleName,
liquidVestingModuleAddr,
utils.MustParseCoins("1utia"),
)
suite.Require().NoError(err)

// Perform the upgrade
suite.performUpgrade()

// Make sure only the TIA/USD market is left
markets, err = suite.App.MarketMapKeeper.GetAllMarkets(suite.Ctx)
suite.Require().NoError(err)
suite.Require().Len(markets, 1)
suite.Require().Equal("TIA/USD", markets["TIA/USD"].Ticker.String())

// Make sure the only currency pair left is TIA/USD
// Make sure all the currency pairs are deleted
currencyPairs = suite.App.OracleKeeper.GetAllCurrencyPairs(suite.Ctx)
suite.Require().Len(currencyPairs, 1)
suite.Require().Equal("TIA/USD", currencyPairs[0].String())
suite.Require().Empty(currencyPairs)

acc = suite.App.AccountKeeper.GetAccount(suite.Ctx, liquidVestingModuleAddr)
suite.Require().NotNil(acc)
_, ok := acc.(sdk.ModuleAccountI)
suite.Require().True(ok)
}

func (suite *UpgradeTestSuite) performUpgrade() {
Expand Down

0 comments on commit ab49b0c

Please sign in to comment.