Skip to content

Commit

Permalink
Merge pull request #470 from irisnet/feature/up_simulate
Browse files Browse the repository at this point in the history
update simulation
  • Loading branch information
mitch1024 authored Dec 19, 2024
2 parents 1380d52 + 0ad41be commit 96f998e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion modules/coinswap/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func RandomizedGenState(simState *module.SimulationState) {

simState.AppParams.GetOrGenerate(
keyPoolCreationFee, &poolCreationFee, simState.Rand,
func(r *rand.Rand) { poolCreationFee = sdk.NewInt64Coin(sdk.DefaultBondDenom, r.Int63n(100)) },
func(r *rand.Rand) { poolCreationFee = sdk.NewInt64Coin(sdk.DefaultBondDenom, r.Int63n(100)+1) },
)

simState.AppParams.GetOrGenerate(
Expand Down
2 changes: 1 addition & 1 deletion modules/service/keeper/invocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func (k Keeper) UpdateRequestContext(
repeatedFreq = requestContext.RepeatedFrequency
}

if repeatedFreq < uint64(timeout) {
if requestContext.Repeated && repeatedFreq < uint64(timeout) {
return errorsmod.Wrapf(
types.ErrInvalidRepeatedFreq,
"repeated frequency [%d] must not be less than the timeout [%d]",
Expand Down
22 changes: 17 additions & 5 deletions modules/service/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package simulation
import (
"errors"
"fmt"
"math/rand"

"cosmossdk.io/math"
tmbytes "github.com/cometbft/cometbft/libs/bytes"
Expand All @@ -14,6 +13,7 @@ import (
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
"math/rand"

"mods.irisnet.org/modules/service/keeper"
"mods.irisnet.org/modules/service/types"
Expand Down Expand Up @@ -990,12 +990,15 @@ func SimulateMsgCallService(
}
timeout := int64(simtypes.RandIntBetween(r, 1, int(k.MaxRequestTimeout(ctx))))

repeated := true
repeatedFrequency := uint64(100)
repeatedTotal := int64(10)
repeated := r.Intn(2) == 0
var repeatedFrequency, repeatedTotal uint64
if repeated {
repeatedFrequency = uint64(100)
repeatedTotal = uint64(10)
}

msg := types.NewMsgCallService(serviceName, providers, consumer, input,
serviceFeeCap, timeout, repeated, repeatedFrequency, repeatedTotal)
serviceFeeCap, timeout, repeated, repeatedFrequency, int64(repeatedTotal))

spendable := bk.SpendableCoins(ctx, account.GetAddress())
spendable, hasNeg := spendable.SafeSub(serviceFeeCap...)
Expand Down Expand Up @@ -1158,6 +1161,15 @@ func SimulateMsgPauseRequestContext(
"not authorized operation",
), nil, nil
}

if !requestContext.Repeated {
return simtypes.NoOpMsg(
types.ModuleName,
types.TypeMsgPauseRequestContext,
"requestContext non repeated",
), nil, nil
}

consumer, err := sdk.AccAddressFromBech32(requestContext.Consumer)
if err != nil {
return simtypes.NoOpMsg(
Expand Down
2 changes: 1 addition & 1 deletion modules/token/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func RandomizedGenState(simState *module.SimulationState) {
)

tokenGenesis := v1.NewGenesisState(
v1.NewParams(tokenTaxRate, sdk.NewCoin(sdk.DefaultBondDenom, issueTokenBaseFee), mintTokenFeeRatio, enableErc20, ""),
v1.NewParams(tokenTaxRate, sdk.NewCoin(v1.GetNativeToken().Symbol, issueTokenBaseFee), mintTokenFeeRatio, enableErc20, ""),
tokens,
)

Expand Down

0 comments on commit 96f998e

Please sign in to comment.