Skip to content

Commit

Permalink
testing: add base upgrade handler (#2144) (#2551)
Browse files Browse the repository at this point in the history
## Description

closes: #XXXX

---

Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

- [ ] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
- [ ] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules/structure.md).
- [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#testing)
- [ ] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`)
- [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code).
- [ ] Added a relevant changelog entry to the `Unreleased` section in `CHANGELOG.md`
- [ ] Re-reviewed `Files changed` in the Github PR explorer
- [ ] Review `Codecov Report` in the comment section below once CI passes

(cherry picked from commit 4b8e534)

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
  • Loading branch information
mergify[bot] and colin-axner authored Oct 19, 2022
1 parent 76dac68 commit 08eb855
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ import (
ibckeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper"
ibcmock "github.com/cosmos/ibc-go/v5/testing/mock"
simappparams "github.com/cosmos/ibc-go/v5/testing/simapp/params"
simappupgrades "github.com/cosmos/ibc-go/v5/testing/simapp/upgrades"
ibctestingtypes "github.com/cosmos/ibc-go/v5/testing/types"
)

Expand Down Expand Up @@ -623,6 +624,8 @@ func NewSimApp(

app.SetEndBlocker(app.EndBlocker)

app.setupUpgradeHandlers()

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
Expand Down Expand Up @@ -847,3 +850,11 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino

return paramsKeeper
}

// setupUpgradeHandlers sets all necessary upgrade handlers for testing purposes
func (app *SimApp) setupUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler(
simappupgrades.DefaultUpgradeName,
simappupgrades.CreateDefaultUpgradeHandler(app.mm, app.configurator),
)
}
23 changes: 23 additions & 0 deletions testing/simapp/upgrades/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package upgrades

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

const (
// DefaultUpgradeName is the default upgrade name used for upgrade tests which do not require special handling.
DefaultUpgradeName = "normal upgrade"
)

// CreateDefaultUpgradeHandler creates an upgrade handler which can be used for regular upgrade tests
// that do not require special logic
func CreateDefaultUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
return mm.RunMigrations(ctx, configurator, vm)
}
}

0 comments on commit 08eb855

Please sign in to comment.