diff --git a/app/app.go b/app/app.go index ea10c348..5d62f67e 100644 --- a/app/app.go +++ b/app/app.go @@ -773,7 +773,17 @@ func NewWasmApp( // Name returns the name of the App func (app *WasmApp) Name() string { return app.BaseApp.Name() } -// application updates every begin block +// ModuleManager returns instance +func (app *WasmApp) ModuleManager() module.Manager { + return *app.mm +} + +// ModuleConfigurator returns instance +func (app *WasmApp) ModuleConfigurator() module.Configurator { + return app.configurator +} + +// BeginBlocker application updates every begin block func (app *WasmApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { return app.mm.BeginBlock(ctx, req) } diff --git a/x/wasm/module.go b/x/wasm/module.go index c7ea6339..a237a910 100644 --- a/x/wasm/module.go +++ b/x/wasm/module.go @@ -111,7 +111,7 @@ type AppModule struct { // module. It should be incremented on each consensus-breaking change // introduced by the module. To avoid wrong/empty versions, the initial version // should be set to 1. -func (AppModule) ConsensusVersion() uint64 { return 2 } +func (AppModule) ConsensusVersion() uint64 { return 1 } // NewAppModule creates a new AppModule object func NewAppModule( diff --git a/x/wasm/module_integration_test.go b/x/wasm/module_integration_test.go new file mode 100644 index 00000000..0cbec664 --- /dev/null +++ b/x/wasm/module_integration_test.go @@ -0,0 +1,31 @@ +package wasm_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + "github.com/CosmWasm/wasmd/app" + "github.com/CosmWasm/wasmd/x/wasm" +) + +func TestModuleMigrations(t *testing.T) { + wasmApp := app.Setup(false) + ctx := wasmApp.BaseApp.NewContext(false, tmproto.Header{}) + upgradeHandler := func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + return wasmApp.ModuleManager().RunMigrations(ctx, wasmApp.ModuleConfigurator(), fromVM) + } + fromVM := wasmApp.UpgradeKeeper.GetModuleVersionMap(ctx) + fromVM[wasm.ModuleName] = 1 // start with initial version + upgradeHandler(ctx, upgradetypes.Plan{Name: "testing"}, fromVM) + // when + gotVM, err := wasmApp.ModuleManager().RunMigrations(ctx, wasmApp.ModuleConfigurator(), fromVM) + // then + require.NoError(t, err) + assert.Equal(t, uint64(1), gotVM[wasm.ModuleName]) +}