Skip to content

Commit

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

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

sim = options.Simulation

txWithExtensions, ok := tx.(authante.HasExtensionOptionsTx)
if ok {
opts := txWithExtensions.GetExtensionOptions()
Expand Down
13 changes: 13 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,18 @@ 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
Simulation bool
}

// newCosmosAnteHandler creates the default ante handler for Ethereum transactions
Expand Down
8 changes: 8 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ func NewIrisApp(
app.MountMemoryStores(app.MemoryStoreKeys())

maxGasWanted := cast.ToUint64(appOpts.Get(srvflags.EVMMaxTxGasWanted))

simulation := false
opt = appOpts.Get(params.Simulation)
if opt, ok := opt.(bool); ok {
simulation = opt
}

anteHandler := irishubante.NewAnteHandler(
irishubante.HandlerOptions{
HandlerOptions: ante.HandlerOptions{
Expand All @@ -195,6 +202,7 @@ func NewIrisApp(
FeeMarketKeeper: app.FeeMarketKeeper,
BypassMinFeeMsgTypes: []string{},
MaxTxGasWanted: maxGasWanted,
Simulation: simulation,
},
)

Expand Down
1 change: 1 addition & 0 deletions app/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ package params
const (
StakePerAccount = "stake_per_account"
InitiallyBondedValidators = "initially_bonded_validators"
Simulation = "simulation"
)
10 changes: 8 additions & 2 deletions app/sim_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli"

"github.com/irisnet/irishub/v4/app/params"
)

// Profile with:
Expand Down Expand Up @@ -51,7 +53,9 @@ func BenchmarkFullAppSimulation(b *testing.B) {
nil,
true,
encfg,
EmptyAppOptions{},
SimTestAppOptions{
options: map[string]interface{}{params.Simulation: true},
},
interBlockCacheOpt(),
)

Expand Down Expand Up @@ -118,7 +122,9 @@ func BenchmarkInvariants(b *testing.B) {
nil,
true,
encfg,
EmptyAppOptions{},
SimTestAppOptions{
options: map[string]interface{}{params.Simulation: true},
},
interBlockCacheOpt(),
)

Expand Down
14 changes: 13 additions & 1 deletion app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,16 @@ func (ao EmptyAppOptions) Get(o string) interface{} {
return nil
}

// SimTestAppOptions is a stub implementing AppOptions
type SimTestAppOptions struct {
options map[string]interface{}
}

// Get implements AppOptions
func (o SimTestAppOptions) Get(key string) interface{} {
return o.options[key]
}

func createApp(
logger log.Logger,
db dbm.DB,
Expand All @@ -494,7 +504,9 @@ func createApp(
nil,
true,
encodingConfig,
EmptyAppOptions{},
SimTestAppOptions{
options: map[string]interface{}{params.Simulation: true},
},
baseAppOptions...,
)
}

0 comments on commit 8ebfe3c

Please sign in to comment.