SDK upgrade to v0.50 (branch) (#1611)
* 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>
This commit is contained in:
172
app/sim_test.go
172
app/sim_test.go
@@ -2,35 +2,31 @@ package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
dbm "github.com/cometbft/cometbft-db"
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
"github.com/cometbft/cometbft/libs/log"
|
||||
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"cosmossdk.io/log"
|
||||
"cosmossdk.io/store"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
"cosmossdk.io/x/feegrant"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
"github.com/cosmos/cosmos-sdk/store"
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
|
||||
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/simulation"
|
||||
simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli"
|
||||
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
|
||||
@@ -42,15 +38,12 @@ import (
|
||||
// SimAppChainID hardcoded chainID for simulation
|
||||
const SimAppChainID = "simulation-app"
|
||||
|
||||
var FlagEnableStreamingValue bool
|
||||
|
||||
// Get flags every time the simulator is run
|
||||
func init() {
|
||||
simcli.GetSimulatorFlags()
|
||||
}
|
||||
|
||||
type StoreKeysPrefixes struct {
|
||||
A storetypes.StoreKey
|
||||
B storetypes.StoreKey
|
||||
Prefixes [][]byte
|
||||
flag.BoolVar(&FlagEnableStreamingValue, "EnableStreaming", false, "Enable streaming service")
|
||||
}
|
||||
|
||||
// fauxMerkleModeOpt returns a BaseApp option to use a dbStoreAdapter instead of
|
||||
@@ -133,58 +126,70 @@ func TestAppImportExport(t *testing.T) {
|
||||
newApp := NewWasmApp(log.NewNopLogger(), newDB, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
|
||||
require.Equal(t, "WasmApp", newApp.Name())
|
||||
|
||||
var genesisState GenesisState
|
||||
err = json.Unmarshal(exported.AppState, &genesisState)
|
||||
require.NoError(t, err)
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err := fmt.Sprintf("%v", r)
|
||||
if !strings.Contains(err, "validator set is empty after InitGenesis") {
|
||||
panic(r)
|
||||
}
|
||||
t.Log("Skipping simulation as all validators have been unbonded")
|
||||
t.Logf("err: %s stacktrace: %s\n", err, string(debug.Stack()))
|
||||
}
|
||||
}()
|
||||
|
||||
ctxA := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
|
||||
ctxB := newApp.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
|
||||
newApp.ModuleManager.InitGenesis(ctxB, app.AppCodec(), genesisState)
|
||||
newApp.StoreConsensusParams(ctxB, exported.ConsensusParams)
|
||||
|
||||
t.Log("comparing stores...")
|
||||
storeKeysPrefixes := []StoreKeysPrefixes{
|
||||
{app.GetKey(wasmtypes.StoreKey), newApp.GetKey(wasmtypes.StoreKey), [][]byte{wasmtypes.TXCounterPrefix}},
|
||||
{app.GetKey(authtypes.StoreKey), newApp.GetKey(authtypes.StoreKey), [][]byte{}},
|
||||
{
|
||||
app.GetKey(stakingtypes.StoreKey), newApp.GetKey(stakingtypes.StoreKey),
|
||||
[][]byte{
|
||||
stakingtypes.UnbondingQueueKey, stakingtypes.RedelegationQueueKey, stakingtypes.ValidatorQueueKey,
|
||||
stakingtypes.HistoricalInfoKey, stakingtypes.UnbondingIDKey, stakingtypes.UnbondingIndexKey, stakingtypes.UnbondingTypeKey, stakingtypes.ValidatorUpdatesKey,
|
||||
},
|
||||
}, // ordering may change but it doesn't matter
|
||||
{app.GetKey(slashingtypes.StoreKey), newApp.GetKey(slashingtypes.StoreKey), [][]byte{}},
|
||||
{app.GetKey(minttypes.StoreKey), newApp.GetKey(minttypes.StoreKey), [][]byte{}},
|
||||
{app.GetKey(distrtypes.StoreKey), newApp.GetKey(distrtypes.StoreKey), [][]byte{}},
|
||||
{app.GetKey(banktypes.StoreKey), newApp.GetKey(banktypes.StoreKey), [][]byte{banktypes.BalancesPrefix}},
|
||||
{app.GetKey(paramtypes.StoreKey), newApp.GetKey(paramtypes.StoreKey), [][]byte{}},
|
||||
{app.GetKey(govtypes.StoreKey), newApp.GetKey(govtypes.StoreKey), [][]byte{}},
|
||||
{app.GetKey(evidencetypes.StoreKey), newApp.GetKey(evidencetypes.StoreKey), [][]byte{}},
|
||||
{app.GetKey(capabilitytypes.StoreKey), newApp.GetKey(capabilitytypes.StoreKey), [][]byte{}},
|
||||
{app.GetKey(authzkeeper.StoreKey), newApp.GetKey(authzkeeper.StoreKey), [][]byte{authzkeeper.GrantKey, authzkeeper.GrantQueuePrefix}},
|
||||
initReq := &abci.RequestInitChain{
|
||||
AppStateBytes: exported.AppState,
|
||||
}
|
||||
|
||||
for _, skp := range storeKeysPrefixes {
|
||||
storeA := ctxA.KVStore(skp.A)
|
||||
storeB := ctxB.KVStore(skp.B)
|
||||
require.NotNil(t, storeA)
|
||||
require.NotNil(t, storeB)
|
||||
failedKVAs, failedKVBs := sdk.DiffKVStores(storeA, storeB, skp.Prefixes)
|
||||
require.Equal(t, len(failedKVAs), len(failedKVBs), "unequal sets of key-values to compare")
|
||||
ctxA := app.NewContextLegacy(true, cmtproto.Header{Height: app.LastBlockHeight()})
|
||||
ctxB := newApp.NewContextLegacy(true, cmtproto.Header{Height: app.LastBlockHeight()})
|
||||
_, err = newApp.InitChainer(ctxB, initReq)
|
||||
|
||||
t.Logf("compared %d different key/value pairs between %s and %s\n", len(failedKVAs), skp.A, skp.B)
|
||||
require.Equal(t, 0, len(failedKVAs), simtestutil.GetSimulationLog(skp.A.Name(), app.SimulationManager().StoreDecoders, failedKVAs, failedKVBs))
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "validator set is empty after InitGenesis") {
|
||||
t.Log("Skipping simulation as all validators have been unbonded")
|
||||
t.Logf("err: %s stacktrace: %s\n", err, string(debug.Stack()))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
err = newApp.StoreConsensusParams(ctxB, exported.ConsensusParams)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Log("comparing stores...")
|
||||
// skip certain prefixes
|
||||
skipPrefixes := map[string][][]byte{
|
||||
stakingtypes.StoreKey: {
|
||||
stakingtypes.UnbondingQueueKey, stakingtypes.RedelegationQueueKey, stakingtypes.ValidatorQueueKey,
|
||||
stakingtypes.HistoricalInfoKey, stakingtypes.UnbondingIDKey, stakingtypes.UnbondingIndexKey,
|
||||
stakingtypes.UnbondingTypeKey, stakingtypes.ValidatorUpdatesKey,
|
||||
},
|
||||
authzkeeper.StoreKey: {authzkeeper.GrantQueuePrefix},
|
||||
feegrant.StoreKey: {feegrant.FeeAllowanceQueueKeyPrefix},
|
||||
slashingtypes.StoreKey: {slashingtypes.ValidatorMissedBlockBitmapKeyPrefix},
|
||||
wasmtypes.StoreKey: {wasmtypes.TXCounterPrefix},
|
||||
}
|
||||
|
||||
storeKeys := app.GetStoreKeys()
|
||||
require.NotEmpty(t, storeKeys)
|
||||
|
||||
for _, appKeyA := range storeKeys {
|
||||
// only compare kvstores
|
||||
if _, ok := appKeyA.(*storetypes.KVStoreKey); !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
keyName := appKeyA.Name()
|
||||
appKeyB := newApp.GetKey(keyName)
|
||||
|
||||
storeA := ctxA.KVStore(appKeyA)
|
||||
storeB := ctxB.KVStore(appKeyB)
|
||||
|
||||
failedKVAs, failedKVBs := simtestutil.DiffKVStores(storeA, storeB, skipPrefixes[keyName])
|
||||
if !assert.Equal(t, len(failedKVAs), len(failedKVBs), "unequal sets of key-values to compare in %q", keyName) {
|
||||
for _, v := range failedKVBs {
|
||||
t.Logf("store missmatch: %q\n", v)
|
||||
}
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
t.Logf("compared %d different key/value pairs between %s and %s\n", len(failedKVAs), appKeyA, appKeyB)
|
||||
if !assert.Equal(t, 0, len(failedKVAs), simtestutil.GetSimulationLog(keyName, app.SimulationManager().StoreDecoders, failedKVAs, failedKVBs)) {
|
||||
for _, v := range failedKVAs {
|
||||
t.Logf("store missmatch: %q\n", v)
|
||||
}
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,10 +241,11 @@ func TestAppSimulationAfterImport(t *testing.T) {
|
||||
newApp := NewWasmApp(log.NewNopLogger(), newDB, nil, true, appOptions, emptyWasmOpts, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
|
||||
require.Equal(t, "WasmApp", newApp.Name())
|
||||
|
||||
newApp.InitChain(abci.RequestInitChain{
|
||||
_, err = newApp.InitChain(&abci.RequestInitChain{
|
||||
ChainId: SimAppChainID,
|
||||
AppStateBytes: exported.AppState,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err = simulation.SimulateFromSeed(
|
||||
t,
|
||||
@@ -256,7 +262,6 @@ func TestAppSimulationAfterImport(t *testing.T) {
|
||||
}
|
||||
|
||||
func setupSimulationApp(t *testing.T, msg string) (simtypes.Config, dbm.DB, simtestutil.AppOptionsMap, *WasmApp) {
|
||||
t.Helper()
|
||||
config := simcli.NewConfigFromFlags()
|
||||
config.ChainID = SimAppChainID
|
||||
|
||||
@@ -295,20 +300,33 @@ func TestAppStateDeterminism(t *testing.T) {
|
||||
config.ChainID = SimAppChainID
|
||||
|
||||
numSeeds := 3
|
||||
numTimesToRunPerSeed := 5
|
||||
numTimesToRunPerSeed := 3 // This used to be set to 5, but we've temporarily reduced it to 3 for the sake of faster CI.
|
||||
appHashList := make([]json.RawMessage, numTimesToRunPerSeed)
|
||||
|
||||
appOptions := make(simtestutil.AppOptionsMap, 0)
|
||||
appOptions[flags.FlagHome] = t.TempDir() // ensure a unique folder
|
||||
appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue
|
||||
// We will be overriding the random seed and just run a single simulation on the provided seed value
|
||||
if config.Seed != simcli.DefaultSeedValue {
|
||||
numSeeds = 1
|
||||
}
|
||||
|
||||
appOptions := viper.New()
|
||||
if FlagEnableStreamingValue {
|
||||
m := make(map[string]interface{})
|
||||
m["streaming.abci.keys"] = []string{"*"}
|
||||
m["streaming.abci.plugin"] = "abci_v1"
|
||||
m["streaming.abci.stop-node-on-err"] = true
|
||||
for key, value := range m {
|
||||
appOptions.SetDefault(key, value)
|
||||
}
|
||||
}
|
||||
appOptions.SetDefault(flags.FlagHome, t.TempDir()) // ensure a unique folder
|
||||
appOptions.SetDefault(server.FlagInvCheckPeriod, simcli.FlagPeriodValue)
|
||||
|
||||
for i := 0; i < numSeeds; i++ {
|
||||
config.Seed += int64(i)
|
||||
|
||||
for j := 0; j < numTimesToRunPerSeed; j++ {
|
||||
var logger log.Logger
|
||||
if simcli.FlagVerboseValue {
|
||||
logger = log.TestingLogger()
|
||||
logger = log.NewTestLogger(t)
|
||||
} else {
|
||||
logger = log.NewNopLogger()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user