Skip to content

Commit

Permalink
fix simulate error
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamer committed Mar 14, 2024
1 parent ece68a5 commit de969d9
Showing 1 changed file with 36 additions and 57 deletions.
93 changes: 36 additions & 57 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
tokentypes "github.com/irisnet/irismod/modules/token/types"
"github.com/stretchr/testify/require"

"github.com/irisnet/irishub/v3/app/params"
iristypes "github.com/irisnet/irishub/v3/types"

dbm "github.com/cometbft/cometbft-db"
Expand Down Expand Up @@ -98,15 +99,7 @@ func TestFullAppSimulation(t *testing.T) {

encfg := RegisterEncodingConfig()

app := NewIrisApp(
logger,
db,
nil,
true,
encfg,
EmptyAppOptions{},
fauxMerkleModeOpt,
)
app := createApp(logger, db, encfg, fauxMerkleModeOpt)
require.Equal(t, "IrisApp", app.Name())

// run randomized simulation
Expand Down Expand Up @@ -136,6 +129,8 @@ func TestAppImportExport(t *testing.T) {
config := simcli.NewConfigFromFlags()
config.ChainID = AppChainID

sdk.DefaultBondDenom = iristypes.NativeToken.Symbol

db, dir, logger, skip, err := simtestutil.SetupSimulation(
config,
"goleveldb-app-sim",
Expand All @@ -155,15 +150,7 @@ func TestAppImportExport(t *testing.T) {
}()

encfg := RegisterEncodingConfig()
app := NewIrisApp(
logger,
db,
nil,
true,
encfg,
EmptyAppOptions{},
fauxMerkleModeOpt,
)
app := createApp(logger, db, encfg, fauxMerkleModeOpt)
require.Equal(t, "IrisApp", app.Name())

// Run randomized simulation
Expand Down Expand Up @@ -209,15 +196,7 @@ func TestAppImportExport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir))
}()

newApp := NewIrisApp(
log.NewNopLogger(),
newDB,
nil,
true,
encfg,
EmptyAppOptions{},
fauxMerkleModeOpt,
)
newApp := createApp(logger, db, encfg, fauxMerkleModeOpt)
require.Equal(t, "IrisApp", newApp.Name())

var genesisState iristypes.GenesisState
Expand All @@ -244,11 +223,13 @@ func TestAppImportExport(t *testing.T) {

storeKeysPrefixes := []StoreKeysPrefixes{
{app.AppKeepers.KvStoreKeys()[authtypes.StoreKey], newApp.AppKeepers.KvStoreKeys()[authtypes.StoreKey], [][]byte{}},
{app.AppKeepers.KvStoreKeys()[stakingtypes.StoreKey], newApp.AppKeepers.KvStoreKeys()[stakingtypes.StoreKey],
{
app.AppKeepers.KvStoreKeys()[stakingtypes.StoreKey], newApp.AppKeepers.KvStoreKeys()[stakingtypes.StoreKey],
[][]byte{
stakingtypes.UnbondingQueueKey, stakingtypes.RedelegationQueueKey, stakingtypes.ValidatorQueueKey,
stakingtypes.HistoricalInfoKey,
}}, // ordering may change but it doesn't matter
},
}, // ordering may change but it doesn't matter
{app.AppKeepers.KvStoreKeys()[slashingtypes.StoreKey], newApp.AppKeepers.KvStoreKeys()[slashingtypes.StoreKey], [][]byte{}},
{app.AppKeepers.KvStoreKeys()[minttypes.StoreKey], newApp.AppKeepers.KvStoreKeys()[minttypes.StoreKey], [][]byte{}},
{app.AppKeepers.KvStoreKeys()[distrtypes.StoreKey], newApp.AppKeepers.KvStoreKeys()[distrtypes.StoreKey], [][]byte{}},
Expand All @@ -267,7 +248,7 @@ func TestAppImportExport(t *testing.T) {
// check irismod module
{app.AppKeepers.KvStoreKeys()[tokentypes.StoreKey], newApp.AppKeepers.KvStoreKeys()[tokentypes.StoreKey], [][]byte{}},
{app.AppKeepers.KvStoreKeys()[oracletypes.StoreKey], newApp.AppKeepers.KvStoreKeys()[oracletypes.StoreKey], [][]byte{}},
//mt.Supply is InitSupply, can be not equal to TotalSupply
// mt.Supply is InitSupply, can be not equal to TotalSupply
{app.AppKeepers.KvStoreKeys()[mttypes.StoreKey], newApp.AppKeepers.KvStoreKeys()[mttypes.StoreKey], [][]byte{mttypes.PrefixMT}},
{app.AppKeepers.KvStoreKeys()[nfttypes.StoreKey], newApp.AppKeepers.KvStoreKeys()[nfttypes.StoreKey], [][]byte{{0x05}}},
{
Expand Down Expand Up @@ -334,15 +315,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.NoError(t, os.RemoveAll(dir))
}()

app := NewIrisApp(
logger,
db,
nil,
true,
encfg,
EmptyAppOptions{},
fauxMerkleModeOpt,
)
app := createApp(logger, db, encfg, fauxMerkleModeOpt)
require.Equal(t, "IrisApp", app.Name())

// Run randomized simulation
Expand Down Expand Up @@ -393,15 +366,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir))
}()

newApp := NewIrisApp(
log.NewNopLogger(),
newDB,
nil,
true,
encfg,
EmptyAppOptions{},
fauxMerkleModeOpt,
)
newApp := createApp(logger, db, encfg, fauxMerkleModeOpt)
require.Equal(t, "IrisApp", newApp.Name())

newApp.InitChain(abci.RequestInitChain{
Expand All @@ -428,6 +393,7 @@ func TestAppStateDeterminism(t *testing.T) {
if !simcli.FlagEnabledValue {
t.Skip("skipping application simulation")
}
sdk.DefaultBondDenom = iristypes.NativeToken.Symbol

config := simcli.NewConfigFromFlags()
config.InitialBlockHeight = 1
Expand All @@ -453,15 +419,7 @@ func TestAppStateDeterminism(t *testing.T) {
}

db := dbm.NewMemDB()
app := NewIrisApp(
logger,
db,
nil,
true,
encfg,
EmptyAppOptions{},
interBlockCacheOpt(),
)
app := createApp(logger, db, encfg, interBlockCacheOpt())

fmt.Printf(
"running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
Expand Down Expand Up @@ -516,3 +474,24 @@ type EmptyAppOptions struct{}
func (ao EmptyAppOptions) Get(o string) interface{} {
return nil
}

func createApp(
logger log.Logger,
db dbm.DB,
encodingConfig params.EncodingConfig,
baseAppOptions ...func(*baseapp.BaseApp),
) *IrisApp {
if baseAppOptions == nil {
baseAppOptions = []func(*baseapp.BaseApp){}
}
baseAppOptions = append(baseAppOptions, baseapp.SetChainID(AppChainID))
return NewIrisApp(
logger,
db,
nil,
true,
encodingConfig,
EmptyAppOptions{},
baseAppOptions...,
)
}

0 comments on commit de969d9

Please sign in to comment.