* Start implementation * Add implementation + some e2e test * Fix lint * Squashed: sdk upgrade to v0.50 * rebuild protos with newer proto builder (cherry picked from commit fd8f4c1d0d2163f0a504356c16cd2d250f6218f3) * update ibc-go (cherry picked from commit fb8667960fbeedb7d242baa644572986a154d4b6) * bump cosmos-sdk and ibc in the v50 branch (#1616) * tidy * upgade ibc * remove the toolchain command * Bump sdk version * Use correct bech32 prefix * Bump SDK * Enable fraud system test again * Fix genesis param name * Fix import/export simulations * set log level for benchmarks (cherry picked from commit 1cfb93008c596db62d22aba882f37a469546bfb9) * Apply review comments * Remove gov beta1 helpers * Bump sdk version to latest in branch * Fix linter * Setup mergify for main * Update mergify for better branch name --------- Co-authored-by: Pino' Surace <pino.surace@live.it> Co-authored-by: Jacob Gadikian <jacobgadikian@gmail.com>
151 lines
4.6 KiB
Go
151 lines
4.6 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
upgradetypes "cosmossdk.io/x/upgrade/types"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
|
|
|
"github.com/CosmWasm/wasmd/app"
|
|
"github.com/CosmWasm/wasmd/x/wasm/types"
|
|
)
|
|
|
|
func TestModuleMigrations(t *testing.T) {
|
|
wasmApp := app.Setup(t)
|
|
|
|
upgradeHandler := func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { //nolint:unparam
|
|
return wasmApp.ModuleManager.RunMigrations(ctx, wasmApp.Configurator(), fromVM)
|
|
}
|
|
|
|
specs := map[string]struct {
|
|
setup func(ctx sdk.Context)
|
|
startVersion uint64
|
|
exp types.Params
|
|
}{
|
|
"with legacy params migrated": {
|
|
startVersion: 1,
|
|
setup: func(ctx sdk.Context) {
|
|
params := types.Params{
|
|
CodeUploadAccess: types.AllowNobody,
|
|
InstantiateDefaultPermission: types.AccessTypeNobody,
|
|
}
|
|
|
|
// upgrade code shipped with v0.40
|
|
// https://github.com/CosmWasm/wasmd/blob/v0.40.0/app/upgrades.go#L66
|
|
sp, _ := wasmApp.ParamsKeeper.GetSubspace(types.ModuleName)
|
|
keyTable := types.ParamKeyTable()
|
|
if !sp.HasKeyTable() {
|
|
sp.WithKeyTable(keyTable)
|
|
}
|
|
|
|
sp.SetParamSet(ctx, ¶ms)
|
|
},
|
|
exp: types.Params{
|
|
CodeUploadAccess: types.AllowNobody,
|
|
InstantiateDefaultPermission: types.AccessTypeNobody,
|
|
},
|
|
},
|
|
"fresh from genesis": {
|
|
startVersion: wasmApp.ModuleManager.GetVersionMap()[types.ModuleName], // latest
|
|
setup: func(ctx sdk.Context) {},
|
|
exp: types.DefaultParams(),
|
|
},
|
|
}
|
|
for name, spec := range specs {
|
|
t.Run(name, func(t *testing.T) {
|
|
ctx, _ := wasmApp.BaseApp.NewContext(false).CacheContext()
|
|
spec.setup(ctx)
|
|
|
|
fromVM, err := wasmApp.UpgradeKeeper.GetModuleVersionMap(ctx)
|
|
require.NoError(t, err)
|
|
fromVM[types.ModuleName] = spec.startVersion
|
|
_, err = upgradeHandler(ctx, upgradetypes.Plan{Name: "testing"}, fromVM)
|
|
require.NoError(t, err)
|
|
|
|
// when
|
|
gotVM, err := wasmApp.ModuleManager.RunMigrations(ctx, wasmApp.Configurator(), fromVM)
|
|
|
|
// then
|
|
require.NoError(t, err)
|
|
var expModuleVersion uint64 = 4
|
|
assert.Equal(t, expModuleVersion, gotVM[types.ModuleName])
|
|
gotParams := wasmApp.WasmKeeper.GetParams(ctx)
|
|
assert.Equal(t, spec.exp, gotParams)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestAccessConfigMigrations(t *testing.T) {
|
|
addr := "cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x"
|
|
address, err := sdk.AccAddressFromBech32(addr)
|
|
require.NoError(t, err)
|
|
|
|
wasmApp := app.Setup(t)
|
|
|
|
upgradeHandler := func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { //nolint:unparam
|
|
return wasmApp.ModuleManager.RunMigrations(ctx, wasmApp.Configurator(), fromVM)
|
|
}
|
|
|
|
ctx, _ := wasmApp.BaseApp.NewContext(false).CacheContext()
|
|
|
|
// any address permission
|
|
code1, err := storeCode(ctx, wasmApp, types.AccessTypeAnyOfAddresses.With(address))
|
|
require.NoError(t, err)
|
|
|
|
// allow everybody permission
|
|
code2, err := storeCode(ctx, wasmApp, types.AllowEverybody)
|
|
require.NoError(t, err)
|
|
|
|
// allow nobody permission
|
|
code3, err := storeCode(ctx, wasmApp, types.AllowNobody)
|
|
require.NoError(t, err)
|
|
|
|
fromVM, err := wasmApp.UpgradeKeeper.GetModuleVersionMap(ctx)
|
|
require.NoError(t, err)
|
|
fromVM[types.ModuleName] = wasmApp.ModuleManager.GetVersionMap()[types.ModuleName]
|
|
_, err = upgradeHandler(ctx, upgradetypes.Plan{Name: "testing"}, fromVM)
|
|
require.NoError(t, err)
|
|
|
|
// when
|
|
gotVM, err := wasmApp.ModuleManager.RunMigrations(ctx, wasmApp.Configurator(), fromVM)
|
|
|
|
// then
|
|
require.NoError(t, err)
|
|
var expModuleVersion uint64 = 4
|
|
assert.Equal(t, expModuleVersion, gotVM[types.ModuleName])
|
|
|
|
// any address was not migrated
|
|
assert.Equal(t, types.AccessTypeAnyOfAddresses.With(address), wasmApp.WasmKeeper.GetCodeInfo(ctx, code1).InstantiateConfig)
|
|
|
|
// allow everybody was not migrated
|
|
assert.Equal(t, types.AllowEverybody, wasmApp.WasmKeeper.GetCodeInfo(ctx, code2).InstantiateConfig)
|
|
|
|
// allow nodoby was not migrated
|
|
assert.Equal(t, types.AllowNobody, wasmApp.WasmKeeper.GetCodeInfo(ctx, code3).InstantiateConfig)
|
|
}
|
|
|
|
func storeCode(ctx sdk.Context, wasmApp *app.WasmApp, instantiatePermission types.AccessConfig) (codeID uint64, err error) {
|
|
msg := types.MsgStoreCodeFixture(func(m *types.MsgStoreCode) {
|
|
m.WASMByteCode = wasmContract
|
|
m.InstantiatePermission = &instantiatePermission
|
|
})
|
|
rsp, err := wasmApp.MsgServiceRouter().Handler(msg)(ctx, msg)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
var result types.MsgStoreCodeResponse
|
|
err = wasmApp.AppCodec().Unmarshal(rsp.Data, &result)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
codeID = result.CodeID
|
|
return
|
|
}
|