Skip to content

Commit

Permalink
add simulate
Browse files Browse the repository at this point in the history
  • Loading branch information
avery committed Dec 18, 2024
1 parent 955cc2e commit 4d1e6e7
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func NewAnteHandler(options HandlerOptions) sdk.AnteHandler {

defer ethante.Recover(ctx.Logger(), &err)

if options.Simulate {
sim = true
}

txWithExtensions, ok := tx.(authante.HasExtensionOptionsTx)
if ok {
opts := txWithExtensions.GetExtensionOptions()
Expand Down
12 changes: 12 additions & 0 deletions app/ante/decorators.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"

coinswaptypes "mods.irisnet.org/modules/coinswap/types"
servicetypes "mods.irisnet.org/modules/service/types"
tokenkeeper "mods.irisnet.org/modules/token/keeper"
tokentypesv1 "mods.irisnet.org/modules/token/types/v1"
tokentypesv1beta1 "mods.irisnet.org/modules/token/types/v1beta1"
Expand Down Expand Up @@ -76,6 +77,17 @@ func (vsd ValidateServiceDecorator) AnteHandle(
simulate bool,
next sdk.AnteHandler,
) (sdk.Context, error) {
if simulate {
return next(ctx, tx, simulate)
}
for _, msg := range tx.GetMsgs() {
switch msg := msg.(type) {
case *servicetypes.MsgCallService:
if msg.Repeated {
return ctx, sdkerrors.Wrap(errortypes.ErrInvalidRequest, "currently does not support to create repeatable service invocation")
}
}
}

return next(ctx, tx, simulate)
}
Expand Down
1 change: 1 addition & 0 deletions app/ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type HandlerOptions struct {
FeeMarketKeeper ethante.FeeMarketKeeper
BypassMinFeeMsgTypes []string
MaxTxGasWanted uint64
Simulate bool
}

// newCosmosAnteHandler creates the default ante handler for Ethereum transactions
Expand Down
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func NewIrisApp(
loadLatest bool,
encodingConfig params.EncodingConfig,
appOpts servertypes.AppOptions,
simulate bool,
baseAppOptions ...func(*baseapp.BaseApp),
) *IrisApp {
appCodec := encodingConfig.Marshaler
Expand Down Expand Up @@ -195,6 +196,7 @@ func NewIrisApp(
FeeMarketKeeper: app.FeeMarketKeeper,
BypassMinFeeMsgTypes: []string{},
MaxTxGasWanted: maxGasWanted,
Simulate: simulate,
},
)

Expand Down
2 changes: 2 additions & 0 deletions app/sim_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func BenchmarkFullAppSimulation(b *testing.B) {
true,
encfg,
EmptyAppOptions{},
true,
interBlockCacheOpt(),
)

Expand Down Expand Up @@ -119,6 +120,7 @@ func BenchmarkInvariants(b *testing.B) {
true,
encfg,
EmptyAppOptions{},
true,
interBlockCacheOpt(),
)

Expand Down
9 changes: 9 additions & 0 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ func TestAppSimulationAfterImport(t *testing.T) {
config.ChainID = AppChainID
encfg := RegisterEncodingConfig()

simcli.FlagEnabledValue = true
simcli.FlagVerboseValue = true
config.NumBlocks = 50
//config.Seed = 89182391
config.Seed = 4
config.Commit = true
simcli.FlagPeriodValue = 5

db, dir, logger, skip, err := simtestutil.SetupSimulation(
config,
"goleveldb-app-sim",
Expand Down Expand Up @@ -495,6 +503,7 @@ func createApp(
true,
encodingConfig,
EmptyAppOptions{},
true,
baseAppOptions...,
)
}
4 changes: 3 additions & 1 deletion cmd/iris/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import (
// main function.
func NewRootCmd() (*cobra.Command, params.EncodingConfig) {

tempApplication := app.NewIrisApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, app.RegisterEncodingConfig(), testutil.EmptyAppOptions{})
tempApplication := app.NewIrisApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, app.RegisterEncodingConfig(), testutil.EmptyAppOptions{}, false)

encodingConfig := app.RegisterEncodingConfig()
initClientCtx := client.Context{}.
Expand Down Expand Up @@ -263,6 +263,7 @@ func (ac appCreator) newApp(
true,
ac.encCfg,
appOpts,
false,
baseappOptions...,
)
}
Expand Down Expand Up @@ -295,6 +296,7 @@ func (ac appCreator) appExport(
loadLatest,
ac.encCfg,
appOpts,
false,
)

if height != -1 {
Expand Down
1 change: 1 addition & 0 deletions testutil/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func setup(
true,
encCdc,
appOpts,
true,
baseAppOptions...,
)
return &AppWrapper{app}
Expand Down

0 comments on commit 4d1e6e7

Please sign in to comment.