@@ -4,6 +4,7 @@ package app_test
4
4
import (
5
5
"encoding/json"
6
6
"flag"
7
+ "fmt"
7
8
"io"
8
9
"math/rand"
9
10
"sync"
@@ -21,12 +22,17 @@ import (
21
22
abci "github.com/cometbft/cometbft/abci/types"
22
23
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
23
24
"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"
24
28
servertypes "github.com/cosmos/cosmos-sdk/server/types"
25
29
"github.com/cosmos/cosmos-sdk/simsx"
30
+ simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
26
31
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
27
32
"github.com/cosmos/cosmos-sdk/x/simulation"
28
33
simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli"
29
34
"github.com/evmos/ethermint/app"
35
+ "github.com/evmos/ethermint/app/ante"
30
36
"github.com/evmos/ethermint/testutil"
31
37
"github.com/stretchr/testify/assert"
32
38
"github.com/stretchr/testify/require"
@@ -55,25 +61,24 @@ func setupStateFactory(app *app.EthermintApp) simsx.SimStateFactory {
55
61
return simsx.SimStateFactory {
56
62
Codec : app .AppCodec (),
57
63
AppStateFn : testutil .StateFn (app ),
58
- BlockedAddr : app .BlockedAddrs (),
64
+ BlockedAddr : app .BlockedAddresses (),
59
65
AccountSource : app .AuthKeeper ,
60
66
BalanceSource : app .BankKeeper ,
61
67
}
62
68
}
63
69
64
70
func TestFullAppSimulation (t * testing.T ) {
65
- return
66
71
config := simcli .NewConfigFromFlags ()
67
72
config .ChainID = SimAppChainID
68
73
config .BlockMaxGas = SimBlockMaxGas
69
- simsx .RunWithSeed (
74
+ simsx .RunWithSeedAndRandAcc (
70
75
t ,
71
76
config ,
72
- app . NewEthermintApp ,
77
+ NewSimApp ,
73
78
setupStateFactory ,
74
79
config .Seed ,
75
80
config .FuzzSeed ,
76
- simtypes .RandomAccounts ,
81
+ testutil .RandomAccounts ,
77
82
)
78
83
}
79
84
@@ -82,15 +87,54 @@ var (
82
87
exportWithValidatorSet []string
83
88
)
84
89
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
+
85
129
func TestAppImportExport (t * testing.T ) {
86
130
return
87
131
config := simcli .NewConfigFromFlags ()
88
132
config .ChainID = SimAppChainID
89
133
config .BlockMaxGas = SimBlockMaxGas
90
- simsx .RunWithSeed (
134
+ simsx .RunWithSeedAndRandAcc (
91
135
t ,
92
136
config ,
93
- app . NewEthermintApp ,
137
+ NewSimApp ,
94
138
setupStateFactory ,
95
139
config .Seed ,
96
140
config .FuzzSeed ,
@@ -102,11 +146,14 @@ func TestAppImportExport(t *testing.T) {
102
146
require .NoError (t , err )
103
147
104
148
t .Log ("importing genesis...\n " )
105
- newTestInstance := simsx .NewSimulationAppInstance (t , ti .Cfg , app . NewEthermintApp )
149
+ newTestInstance := simsx .NewSimulationAppInstance (t , ti .Cfg , NewSimApp )
106
150
newApp := newTestInstance .App
107
151
var genesisState map [string ]json.RawMessage
108
152
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
+ })
110
157
_ , err = newApp .ModuleManager .InitGenesis (ctxB , genesisState )
111
158
if simapp .IsEmptyValidatorSetErr (err ) {
112
159
t .Skip ("Skipping simulation as all validators have been unbonded" )
@@ -135,10 +182,10 @@ func TestAppSimulationAfterImport(t *testing.T) {
135
182
config := simcli .NewConfigFromFlags ()
136
183
config .ChainID = SimAppChainID
137
184
config .BlockMaxGas = SimBlockMaxGas
138
- simsx .RunWithSeed (
185
+ simsx .RunWithSeedAndRandAcc (
139
186
t ,
140
187
config ,
141
- app . NewEthermintApp ,
188
+ NewSimApp ,
142
189
setupStateFactory ,
143
190
config .Seed ,
144
191
config .FuzzSeed ,
@@ -158,7 +205,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
158
205
159
206
_ , err = a .InitChain (& abci.InitChainRequest {
160
207
AppStateBytes : exported .AppState ,
161
- ChainId : simsx . SimAppChainID ,
208
+ ChainId : config . ChainID ,
162
209
InitialHeight : exported .Height ,
163
210
Time : genesisTimestamp ,
164
211
})
@@ -170,18 +217,17 @@ func TestAppSimulationAfterImport(t *testing.T) {
170
217
// use accounts from initial run
171
218
return exported .AppState , accs , config .ChainID , genesisTimestamp
172
219
},
173
- BlockedAddr : a .BlockedAddrs (),
220
+ BlockedAddr : a .BlockedAddresses (),
174
221
AccountSource : a .AuthKeeper ,
175
222
BalanceSource : a .BankKeeper ,
176
223
}
177
224
}
178
225
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 )
180
227
})
181
228
}
182
229
183
230
func TestAppStateDeterminism (t * testing.T ) {
184
- return
185
231
const numTimesToRunPerSeed = 3
186
232
var seeds []int64
187
233
if s := simcli .NewConfigFromFlags ().Seed ; s != simcli .DefaultSeedValue {
@@ -214,7 +260,7 @@ func TestAppStateDeterminism(t *testing.T) {
214
260
return others .Get (k )
215
261
})
216
262
}
217
- return app . NewEthermintApp (logger , db , nil , true , appOpts , append (baseAppOptions , interBlockCacheOpt ())... )
263
+ return NewSimApp (logger , db , nil , true , appOpts , append (baseAppOptions , interBlockCacheOpt ())... )
218
264
}
219
265
var mx sync.Mutex
220
266
appHashResults := make (map [int64 ][][]byte )
@@ -245,13 +291,23 @@ func TestAppStateDeterminism(t *testing.T) {
245
291
}
246
292
}
247
293
// 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
+
257
313
}
0 commit comments