From 885e3be8569027df5c8a96e4340cd3bf40a4c35d Mon Sep 17 00:00:00 2001 From: avery <> Date: Mon, 16 Dec 2024 16:30:08 +0100 Subject: [PATCH 1/2] simulation --- modules/coinswap/simulation/genesis.go | 2 +- modules/service/keeper/invocation.go | 16 ++++++++------- modules/service/simulation/operations.go | 26 +++++++++++++++++++----- modules/token/simulation/genesis.go | 2 +- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/modules/coinswap/simulation/genesis.go b/modules/coinswap/simulation/genesis.go index e73cf0de..86bb3501 100644 --- a/modules/coinswap/simulation/genesis.go +++ b/modules/coinswap/simulation/genesis.go @@ -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( diff --git a/modules/service/keeper/invocation.go b/modules/service/keeper/invocation.go index da4134de..fb0c5a75 100644 --- a/modules/service/keeper/invocation.go +++ b/modules/service/keeper/invocation.go @@ -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) { diff --git a/modules/service/simulation/operations.go b/modules/service/simulation/operations.go index 5e17bd42..b6645846 100644 --- a/modules/service/simulation/operations.go +++ b/modules/service/simulation/operations.go @@ -3,7 +3,6 @@ package simulation import ( "errors" "fmt" - "math/rand" "cosmossdk.io/math" tmbytes "github.com/cometbft/cometbft/libs/bytes" @@ -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" @@ -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...) @@ -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( @@ -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(), diff --git a/modules/token/simulation/genesis.go b/modules/token/simulation/genesis.go index 0db47cd9..742ba439 100644 --- a/modules/token/simulation/genesis.go +++ b/modules/token/simulation/genesis.go @@ -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, ) From 0ad41be03ac68b241ced36ac44adc2e0a5fbbeb5 Mon Sep 17 00:00:00 2001 From: avery <> Date: Tue, 17 Dec 2024 09:01:51 +0100 Subject: [PATCH 2/2] format code --- modules/service/keeper/invocation.go | 16 +++++++--------- modules/service/simulation/operations.go | 4 ---- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/modules/service/keeper/invocation.go b/modules/service/keeper/invocation.go index fb0c5a75..50cbac69 100644 --- a/modules/service/keeper/invocation.go +++ b/modules/service/keeper/invocation.go @@ -236,15 +236,13 @@ func (k Keeper) UpdateRequestContext( repeatedFreq = requestContext.RepeatedFrequency } - 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 requestContext.Repeated && 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) { diff --git a/modules/service/simulation/operations.go b/modules/service/simulation/operations.go index b6645846..5ee0e991 100644 --- a/modules/service/simulation/operations.go +++ b/modules/service/simulation/operations.go @@ -1496,10 +1496,6 @@ 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(),