@@ -4,6 +4,7 @@ package app_test
44import (
55 "encoding/json"
66 "flag"
7+ "fmt"
78 "io"
89 "math/rand"
910 "sync"
@@ -21,12 +22,17 @@ import (
2122 abci "github.com/cometbft/cometbft/abci/types"
2223 cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
2324 "github.com/cosmos/cosmos-sdk/baseapp"
25+ "github.com/cosmos/cosmos-sdk/client/flags"
26+ "github.com/cosmos/cosmos-sdk/runtime"
27+ "github.com/cosmos/cosmos-sdk/server"
2428 servertypes "github.com/cosmos/cosmos-sdk/server/types"
2529 "github.com/cosmos/cosmos-sdk/simsx"
30+ simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
2631 simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
2732 "github.com/cosmos/cosmos-sdk/x/simulation"
2833 simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli"
2934 "github.com/evmos/ethermint/app"
35+ "github.com/evmos/ethermint/app/ante"
3036 "github.com/evmos/ethermint/testutil"
3137 "github.com/stretchr/testify/assert"
3238 "github.com/stretchr/testify/require"
@@ -55,25 +61,24 @@ func setupStateFactory(app *app.EthermintApp) simsx.SimStateFactory {
5561 return simsx.SimStateFactory {
5662 Codec : app .AppCodec (),
5763 AppStateFn : testutil .StateFn (app ),
58- BlockedAddr : app .BlockedAddrs (),
64+ BlockedAddr : app .BlockedAddresses (),
5965 AccountSource : app .AuthKeeper ,
6066 BalanceSource : app .BankKeeper ,
6167 }
6268}
6369
6470func TestFullAppSimulation (t * testing.T ) {
65- return
6671 config := simcli .NewConfigFromFlags ()
6772 config .ChainID = SimAppChainID
6873 config .BlockMaxGas = SimBlockMaxGas
69- simsx .RunWithSeed (
74+ simsx .RunWithSeedAndRandAcc (
7075 t ,
7176 config ,
72- app . NewEthermintApp ,
77+ NewSimApp ,
7378 setupStateFactory ,
7479 config .Seed ,
7580 config .FuzzSeed ,
76- simtypes .RandomAccounts ,
81+ testutil .RandomAccounts ,
7782 )
7883}
7984
@@ -82,15 +87,54 @@ var (
8287 exportWithValidatorSet []string
8388)
8489
90+ func NewSimApp (
91+ logger log.Logger ,
92+ db corestore.KVStoreWithBatch ,
93+ traceStore io.Writer ,
94+ loadLatest bool ,
95+ appOpts servertypes.AppOptions ,
96+ baseAppOptions ... func (* baseapp.BaseApp ),
97+ ) * app.EthermintApp {
98+ appOptions := make (simtestutil.AppOptionsMap , 0 )
99+ appOptions [flags .FlagHome ] = app .DefaultNodeHome
100+ appOptions [server .FlagInvCheckPeriod ] = simcli .FlagPeriodValue
101+ app := app .NewEthermintApp (logger , db , nil , false , appOptions , baseAppOptions ... )
102+ // disable feemarket on native tx
103+ anteHandler , err := ante .NewAnteHandler (ante.HandlerOptions {
104+ Environment : runtime .NewEnvironment (
105+ nil ,
106+ logger ,
107+ ), // nil is set as the kvstoreservice to avoid module access
108+ ConsensusKeeper : app .ConsensusParamsKeeper ,
109+ AccountKeeper : app .AuthKeeper ,
110+ AccountAbstractionKeeper : app .AccountsKeeper ,
111+ BankKeeper : app .BankKeeper ,
112+ SignModeHandler : app .TxConfig ().SignModeHandler (),
113+ FeegrantKeeper : app .FeeGrantKeeper ,
114+ SigGasConsumer : ante .DefaultSigVerificationGasConsumer ,
115+ EvmKeeper : app .EvmKeeper ,
116+ FeeMarketKeeper : app .FeeMarketKeeper ,
117+ MaxTxGasWanted : 0 ,
118+ })
119+ if err != nil {
120+ panic (err )
121+ }
122+ app .SetAnteHandler (anteHandler )
123+ if err := app .LoadLatestVersion (); err != nil {
124+ panic (err )
125+ }
126+ return app
127+ }
128+
85129func TestAppImportExport (t * testing.T ) {
86130 return
87131 config := simcli .NewConfigFromFlags ()
88132 config .ChainID = SimAppChainID
89133 config .BlockMaxGas = SimBlockMaxGas
90- simsx .RunWithSeed (
134+ simsx .RunWithSeedAndRandAcc (
91135 t ,
92136 config ,
93- app . NewEthermintApp ,
137+ NewSimApp ,
94138 setupStateFactory ,
95139 config .Seed ,
96140 config .FuzzSeed ,
@@ -102,11 +146,14 @@ func TestAppImportExport(t *testing.T) {
102146 require .NoError (t , err )
103147
104148 t .Log ("importing genesis...\n " )
105- newTestInstance := simsx .NewSimulationAppInstance (t , ti .Cfg , app . NewEthermintApp )
149+ newTestInstance := simsx .NewSimulationAppInstance (t , ti .Cfg , NewSimApp )
106150 newApp := newTestInstance .App
107151 var genesisState map [string ]json.RawMessage
108152 require .NoError (t , json .Unmarshal (exported .AppState , & genesisState ))
109- ctxB := newApp .NewContextLegacy (true , cmtproto.Header {Height : a .LastBlockHeight ()})
153+ ctxB := newApp .NewContextLegacy (true , cmtproto.Header {
154+ Height : a .LastBlockHeight (),
155+ ChainID : config .ChainID ,
156+ })
110157 _ , err = newApp .ModuleManager .InitGenesis (ctxB , genesisState )
111158 if simapp .IsEmptyValidatorSetErr (err ) {
112159 t .Skip ("Skipping simulation as all validators have been unbonded" )
@@ -135,10 +182,10 @@ func TestAppSimulationAfterImport(t *testing.T) {
135182 config := simcli .NewConfigFromFlags ()
136183 config .ChainID = SimAppChainID
137184 config .BlockMaxGas = SimBlockMaxGas
138- simsx .RunWithSeed (
185+ simsx .RunWithSeedAndRandAcc (
139186 t ,
140187 config ,
141- app . NewEthermintApp ,
188+ NewSimApp ,
142189 setupStateFactory ,
143190 config .Seed ,
144191 config .FuzzSeed ,
@@ -158,7 +205,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
158205
159206 _ , err = a .InitChain (& abci.InitChainRequest {
160207 AppStateBytes : exported .AppState ,
161- ChainId : simsx . SimAppChainID ,
208+ ChainId : config . ChainID ,
162209 InitialHeight : exported .Height ,
163210 Time : genesisTimestamp ,
164211 })
@@ -170,18 +217,17 @@ func TestAppSimulationAfterImport(t *testing.T) {
170217 // use accounts from initial run
171218 return exported .AppState , accs , config .ChainID , genesisTimestamp
172219 },
173- BlockedAddr : a .BlockedAddrs (),
220+ BlockedAddr : a .BlockedAddresses (),
174221 AccountSource : a .AuthKeeper ,
175222 BalanceSource : a .BankKeeper ,
176223 }
177224 }
178225 ti .Cfg .InitialBlockHeight = int (exported .Height )
179- simsx .RunWithSeed (t , ti .Cfg , app . NewEthermintApp , importGenesisStateFactory , ti .Cfg .Seed , ti .Cfg .FuzzSeed , testutil .RandomAccounts )
226+ simsx .RunWithSeedAndRandAcc (t , ti .Cfg , NewSimApp , importGenesisStateFactory , ti .Cfg .Seed , ti .Cfg .FuzzSeed , testutil .RandomAccounts )
180227 })
181228}
182229
183230func TestAppStateDeterminism (t * testing.T ) {
184- return
185231 const numTimesToRunPerSeed = 3
186232 var seeds []int64
187233 if s := simcli .NewConfigFromFlags ().Seed ; s != simcli .DefaultSeedValue {
@@ -214,7 +260,7 @@ func TestAppStateDeterminism(t *testing.T) {
214260 return others .Get (k )
215261 })
216262 }
217- return app . NewEthermintApp (logger , db , nil , true , appOpts , append (baseAppOptions , interBlockCacheOpt ())... )
263+ return NewSimApp (logger , db , nil , true , appOpts , append (baseAppOptions , interBlockCacheOpt ())... )
218264 }
219265 var mx sync.Mutex
220266 appHashResults := make (map [int64 ][][]byte )
@@ -245,13 +291,23 @@ func TestAppStateDeterminism(t *testing.T) {
245291 }
246292 }
247293 // run simulations
248- simsx .RunWithSeeds (
249- t ,
250- interBlockCachingAppFactory ,
251- setupStateFactory ,
252- seeds ,
253- []byte {},
254- testutil .RandomAccounts ,
255- captureAndCheckHash ,
256- )
294+ cfg := simcli .NewConfigFromFlags ()
295+ cfg .ChainID = SimAppChainID
296+ for i := range seeds {
297+ seed := seeds [i ]
298+ t .Run (fmt .Sprintf ("seed: %d" , seed ), func (t * testing.T ) {
299+ t .Parallel ()
300+ simsx .RunWithSeedAndRandAcc (
301+ t ,
302+ cfg ,
303+ interBlockCachingAppFactory ,
304+ setupStateFactory ,
305+ seed ,
306+ []byte {},
307+ testutil .RandomAccounts ,
308+ captureAndCheckHash ,
309+ )
310+ })
311+ }
312+
257313}
0 commit comments