Skip to content

Commit

Permalink
simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
avery committed Dec 16, 2024
1 parent 1380d52 commit 885e3be
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 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
16 changes: 9 additions & 7 deletions modules/service/keeper/invocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,15 @@ func (k Keeper) UpdateRequestContext(
repeatedFreq = requestContext.RepeatedFrequency
}

if repeatedFreq < uint64(timeout) {
return errorsmod.Wrapf(
types.ErrInvalidRepeatedFreq,
"repeated frequency [%d] must not be less than the timeout [%d]",
repeatedFreq,
requestContext.Timeout,
)
if requestContext.Repeated {
if repeatedFreq < uint64(timeout) {
return errorsmod.Wrapf(
types.ErrInvalidRepeatedFreq,
"repeated frequency [%d] must not be less than the timeout [%d]",
repeatedFreq,
requestContext.Timeout,
)
}
}

if repeatedTotal >= 1 && repeatedTotal < int64(requestContext.BatchCounter) {
Expand Down
26 changes: 21 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 Expand Up @@ -1484,6 +1496,10 @@ func SimulateMsgUpdateRequestContext(
timeout := r.Int63n(k.MaxRequestTimeout(ctx))
repeatedFrequency := uint64(0)
repeatedTotal := int64(0)
//if requestContext.Repeated {
// repeatedFrequency = requestContext.RepeatedFrequency
// repeatedTotal = int64(repeatedTotal)
//}

msg := types.NewMsgUpdateRequestContext(
requestContextId.String(),
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 885e3be

Please sign in to comment.