Some checks are pending
Build SimApp / build (amd64) (push) Waiting to run
Build SimApp / build (arm64) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Build & Push / build (push) Waiting to run
Run Gosec / Gosec (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Checks dependencies and mocks generation / Check go mod tidy (push) Waiting to run
Checks dependencies and mocks generation / Check up to date mocks (push) Waiting to run
System Tests / setup (push) Waiting to run
System Tests / test-system (push) Blocked by required conditions
System Tests / test-system-legacy (push) Blocked by required conditions
Tests / Code Coverage / split-test-files (push) Waiting to run
Tests / Code Coverage / tests (00) (push) Blocked by required conditions
Tests / Code Coverage / tests (01) (push) Blocked by required conditions
Tests / Code Coverage / tests (02) (push) Blocked by required conditions
Tests / Code Coverage / tests (03) (push) Blocked by required conditions
Tests / Code Coverage / test-integration (push) Waiting to run
Tests / Code Coverage / test-e2e (push) Waiting to run
Tests / Code Coverage / repo-analysis (push) Blocked by required conditions
Tests / Code Coverage / test-sim-nondeterminism (push) Waiting to run
Tests / Code Coverage / test-clientv2 (push) Waiting to run
Tests / Code Coverage / test-core (push) Waiting to run
Tests / Code Coverage / test-depinject (push) Waiting to run
Tests / Code Coverage / test-errors (push) Waiting to run
Tests / Code Coverage / test-math (push) Waiting to run
Tests / Code Coverage / test-schema (push) Waiting to run
Tests / Code Coverage / test-collections (push) Waiting to run
Tests / Code Coverage / test-cosmovisor (push) Waiting to run
Tests / Code Coverage / test-confix (push) Waiting to run
Tests / Code Coverage / test-store (push) Waiting to run
Tests / Code Coverage / test-log (push) Waiting to run
Tests / Code Coverage / test-x-tx (push) Waiting to run
Tests / Code Coverage / test-x-nft (push) Waiting to run
Tests / Code Coverage / test-x-circuit (push) Waiting to run
Tests / Code Coverage / test-x-feegrant (push) Waiting to run
Tests / Code Coverage / test-x-evidence (push) Waiting to run
Tests / Code Coverage / test-x-upgrade (push) Waiting to run
Tests / Code Coverage / test-tools-benchmark (push) Waiting to run
91 lines
2.7 KiB
Go
91 lines
2.7 KiB
Go
package simulation
|
|
|
|
import (
|
|
"fmt"
|
|
"math/rand"
|
|
|
|
"cosmossdk.io/math"
|
|
|
|
"git.cw.tr/mukan-network/mukan-sdk/baseapp"
|
|
"git.cw.tr/mukan-network/mukan-sdk/client"
|
|
sdk "git.cw.tr/mukan-network/mukan-sdk/types"
|
|
simtypes "git.cw.tr/mukan-network/mukan-sdk/types/simulation"
|
|
"git.cw.tr/mukan-network/mukan-sdk/x/protocolpool/keeper"
|
|
"git.cw.tr/mukan-network/mukan-sdk/x/protocolpool/types"
|
|
"git.cw.tr/mukan-network/mukan-sdk/x/simulation"
|
|
)
|
|
|
|
var TypeFundCommunityPool = sdk.MsgTypeURL(&types.MsgFundCommunityPool{})
|
|
|
|
// Simulation operation weights constants
|
|
const (
|
|
OpWeightMsgFundCommunityPool = "op_weight_msg_fund_community_pool"
|
|
|
|
DefaultWeightMsgFundCommunityPool = 100
|
|
)
|
|
|
|
// WeightedOperations returns all the operations from the module with their respective weights
|
|
func WeightedOperations(
|
|
appParams simtypes.AppParams,
|
|
txGen client.TxConfig,
|
|
ak types.AccountKeeper,
|
|
bk types.BankKeeper,
|
|
k keeper.Keeper,
|
|
) simulation.WeightedOperations {
|
|
var weightMsgFundCommunityPool int
|
|
|
|
appParams.GetOrGenerate(OpWeightMsgFundCommunityPool, &weightMsgFundCommunityPool, nil,
|
|
func(_ *rand.Rand) {
|
|
weightMsgFundCommunityPool = DefaultWeightMsgFundCommunityPool
|
|
},
|
|
)
|
|
|
|
return simulation.WeightedOperations{
|
|
simulation.NewWeightedOperation(
|
|
weightMsgFundCommunityPool,
|
|
SimulateMsgFundCommunityPool(txGen, ak, bk, k),
|
|
),
|
|
}
|
|
}
|
|
|
|
func SimulateMsgFundCommunityPool(
|
|
txGen client.TxConfig,
|
|
ak types.AccountKeeper,
|
|
bk types.BankKeeper,
|
|
_ keeper.Keeper,
|
|
) simtypes.Operation {
|
|
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
|
|
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
|
simAccount, _ := simtypes.RandomAcc(r, accs)
|
|
account := ak.GetAccount(ctx, simAccount.Address)
|
|
spendable := bk.SpendableCoins(ctx, account.GetAddress())
|
|
// choose 10% - 70% of spendable
|
|
// we do not want to use the full balance so that fees can be covered
|
|
decimalVal := r.Intn(6) + 1 // [1:7]
|
|
spendableSubAmount := keeper.PercentageCoinMul(math.LegacyMustNewDecFromStr(fmt.Sprintf("0.%d", decimalVal)), spendable)
|
|
if spendableSubAmount.IsZero() {
|
|
return simtypes.NoOpMsg(types.ModuleName, TypeFundCommunityPool, "no balance"), nil, nil
|
|
}
|
|
|
|
msg := &types.MsgFundCommunityPool{
|
|
Amount: spendableSubAmount,
|
|
Depositor: account.GetAddress().String(),
|
|
}
|
|
|
|
txCtx := simulation.OperationInput{
|
|
R: r,
|
|
App: app,
|
|
TxGen: txGen,
|
|
Cdc: nil,
|
|
Msg: msg,
|
|
Context: ctx,
|
|
SimAccount: simAccount,
|
|
AccountKeeper: ak,
|
|
Bankkeeper: bk,
|
|
ModuleName: types.ModuleName,
|
|
CoinsSpentInMsg: spendableSubAmount,
|
|
}
|
|
|
|
return simulation.GenAndDeliverTxWithRandFees(txCtx)
|
|
}
|
|
}
|