Skip to content

Commit

Permalink
upgrade tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jiujiteiro committed Aug 12, 2022
1 parent 21608bd commit c8fb3ee
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 4 deletions.
50 changes: 46 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package app

import (
"fmt"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
ibcclientclient "github.com/cosmos/ibc-go/v3/modules/core/02-client/client"
ibcclienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
v2 "github.com/realiotech/realio-network/v1/app/upgrades/v2"

evmante "github.com/tharsis/ethermint/app/ante"
srvflags "github.com/tharsis/ethermint/server/flags"
Expand Down Expand Up @@ -239,6 +242,9 @@ type App struct {

// sm is the simulation manager
sm *module.SimulationManager

// the configurator
configurator module.Configurator
}

// New returns a reference to an initialized blockchain app
Expand Down Expand Up @@ -527,7 +533,8 @@ func New(

app.mm.RegisterInvariants(&app.CrisisKeeper)
app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)
app.mm.RegisterServices(module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()))
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
app.mm.RegisterServices(app.configurator)

// create the simulation manager and define the order of the modules for deterministic simulations
app.sm = module.NewSimulationManager(
Expand Down Expand Up @@ -583,6 +590,8 @@ func New(

app.SetEndBlocker(app.EndBlocker)

app.setupUpgradeHandlers()

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
Expand Down Expand Up @@ -727,6 +736,11 @@ func GetMaccPerms() map[string][]string {
return dupMaccPerms
}

// SimulationManager implements the SimulationApp interface
func (app *App) SimulationManager() *module.SimulationManager {
return app.sm
}

// initParamsKeeper init params keeper and its subspaces
func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)
Expand All @@ -749,7 +763,35 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
return paramsKeeper
}

// SimulationManager implements the SimulationApp interface
func (app *App) SimulationManager() *module.SimulationManager {
return app.sm
func (app *App) setupUpgradeHandlers() {
// add upgrade handlers here
// stub for v2 upgrade handler
app.UpgradeKeeper.SetUpgradeHandler(
v2.UpgradeName,
v2.CreateUpgradeHandler(app.mm, app.configurator),
)

// When a planned update height is reached, the old binary will panic
// writing on disk the height and name of the update that triggered it
// This will read that value, and execute the preparations for the upgrade.
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Errorf("failed to read upgrade info from disk: %w", err))
}

if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
return
}

var storeUpgrades *storetypes.StoreUpgrades

switch upgradeInfo.Name {
case v2.UpgradeName:
// no store upgrades in v2
}

if storeUpgrades != nil {
// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades))
}
}
10 changes: 10 additions & 0 deletions app/upgrades/v2/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package v2

const (
// UpgradeName is the shared upgrade plan name for mainnet and testnet
UpgradeName = "v2.0.0"
// MainnetUpgradeHeight defines the Evmos mainnet block height on which the upgrade will take place
MainnetUpgradeHeight = 58700 // (24 * 60 * 60) / 6 + 44300
// UpgradeInfo defines the binaries that will be used for the upgrade
UpgradeInfo = `'{"binaries":{"darwin/arm64":"https://github.com/realiotech/realio-network/releases/download/v0.1.0/realio-network_0.1.0_Darwin_arm64.tar.gz","darwin/x86_64":"https://github.com/realiotech/realio-network/releases/download/v0.1.0/realio-network_0.1.0_Darwin_x86_64.tar.gz","linux/arm64":"https://github.com/realiotech/realio-network/releases/download/v0.1.0/realio-network_0.1.0_Linux_arm64.tar.gz","linux/x86_64":"https://github.com/realiotech/realio-network/releases/download/v0.1.0/realio-network_0.1.0_Linux_x86_64.tar.gz","windows/x86_64":"https://github.com/realiotech/realio-network/releases/download/v0.1.0/realio-network_0.1.0_Windows_x86_64.zip"}}'`
)
20 changes: 20 additions & 0 deletions app/upgrades/v2/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package v2

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

// CreateUpgradeHandler creates an SDK upgrade handler for v2
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
// Refs:
// - https://docs.cosmos.network/master/building-modules/upgrade.html#registering-migrations
// - https://docs.cosmos.network/master/migrations/chain-upgrade-guide-044.html#chain-upgrade
return mm.RunMigrations(ctx, configurator, vm)
}
}

0 comments on commit c8fb3ee

Please sign in to comment.