forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce system tests - initial version from wasmd
- Loading branch information
Showing
21 changed files
with
3,496 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,52 @@ | ||
package simapp | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
storetypes "cosmossdk.io/store/types" | ||
"cosmossdk.io/x/accounts" | ||
protocolpooltypes "cosmossdk.io/x/protocolpool/types" | ||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
"cosmossdk.io/simapp/upgrades" | ||
"cosmossdk.io/simapp/upgrades/noop" | ||
v051 "cosmossdk.io/simapp/upgrades/v051" | ||
|
||
"github.com/cosmos/cosmos-sdk/types/module" | ||
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" | ||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
) | ||
|
||
// UpgradeName defines the on-chain upgrade name for the sample SimApp upgrade | ||
// from v0.50.x to v0.51.x | ||
// | ||
// NOTE: This upgrade defines a reference implementation of what an upgrade | ||
// could look like when an application is migrating from Cosmos SDK version | ||
// v0.50.x to v0.51.x. | ||
const UpgradeName = "v050-to-v051" | ||
// Upgrades list of chain upgrades | ||
var Upgrades = []upgrades.Upgrade[upgrades.AppKeepers]{v051.Upgrade} | ||
|
||
// RegisterUpgradeHandlers registers the chain upgrade handlers | ||
func (app SimApp) RegisterUpgradeHandlers() { | ||
app.UpgradeKeeper.SetUpgradeHandler( | ||
UpgradeName, | ||
func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { | ||
return app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM) | ||
}, | ||
) | ||
if len(Upgrades) == 0 { | ||
// always have a unique upgrade registered for the current version to test in system tests or manual | ||
Upgrades = append(Upgrades, noop.NewUpgrade[upgrades.AppKeepers](app.Version())) | ||
} | ||
|
||
var keepers upgrades.AppKeepers | ||
app.GetStoreKeys() | ||
// register all upgrade handlers | ||
for _, upgrade := range Upgrades { | ||
app.UpgradeKeeper.SetUpgradeHandler( | ||
upgrade.UpgradeName, | ||
upgrade.CreateUpgradeHandler( | ||
app.ModuleManager, | ||
app.Configurator(), | ||
&keepers, | ||
), | ||
) | ||
} | ||
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() | ||
if err != nil { | ||
panic(err) | ||
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err)) | ||
} | ||
|
||
if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { | ||
storeUpgrades := storetypes.StoreUpgrades{ | ||
Added: []string{ | ||
accounts.ModuleName, | ||
protocolpooltypes.ModuleName, | ||
}, | ||
Deleted: []string{ | ||
crisistypes.ModuleName, // The SDK discontinued the crisis module in v0.51.0 | ||
}, | ||
} | ||
if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { | ||
return | ||
} | ||
|
||
// configure store loader that checks if version == upgradeHeight and applies store upgrades | ||
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) | ||
// register store loader for current upgrade | ||
for _, upgrade := range Upgrades { | ||
if upgradeInfo.Name == upgrade.UpgradeName { | ||
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgrade.StoreUpgrades)) // nolint:gosec | ||
break | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package noop | ||
|
||
import ( | ||
"context" | ||
|
||
"cosmossdk.io/simapp/upgrades" | ||
|
||
storetypes "cosmossdk.io/store/types" | ||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/types/module" | ||
) | ||
|
||
// NewUpgrade constructor | ||
func NewUpgrade[T upgrades.AppKeepers](semver string) upgrades.Upgrade[T] { | ||
return upgrades.Upgrade[T]{ | ||
UpgradeName: semver, | ||
CreateUpgradeHandler: CreateUpgradeHandler[T], | ||
StoreUpgrades: storetypes.StoreUpgrades{ | ||
Added: []string{}, | ||
Deleted: []string{}, | ||
}, | ||
} | ||
} | ||
|
||
func CreateUpgradeHandler[T upgrades.AppKeepers]( | ||
mm upgrades.ModuleManager, | ||
configurator module.Configurator, | ||
ak *T, | ||
) upgradetypes.UpgradeHandler { | ||
return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { | ||
return mm.RunMigrations(ctx, configurator, fromVM) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package upgrades | ||
|
||
import ( | ||
"context" | ||
|
||
storetypes "cosmossdk.io/store/types" | ||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/types/module" | ||
) | ||
|
||
// AppKeepers placeholder type to customize for concrete use cases | ||
type AppKeepers any | ||
|
||
type ModuleManager interface { | ||
RunMigrations(ctx context.Context, cfg module.Configurator, fromVM module.VersionMap) (module.VersionMap, error) | ||
GetVersionMap() module.VersionMap | ||
} | ||
|
||
// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal | ||
// must have written, in order for the state migration to go smoothly. | ||
// An upgrade must implement this struct, and then set it in the app.go. | ||
// The app.go will then define the handler. | ||
type Upgrade[T AppKeepers] struct { | ||
// Upgrade version name, for the upgrade handler, e.g. `v0.51.0` | ||
UpgradeName string | ||
|
||
// CreateUpgradeHandler defines the function that creates an upgrade handler | ||
CreateUpgradeHandler func(ModuleManager, module.Configurator, *T) upgradetypes.UpgradeHandler | ||
StoreUpgrades storetypes.StoreUpgrades | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package v051 | ||
|
||
import ( | ||
"context" | ||
|
||
"cosmossdk.io/simapp/upgrades" | ||
"cosmossdk.io/x/accounts" | ||
protocolpooltypes "cosmossdk.io/x/protocolpool/types" | ||
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" | ||
|
||
storetypes "cosmossdk.io/store/types" | ||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/types/module" | ||
) | ||
|
||
// UpgradeName defines the on-chain upgrade name | ||
const UpgradeName = "v0.51" | ||
|
||
var Upgrade = upgrades.Upgrade[upgrades.AppKeepers]{ | ||
UpgradeName: UpgradeName, | ||
CreateUpgradeHandler: CreateUpgradeHandler[upgrades.AppKeepers], | ||
StoreUpgrades: storetypes.StoreUpgrades{ | ||
Added: []string{ | ||
accounts.StoreKey, | ||
// accounts.ModuleName, | ||
protocolpooltypes.ModuleName, | ||
}, | ||
Deleted: []string{ | ||
crisistypes.ModuleName, // The SDK discontinued the crisis module in v0.51.0 | ||
}, | ||
}, | ||
} | ||
|
||
func CreateUpgradeHandler[T upgrades.AppKeepers]( | ||
mm upgrades.ModuleManager, | ||
configurator module.Configurator, | ||
ak *T, | ||
) upgradetypes.UpgradeHandler { | ||
return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { | ||
return mm.RunMigrations(ctx, configurator, fromVM) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/testnet | ||
/binaries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/make -f | ||
|
||
WAIT_TIME ?= 45s | ||
|
||
all: test | ||
|
||
test: | ||
go test -mod=readonly -failfast -tags='system_test' ./... --wait-time=$(WAIT_TIME) --verbose | ||
|
||
format: | ||
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs gofumpt -w | ||
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs misspell -w | ||
find . -name '*.go' -type f -not -path "./vendor*" -not -path "./tests/system/vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs gci write --skip-generated -s standard -s default -s "prefix(cosmossdk.io)" -s "prefix(github.com/cosmos/cosmos-sdk)" --custom-order | ||
|
||
.PHONY: all test format |
Oops, something went wrong.