1+ //go:build sims
2+
13package app_test
24
35// TODO: COsmos SDK fix for the simulator issue for custom keys
46import (
57 "encoding/json"
68 "flag"
9+ "fmt"
710 "io"
811 "math/rand"
912 "sync"
@@ -21,12 +24,17 @@ import (
2124 abci "github.com/cometbft/cometbft/abci/types"
2225 cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
2326 "github.com/cosmos/cosmos-sdk/baseapp"
27+ "github.com/cosmos/cosmos-sdk/client/flags"
28+ "github.com/cosmos/cosmos-sdk/runtime"
29+ "github.com/cosmos/cosmos-sdk/server"
2430 servertypes "github.com/cosmos/cosmos-sdk/server/types"
2531 "github.com/cosmos/cosmos-sdk/simsx"
32+ simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
2633 simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
2734 "github.com/cosmos/cosmos-sdk/x/simulation"
2835 simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli"
2936 "github.com/evmos/ethermint/app"
37+ "github.com/evmos/ethermint/app/ante"
3038 "github.com/evmos/ethermint/testutil"
3139 "github.com/stretchr/testify/assert"
3240 "github.com/stretchr/testify/require"
@@ -55,25 +63,24 @@ func setupStateFactory(app *app.EthermintApp) simsx.SimStateFactory {
5563 return simsx.SimStateFactory {
5664 Codec : app .AppCodec (),
5765 AppStateFn : testutil .StateFn (app ),
58- BlockedAddr : app .BlockedAddrs (),
66+ BlockedAddr : app .BlockedAddresses (),
5967 AccountSource : app .AuthKeeper ,
6068 BalanceSource : app .BankKeeper ,
6169 }
6270}
6371
6472func TestFullAppSimulation (t * testing.T ) {
65- return
6673 config := simcli .NewConfigFromFlags ()
6774 config .ChainID = SimAppChainID
6875 config .BlockMaxGas = SimBlockMaxGas
69- simsx .RunWithSeed (
76+ simsx .RunWithSeedAndRandAcc (
7077 t ,
7178 config ,
72- app . NewEthermintApp ,
79+ NewSimApp ,
7380 setupStateFactory ,
7481 config .Seed ,
7582 config .FuzzSeed ,
76- simtypes .RandomAccounts ,
83+ testutil .RandomAccounts ,
7784 )
7885}
7986
@@ -82,15 +89,54 @@ var (
8289 exportWithValidatorSet []string
8390)
8491
92+ func NewSimApp (
93+ logger log.Logger ,
94+ db corestore.KVStoreWithBatch ,
95+ traceStore io.Writer ,
96+ loadLatest bool ,
97+ appOpts servertypes.AppOptions ,
98+ baseAppOptions ... func (* baseapp.BaseApp ),
99+ ) * app.EthermintApp {
100+ appOptions := make (simtestutil.AppOptionsMap , 0 )
101+ appOptions [flags .FlagHome ] = app .DefaultNodeHome
102+ appOptions [server .FlagInvCheckPeriod ] = simcli .FlagPeriodValue
103+ app := app .NewEthermintApp (logger , db , nil , false , appOptions , baseAppOptions ... )
104+ // disable feemarket on native tx
105+ anteHandler , err := ante .NewAnteHandler (ante.HandlerOptions {
106+ Environment : runtime .NewEnvironment (
107+ nil ,
108+ logger ,
109+ ), // nil is set as the kvstoreservice to avoid module access
110+ ConsensusKeeper : app .ConsensusParamsKeeper ,
111+ AccountKeeper : app .AuthKeeper ,
112+ AccountAbstractionKeeper : app .AccountsKeeper ,
113+ BankKeeper : app .BankKeeper ,
114+ SignModeHandler : app .TxConfig ().SignModeHandler (),
115+ FeegrantKeeper : app .FeeGrantKeeper ,
116+ SigGasConsumer : ante .DefaultSigVerificationGasConsumer ,
117+ EvmKeeper : app .EvmKeeper ,
118+ FeeMarketKeeper : app .FeeMarketKeeper ,
119+ MaxTxGasWanted : 0 ,
120+ })
121+ if err != nil {
122+ panic (err )
123+ }
124+ app .SetAnteHandler (anteHandler )
125+ if err := app .LoadLatestVersion (); err != nil {
126+ panic (err )
127+ }
128+ return app
129+ }
130+
85131func TestAppImportExport (t * testing.T ) {
86132 return
87133 config := simcli .NewConfigFromFlags ()
88134 config .ChainID = SimAppChainID
89135 config .BlockMaxGas = SimBlockMaxGas
90- simsx .RunWithSeed (
136+ simsx .RunWithSeedAndRandAcc (
91137 t ,
92138 config ,
93- app . NewEthermintApp ,
139+ NewSimApp ,
94140 setupStateFactory ,
95141 config .Seed ,
96142 config .FuzzSeed ,
@@ -102,11 +148,14 @@ func TestAppImportExport(t *testing.T) {
102148 require .NoError (t , err )
103149
104150 t .Log ("importing genesis...\n " )
105- newTestInstance := simsx .NewSimulationAppInstance (t , ti .Cfg , app . NewEthermintApp )
151+ newTestInstance := simsx .NewSimulationAppInstance (t , ti .Cfg , NewSimApp )
106152 newApp := newTestInstance .App
107153 var genesisState map [string ]json.RawMessage
108154 require .NoError (t , json .Unmarshal (exported .AppState , & genesisState ))
109- ctxB := newApp .NewContextLegacy (true , cmtproto.Header {Height : a .LastBlockHeight ()})
155+ ctxB := newApp .NewContextLegacy (true , cmtproto.Header {
156+ Height : a .LastBlockHeight (),
157+ ChainID : config .ChainID ,
158+ })
110159 _ , err = newApp .ModuleManager .InitGenesis (ctxB , genesisState )
111160 if simapp .IsEmptyValidatorSetErr (err ) {
112161 t .Skip ("Skipping simulation as all validators have been unbonded" )
@@ -135,10 +184,10 @@ func TestAppSimulationAfterImport(t *testing.T) {
135184 config := simcli .NewConfigFromFlags ()
136185 config .ChainID = SimAppChainID
137186 config .BlockMaxGas = SimBlockMaxGas
138- simsx .RunWithSeed (
187+ simsx .RunWithSeedAndRandAcc (
139188 t ,
140189 config ,
141- app . NewEthermintApp ,
190+ NewSimApp ,
142191 setupStateFactory ,
143192 config .Seed ,
144193 config .FuzzSeed ,
@@ -158,7 +207,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
158207
159208 _ , err = a .InitChain (& abci.InitChainRequest {
160209 AppStateBytes : exported .AppState ,
161- ChainId : simsx . SimAppChainID ,
210+ ChainId : config . ChainID ,
162211 InitialHeight : exported .Height ,
163212 Time : genesisTimestamp ,
164213 })
@@ -170,18 +219,17 @@ func TestAppSimulationAfterImport(t *testing.T) {
170219 // use accounts from initial run
171220 return exported .AppState , accs , config .ChainID , genesisTimestamp
172221 },
173- BlockedAddr : a .BlockedAddrs (),
222+ BlockedAddr : a .BlockedAddresses (),
174223 AccountSource : a .AuthKeeper ,
175224 BalanceSource : a .BankKeeper ,
176225 }
177226 }
178227 ti .Cfg .InitialBlockHeight = int (exported .Height )
179- simsx .RunWithSeed (t , ti .Cfg , app . NewEthermintApp , importGenesisStateFactory , ti .Cfg .Seed , ti .Cfg .FuzzSeed , testutil .RandomAccounts )
228+ simsx .RunWithSeedAndRandAcc (t , ti .Cfg , NewSimApp , importGenesisStateFactory , ti .Cfg .Seed , ti .Cfg .FuzzSeed , testutil .RandomAccounts )
180229 })
181230}
182231
183232func TestAppStateDeterminism (t * testing.T ) {
184- return
185233 const numTimesToRunPerSeed = 3
186234 var seeds []int64
187235 if s := simcli .NewConfigFromFlags ().Seed ; s != simcli .DefaultSeedValue {
@@ -214,7 +262,7 @@ func TestAppStateDeterminism(t *testing.T) {
214262 return others .Get (k )
215263 })
216264 }
217- return app . NewEthermintApp (logger , db , nil , true , appOpts , append (baseAppOptions , interBlockCacheOpt ())... )
265+ return NewSimApp (logger , db , nil , true , appOpts , append (baseAppOptions , interBlockCacheOpt ())... )
218266 }
219267 var mx sync.Mutex
220268 appHashResults := make (map [int64 ][][]byte )
@@ -245,13 +293,23 @@ func TestAppStateDeterminism(t *testing.T) {
245293 }
246294 }
247295 // run simulations
248- simsx .RunWithSeeds (
249- t ,
250- interBlockCachingAppFactory ,
251- setupStateFactory ,
252- seeds ,
253- []byte {},
254- testutil .RandomAccounts ,
255- captureAndCheckHash ,
256- )
296+ cfg := simcli .NewConfigFromFlags ()
297+ cfg .ChainID = SimAppChainID
298+ for i := range seeds {
299+ seed := seeds [i ]
300+ t .Run (fmt .Sprintf ("seed: %d" , seed ), func (t * testing.T ) {
301+ t .Parallel ()
302+ simsx .RunWithSeedAndRandAcc (
303+ t ,
304+ cfg ,
305+ interBlockCachingAppFactory ,
306+ setupStateFactory ,
307+ seed ,
308+ []byte {},
309+ testutil .RandomAccounts ,
310+ captureAndCheckHash ,
311+ )
312+ })
313+ }
314+
257315}
0 commit comments