2022-01-21 02:52:26 -08:00
|
|
|
package simulation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
|
|
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/simapp/helpers"
|
|
|
|
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
|
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/group/keeper"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/simulation"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/group"
|
|
|
|
)
|
|
|
|
|
|
|
|
var initialGroupID = uint64(100000000000000)
|
|
|
|
|
|
|
|
// group message types
|
|
|
|
var (
|
|
|
|
TypeMsgCreateGroup = sdk.MsgTypeURL(&group.MsgCreateGroup{})
|
|
|
|
TypeMsgUpdateGroupMembers = sdk.MsgTypeURL(&group.MsgUpdateGroupMembers{})
|
|
|
|
TypeMsgUpdateGroupAdmin = sdk.MsgTypeURL(&group.MsgUpdateGroupAdmin{})
|
|
|
|
TypeMsgUpdateGroupMetadata = sdk.MsgTypeURL(&group.MsgUpdateGroupMetadata{})
|
2022-02-18 05:47:04 -08:00
|
|
|
TypeMsgCreateGroupWithPolicy = sdk.MsgTypeURL(&group.MsgCreateGroupWithPolicy{})
|
2022-01-21 02:52:26 -08:00
|
|
|
TypeMsgCreateGroupPolicy = sdk.MsgTypeURL(&group.MsgCreateGroupPolicy{})
|
|
|
|
TypeMsgUpdateGroupPolicyAdmin = sdk.MsgTypeURL(&group.MsgUpdateGroupPolicyAdmin{})
|
|
|
|
TypeMsgUpdateGroupPolicyDecisionPolicy = sdk.MsgTypeURL(&group.MsgUpdateGroupPolicyDecisionPolicy{})
|
|
|
|
TypeMsgUpdateGroupPolicyMetadata = sdk.MsgTypeURL(&group.MsgUpdateGroupPolicyMetadata{})
|
2022-02-14 05:48:17 -08:00
|
|
|
TypeMsgSubmitProposal = sdk.MsgTypeURL(&group.MsgSubmitProposal{})
|
2022-02-04 00:37:45 -08:00
|
|
|
TypeMsgWithdrawProposal = sdk.MsgTypeURL(&group.MsgWithdrawProposal{})
|
2022-01-21 02:52:26 -08:00
|
|
|
TypeMsgVote = sdk.MsgTypeURL(&group.MsgVote{})
|
|
|
|
TypeMsgExec = sdk.MsgTypeURL(&group.MsgExec{})
|
2022-03-04 06:03:31 -08:00
|
|
|
TypeMsgLeaveGroup = sdk.MsgTypeURL(&group.MsgLeaveGroup{})
|
2022-01-21 02:52:26 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
// Simulation operation weights constants
|
|
|
|
const (
|
|
|
|
OpMsgCreateGroup = "op_weight_msg_create_group"
|
|
|
|
OpMsgUpdateGroupAdmin = "op_weight_msg_update_group_admin"
|
|
|
|
OpMsgUpdateGroupMetadata = "op_wieght_msg_update_group_metadata"
|
|
|
|
OpMsgUpdateGroupMembers = "op_weight_msg_update_group_members"
|
2022-02-18 05:47:04 -08:00
|
|
|
OpMsgCreateGroupPolicy = "op_weight_msg_create_group_account"
|
|
|
|
OpMsgCreateGroupWithPolicy = "op_weight_msg_create_group_with_policy"
|
|
|
|
OpMsgUpdateGroupPolicyAdmin = "op_weight_msg_update_group_account_admin"
|
|
|
|
OpMsgUpdateGroupPolicyDecisionPolicy = "op_weight_msg_update_group_account_decision_policy"
|
|
|
|
OpMsgUpdateGroupPolicyMetaData = "op_weight_msg_update_group_account_metadata"
|
2022-02-14 05:48:17 -08:00
|
|
|
OpMsgSubmitProposal = "op_weight_msg_submit_proposal"
|
2022-02-04 00:37:45 -08:00
|
|
|
OpMsgWithdrawProposal = "op_weight_msg_withdraw_proposal"
|
2022-01-21 02:52:26 -08:00
|
|
|
OpMsgVote = "op_weight_msg_vote"
|
2022-03-04 06:03:31 -08:00
|
|
|
OpMsgExec = "ops_weight_msg_exec"
|
|
|
|
OpMsgLeaveGroup = "ops_weight_msg_leave_group"
|
2022-01-21 02:52:26 -08:00
|
|
|
)
|
|
|
|
|
2022-02-04 00:37:45 -08:00
|
|
|
// If update group or group policy txn's executed, `SimulateMsgVote` & `SimulateMsgExec` txn's returns `noOp`.
|
|
|
|
// That's why we have less weight for update group & group-policy txn's.
|
2022-01-21 02:52:26 -08:00
|
|
|
const (
|
|
|
|
WeightMsgCreateGroup = 100
|
2022-02-18 05:47:04 -08:00
|
|
|
WeightMsgCreateGroupPolicy = 50
|
2022-02-14 05:48:17 -08:00
|
|
|
WeightMsgSubmitProposal = 90
|
2022-01-21 02:52:26 -08:00
|
|
|
WeightMsgVote = 90
|
|
|
|
WeightMsgExec = 90
|
2022-03-14 08:52:07 -07:00
|
|
|
WeightMsgLeaveGroup = 5
|
2022-01-21 02:52:26 -08:00
|
|
|
WeightMsgUpdateGroupMetadata = 5
|
|
|
|
WeightMsgUpdateGroupAdmin = 5
|
|
|
|
WeightMsgUpdateGroupMembers = 5
|
|
|
|
WeightMsgUpdateGroupPolicyAdmin = 5
|
|
|
|
WeightMsgUpdateGroupPolicyDecisionPolicy = 5
|
|
|
|
WeightMsgUpdateGroupPolicyMetadata = 5
|
2022-02-04 00:37:45 -08:00
|
|
|
WeightMsgWithdrawProposal = 20
|
2022-03-04 03:10:48 -08:00
|
|
|
WeightMsgCreateGroupWithPolicy = 50
|
2022-01-21 02:52:26 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
// WeightedOperations returns all the operations from the module with their respective weights
|
|
|
|
func WeightedOperations(
|
|
|
|
appParams simtypes.AppParams, cdc codec.JSONCodec, ak group.AccountKeeper,
|
|
|
|
bk group.BankKeeper, k keeper.Keeper, appCdc cdctypes.AnyUnpacker) simulation.WeightedOperations {
|
|
|
|
var (
|
|
|
|
weightMsgCreateGroup int
|
|
|
|
weightMsgUpdateGroupAdmin int
|
|
|
|
weightMsgUpdateGroupMetadata int
|
|
|
|
weightMsgUpdateGroupMembers int
|
|
|
|
weightMsgCreateGroupPolicy int
|
|
|
|
weightMsgUpdateGroupPolicyAdmin int
|
|
|
|
weightMsgUpdateGroupPolicyDecisionPolicy int
|
|
|
|
weightMsgUpdateGroupPolicyMetadata int
|
2022-02-14 05:48:17 -08:00
|
|
|
weightMsgSubmitProposal int
|
2022-01-21 02:52:26 -08:00
|
|
|
weightMsgVote int
|
|
|
|
weightMsgExec int
|
2022-03-04 06:03:31 -08:00
|
|
|
weightMsgLeaveGroup int
|
2022-02-04 00:37:45 -08:00
|
|
|
weightMsgWithdrawProposal int
|
2022-02-18 05:47:04 -08:00
|
|
|
weightMsgCreateGroupWithPolicy int
|
2022-01-21 02:52:26 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
appParams.GetOrGenerate(cdc, OpMsgCreateGroup, &weightMsgCreateGroup, nil,
|
|
|
|
func(_ *rand.Rand) {
|
|
|
|
weightMsgCreateGroup = WeightMsgCreateGroup
|
|
|
|
},
|
|
|
|
)
|
|
|
|
appParams.GetOrGenerate(cdc, OpMsgCreateGroupPolicy, &weightMsgCreateGroupPolicy, nil,
|
|
|
|
func(_ *rand.Rand) {
|
|
|
|
weightMsgCreateGroupPolicy = WeightMsgCreateGroupPolicy
|
|
|
|
},
|
|
|
|
)
|
2022-03-04 06:03:31 -08:00
|
|
|
appParams.GetOrGenerate(cdc, OpMsgLeaveGroup, &weightMsgLeaveGroup, nil,
|
|
|
|
func(_ *rand.Rand) {
|
|
|
|
weightMsgLeaveGroup = WeightMsgLeaveGroup
|
|
|
|
},
|
|
|
|
)
|
2022-02-18 05:47:04 -08:00
|
|
|
appParams.GetOrGenerate(cdc, OpMsgCreateGroupWithPolicy, &weightMsgCreateGroupWithPolicy, nil,
|
|
|
|
func(_ *rand.Rand) {
|
|
|
|
weightMsgCreateGroupWithPolicy = WeightMsgCreateGroupWithPolicy
|
|
|
|
},
|
|
|
|
)
|
2022-02-14 05:48:17 -08:00
|
|
|
appParams.GetOrGenerate(cdc, OpMsgSubmitProposal, &weightMsgSubmitProposal, nil,
|
2022-01-21 02:52:26 -08:00
|
|
|
func(_ *rand.Rand) {
|
2022-02-14 05:48:17 -08:00
|
|
|
weightMsgSubmitProposal = WeightMsgSubmitProposal
|
2022-01-21 02:52:26 -08:00
|
|
|
},
|
|
|
|
)
|
|
|
|
appParams.GetOrGenerate(cdc, OpMsgVote, &weightMsgVote, nil,
|
|
|
|
func(_ *rand.Rand) {
|
|
|
|
weightMsgVote = WeightMsgVote
|
|
|
|
},
|
|
|
|
)
|
|
|
|
appParams.GetOrGenerate(cdc, OpMsgExec, &weightMsgExec, nil,
|
|
|
|
func(_ *rand.Rand) {
|
|
|
|
weightMsgExec = WeightMsgExec
|
|
|
|
},
|
|
|
|
)
|
|
|
|
appParams.GetOrGenerate(cdc, OpMsgUpdateGroupMetadata, &weightMsgUpdateGroupMetadata, nil,
|
|
|
|
func(_ *rand.Rand) {
|
|
|
|
weightMsgUpdateGroupMetadata = WeightMsgUpdateGroupMetadata
|
|
|
|
},
|
|
|
|
)
|
|
|
|
appParams.GetOrGenerate(cdc, OpMsgUpdateGroupAdmin, &weightMsgUpdateGroupAdmin, nil,
|
|
|
|
func(_ *rand.Rand) {
|
|
|
|
weightMsgUpdateGroupAdmin = WeightMsgUpdateGroupAdmin
|
|
|
|
},
|
|
|
|
)
|
|
|
|
appParams.GetOrGenerate(cdc, OpMsgUpdateGroupMembers, &weightMsgUpdateGroupMembers, nil,
|
|
|
|
func(_ *rand.Rand) {
|
|
|
|
weightMsgUpdateGroupMembers = WeightMsgUpdateGroupMembers
|
|
|
|
},
|
|
|
|
)
|
|
|
|
appParams.GetOrGenerate(cdc, OpMsgUpdateGroupPolicyAdmin, &weightMsgUpdateGroupPolicyAdmin, nil,
|
|
|
|
func(_ *rand.Rand) {
|
|
|
|
weightMsgUpdateGroupPolicyAdmin = WeightMsgUpdateGroupPolicyAdmin
|
|
|
|
},
|
|
|
|
)
|
|
|
|
appParams.GetOrGenerate(cdc, OpMsgUpdateGroupPolicyDecisionPolicy, &weightMsgUpdateGroupPolicyDecisionPolicy, nil,
|
|
|
|
func(_ *rand.Rand) {
|
|
|
|
weightMsgUpdateGroupPolicyDecisionPolicy = WeightMsgUpdateGroupPolicyDecisionPolicy
|
|
|
|
},
|
|
|
|
)
|
|
|
|
appParams.GetOrGenerate(cdc, OpMsgUpdateGroupPolicyMetaData, &weightMsgUpdateGroupPolicyMetadata, nil,
|
|
|
|
func(_ *rand.Rand) {
|
|
|
|
weightMsgUpdateGroupPolicyMetadata = WeightMsgUpdateGroupPolicyMetadata
|
|
|
|
},
|
|
|
|
)
|
2022-02-04 00:37:45 -08:00
|
|
|
appParams.GetOrGenerate(cdc, OpMsgWithdrawProposal, &weightMsgWithdrawProposal, nil,
|
|
|
|
func(_ *rand.Rand) {
|
|
|
|
weightMsgWithdrawProposal = WeightMsgWithdrawProposal
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
// create two proposals for weightedOperations
|
|
|
|
var createProposalOps simulation.WeightedOperations
|
|
|
|
for i := 0; i < 2; i++ {
|
|
|
|
createProposalOps = append(createProposalOps, simulation.NewWeightedOperation(
|
2022-02-14 05:48:17 -08:00
|
|
|
weightMsgSubmitProposal,
|
|
|
|
SimulateMsgSubmitProposal(ak, bk, k),
|
2022-02-04 00:37:45 -08:00
|
|
|
))
|
|
|
|
}
|
2022-01-21 02:52:26 -08:00
|
|
|
|
2022-02-04 00:37:45 -08:00
|
|
|
wPreCreateProposalOps := simulation.WeightedOperations{
|
2022-01-21 02:52:26 -08:00
|
|
|
simulation.NewWeightedOperation(
|
|
|
|
weightMsgCreateGroup,
|
|
|
|
SimulateMsgCreateGroup(ak, bk),
|
|
|
|
),
|
|
|
|
simulation.NewWeightedOperation(
|
|
|
|
weightMsgCreateGroupPolicy,
|
|
|
|
SimulateMsgCreateGroupPolicy(ak, bk, k),
|
|
|
|
),
|
2022-03-04 03:10:48 -08:00
|
|
|
simulation.NewWeightedOperation(
|
|
|
|
weightMsgCreateGroupWithPolicy,
|
|
|
|
SimulateMsgCreateGroupWithPolicy(ak, bk),
|
|
|
|
),
|
2022-02-04 00:37:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
wPostCreateProposalOps := simulation.WeightedOperations{
|
2022-01-21 02:52:26 -08:00
|
|
|
simulation.NewWeightedOperation(
|
2022-02-04 00:37:45 -08:00
|
|
|
WeightMsgWithdrawProposal,
|
|
|
|
SimulateMsgWithdrawProposal(ak, bk, k),
|
2022-01-21 02:52:26 -08:00
|
|
|
),
|
|
|
|
simulation.NewWeightedOperation(
|
|
|
|
weightMsgVote,
|
|
|
|
SimulateMsgVote(ak, bk, k),
|
|
|
|
),
|
|
|
|
simulation.NewWeightedOperation(
|
|
|
|
weightMsgExec,
|
|
|
|
SimulateMsgExec(ak, bk, k),
|
|
|
|
),
|
|
|
|
simulation.NewWeightedOperation(
|
|
|
|
weightMsgUpdateGroupMetadata,
|
|
|
|
SimulateMsgUpdateGroupMetadata(ak, bk, k),
|
|
|
|
),
|
|
|
|
simulation.NewWeightedOperation(
|
|
|
|
weightMsgUpdateGroupAdmin,
|
|
|
|
SimulateMsgUpdateGroupAdmin(ak, bk, k),
|
|
|
|
),
|
|
|
|
simulation.NewWeightedOperation(
|
|
|
|
weightMsgUpdateGroupMembers,
|
|
|
|
SimulateMsgUpdateGroupMembers(ak, bk, k),
|
|
|
|
),
|
|
|
|
simulation.NewWeightedOperation(
|
|
|
|
weightMsgUpdateGroupPolicyAdmin,
|
|
|
|
SimulateMsgUpdateGroupPolicyAdmin(ak, bk, k),
|
|
|
|
),
|
|
|
|
simulation.NewWeightedOperation(
|
|
|
|
weightMsgUpdateGroupPolicyDecisionPolicy,
|
|
|
|
SimulateMsgUpdateGroupPolicyDecisionPolicy(ak, bk, k),
|
|
|
|
),
|
|
|
|
simulation.NewWeightedOperation(
|
|
|
|
weightMsgUpdateGroupPolicyMetadata,
|
|
|
|
SimulateMsgUpdateGroupPolicyMetadata(ak, bk, k),
|
|
|
|
),
|
2022-03-14 08:52:07 -07:00
|
|
|
simulation.NewWeightedOperation(
|
|
|
|
weightMsgLeaveGroup,
|
|
|
|
SimulateMsgLeaveGroup(k, ak, bk),
|
|
|
|
),
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
2022-02-04 00:37:45 -08:00
|
|
|
|
|
|
|
return append(wPreCreateProposalOps, append(createProposalOps, wPostCreateProposalOps...)...)
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// SimulateMsgCreateGroup generates a MsgCreateGroup with random values
|
|
|
|
func SimulateMsgCreateGroup(ak group.AccountKeeper, bk group.BankKeeper) simtypes.Operation {
|
|
|
|
return func(
|
|
|
|
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simtypes.Account, chainID string) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
|
|
|
acc, _ := simtypes.RandomAcc(r, accounts)
|
|
|
|
account := ak.GetAccount(ctx, acc.Address)
|
|
|
|
accAddr := acc.Address.String()
|
|
|
|
|
|
|
|
spendableCoins := bk.SpendableCoins(ctx, account.GetAddress())
|
|
|
|
fees, err := simtypes.RandomFees(r, ctx, spendableCoins)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgCreateGroup, "fee error"), nil, err
|
|
|
|
}
|
|
|
|
|
2022-02-18 05:47:04 -08:00
|
|
|
members := genGroupMembers(r, accounts)
|
2022-03-01 00:35:37 -08:00
|
|
|
msg := &group.MsgCreateGroup{Admin: accAddr, Members: members, Metadata: simtypes.RandStringOfLength(r, 10)}
|
2022-01-21 02:52:26 -08:00
|
|
|
|
|
|
|
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
2022-04-20 08:27:19 -07:00
|
|
|
tx, err := helpers.GenSignedMockTx(
|
2022-01-21 02:52:26 -08:00
|
|
|
txGen,
|
|
|
|
[]sdk.Msg{msg},
|
|
|
|
fees,
|
|
|
|
helpers.DefaultGenTxGas,
|
|
|
|
chainID,
|
|
|
|
[]uint64{account.GetAccountNumber()},
|
|
|
|
[]uint64{account.GetSequence()},
|
|
|
|
acc.PrivKey,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgCreateGroup, "unable to generate mock tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _, err = app.SimDeliver(txGen.TxEncoder(), tx)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return simtypes.NewOperationMsg(msg, true, "", nil), nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-18 05:47:04 -08:00
|
|
|
// SimulateMsgCreateGroupWithPolicy generates a MsgCreateGroupWithPolicy with random values
|
|
|
|
func SimulateMsgCreateGroupWithPolicy(ak group.AccountKeeper, bk group.BankKeeper) simtypes.Operation {
|
|
|
|
return func(
|
|
|
|
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simtypes.Account, chainID string) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
|
|
|
acc, _ := simtypes.RandomAcc(r, accounts)
|
|
|
|
account := ak.GetAccount(ctx, acc.Address)
|
|
|
|
accAddr := acc.Address.String()
|
|
|
|
|
|
|
|
spendableCoins := bk.SpendableCoins(ctx, account.GetAddress())
|
|
|
|
fees, err := simtypes.RandomFees(r, ctx, spendableCoins)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgCreateGroup, "fee error"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
members := genGroupMembers(r, accounts)
|
|
|
|
decisionPolicy := &group.ThresholdDecisionPolicy{
|
|
|
|
Threshold: fmt.Sprintf("%d", simtypes.RandIntBetween(r, 1, 10)),
|
2022-03-02 04:00:59 -08:00
|
|
|
Windows: &group.DecisionPolicyWindows{
|
|
|
|
VotingPeriod: time.Second * time.Duration(30*24*60*60),
|
|
|
|
},
|
2022-02-18 05:47:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
msg := &group.MsgCreateGroupWithPolicy{
|
|
|
|
Admin: accAddr,
|
|
|
|
Members: members,
|
2022-03-01 00:35:37 -08:00
|
|
|
GroupMetadata: simtypes.RandStringOfLength(r, 10),
|
|
|
|
GroupPolicyMetadata: simtypes.RandStringOfLength(r, 10),
|
2022-02-18 05:47:04 -08:00
|
|
|
GroupPolicyAsAdmin: r.Float32() < 0.5,
|
|
|
|
}
|
|
|
|
msg.SetDecisionPolicy(decisionPolicy)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to set decision policy"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
2022-04-20 08:27:19 -07:00
|
|
|
tx, err := helpers.GenSignedMockTx(
|
2022-02-18 05:47:04 -08:00
|
|
|
txGen,
|
|
|
|
[]sdk.Msg{msg},
|
|
|
|
fees,
|
|
|
|
helpers.DefaultGenTxGas,
|
|
|
|
chainID,
|
|
|
|
[]uint64{account.GetAccountNumber()},
|
|
|
|
[]uint64{account.GetSequence()},
|
|
|
|
acc.PrivKey,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgCreateGroupWithPolicy, "unable to generate mock tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _, err = app.SimDeliver(txGen.TxEncoder(), tx)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-21 02:52:26 -08:00
|
|
|
// SimulateMsgCreateGroupPolicy generates a NewMsgCreateGroupPolicy with random values
|
|
|
|
func SimulateMsgCreateGroupPolicy(ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation {
|
|
|
|
return func(
|
|
|
|
r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
|
|
|
groupInfo, acc, account, err := randomGroup(r, k, ak, sdkCtx, accounts)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgCreateGroupPolicy, ""), nil, err
|
|
|
|
}
|
|
|
|
if groupInfo == nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgCreateGroupPolicy, ""), nil, nil
|
|
|
|
}
|
2022-02-14 05:48:17 -08:00
|
|
|
groupID := groupInfo.Id
|
2022-01-21 02:52:26 -08:00
|
|
|
|
|
|
|
spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress())
|
|
|
|
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgCreateGroupPolicy, "fee error"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
msg, err := group.NewMsgCreateGroupPolicy(
|
|
|
|
acc.Address,
|
|
|
|
groupID,
|
2022-03-01 00:35:37 -08:00
|
|
|
simtypes.RandStringOfLength(r, 10),
|
2022-01-21 02:52:26 -08:00
|
|
|
&group.ThresholdDecisionPolicy{
|
2022-02-18 05:47:04 -08:00
|
|
|
Threshold: fmt.Sprintf("%d", simtypes.RandIntBetween(r, 1, 10)),
|
2022-03-02 04:00:59 -08:00
|
|
|
Windows: &group.DecisionPolicyWindows{
|
|
|
|
VotingPeriod: time.Second * time.Duration(30*24*60*60),
|
|
|
|
},
|
2022-01-21 02:52:26 -08:00
|
|
|
},
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgCreateGroupPolicy, err.Error()), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
2022-04-20 08:27:19 -07:00
|
|
|
tx, err := helpers.GenSignedMockTx(
|
2022-01-21 02:52:26 -08:00
|
|
|
txGen,
|
|
|
|
[]sdk.Msg{msg},
|
|
|
|
fees,
|
|
|
|
helpers.DefaultGenTxGas,
|
|
|
|
chainID,
|
|
|
|
[]uint64{account.GetAccountNumber()},
|
|
|
|
[]uint64{account.GetSequence()},
|
|
|
|
acc.PrivKey,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgCreateGroupPolicy, "unable to generate mock tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _, err = app.SimDeliver(txGen.TxEncoder(), tx)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("ERR DELIVER %v\n", err)
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return simtypes.NewOperationMsg(msg, true, "", nil), nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-14 05:48:17 -08:00
|
|
|
// SimulateMsgSubmitProposal generates a NewMsgSubmitProposal with random values
|
|
|
|
func SimulateMsgSubmitProposal(ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation {
|
2022-01-21 02:52:26 -08:00
|
|
|
return func(
|
|
|
|
r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
|
|
|
g, groupPolicy, _, _, err := randomGroupPolicy(r, k, ak, sdkCtx, accounts)
|
|
|
|
if err != nil {
|
2022-02-14 05:48:17 -08:00
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgSubmitProposal, ""), nil, err
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
if g == nil {
|
2022-02-14 05:48:17 -08:00
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgSubmitProposal, "no group found"), nil, nil
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
if groupPolicy == nil {
|
2022-02-14 05:48:17 -08:00
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgSubmitProposal, "no group policy found"), nil, nil
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
2022-02-14 05:48:17 -08:00
|
|
|
groupID := g.Id
|
2022-01-21 02:52:26 -08:00
|
|
|
groupPolicyAddr := groupPolicy.Address
|
|
|
|
|
|
|
|
// Return a no-op if we know the proposal cannot be created
|
2022-04-15 03:35:45 -07:00
|
|
|
policy, err := groupPolicy.GetDecisionPolicy()
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgSubmitProposal, ""), nil, nil
|
|
|
|
}
|
2022-03-02 04:00:59 -08:00
|
|
|
err = policy.Validate(*g, group.DefaultConfig())
|
2022-01-21 02:52:26 -08:00
|
|
|
if err != nil {
|
2022-02-14 05:48:17 -08:00
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgSubmitProposal, ""), nil, nil
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pick a random member from the group
|
|
|
|
ctx := sdk.WrapSDKContext(sdkCtx)
|
|
|
|
acc, account, err := randomMember(r, k, ak, ctx, accounts, groupID)
|
|
|
|
if err != nil {
|
2022-02-14 05:48:17 -08:00
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgSubmitProposal, ""), nil, err
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
if account == nil {
|
2022-02-14 05:48:17 -08:00
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgSubmitProposal, "no group member found"), nil, nil
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress())
|
|
|
|
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
|
|
|
|
if err != nil {
|
2022-02-14 05:48:17 -08:00
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgSubmitProposal, "fee error"), nil, err
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
|
2022-02-14 05:48:17 -08:00
|
|
|
msg := group.MsgSubmitProposal{
|
2022-04-06 04:16:23 -07:00
|
|
|
GroupPolicyAddress: groupPolicyAddr,
|
|
|
|
Proposers: []string{acc.Address.String()},
|
|
|
|
Metadata: simtypes.RandStringOfLength(r, 10),
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
2022-04-20 08:27:19 -07:00
|
|
|
tx, err := helpers.GenSignedMockTx(
|
2022-01-21 02:52:26 -08:00
|
|
|
txGen,
|
|
|
|
[]sdk.Msg{&msg},
|
|
|
|
fees,
|
|
|
|
helpers.DefaultGenTxGas,
|
|
|
|
chainID,
|
|
|
|
[]uint64{account.GetAccountNumber()},
|
|
|
|
[]uint64{account.GetSequence()},
|
|
|
|
acc.PrivKey,
|
|
|
|
)
|
|
|
|
if err != nil {
|
2022-02-14 05:48:17 -08:00
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgSubmitProposal, "unable to generate mock tx"), nil, err
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
_, _, err = app.SimDeliver(txGen.TxEncoder(), tx)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SimulateMsgUpdateGroupAdmin generates a MsgUpdateGroupAdmin with random values
|
|
|
|
func SimulateMsgUpdateGroupAdmin(ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation {
|
|
|
|
return func(
|
|
|
|
r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
|
|
|
groupInfo, acc, account, err := randomGroup(r, k, ak, sdkCtx, accounts)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupAdmin, ""), nil, err
|
|
|
|
}
|
|
|
|
if groupInfo == nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupAdmin, ""), nil, nil
|
|
|
|
}
|
2022-02-14 05:48:17 -08:00
|
|
|
groupID := groupInfo.Id
|
2022-01-21 02:52:26 -08:00
|
|
|
|
|
|
|
spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress())
|
|
|
|
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupAdmin, "fee error"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(accounts) == 1 {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupAdmin, "can't set a new admin with only one account"), nil, nil
|
|
|
|
}
|
|
|
|
newAdmin, _ := simtypes.RandomAcc(r, accounts)
|
|
|
|
// disallow setting current admin as new admin
|
|
|
|
for acc.PubKey.Equals(newAdmin.PubKey) {
|
|
|
|
newAdmin, _ = simtypes.RandomAcc(r, accounts)
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := group.MsgUpdateGroupAdmin{
|
|
|
|
GroupId: groupID,
|
|
|
|
Admin: account.GetAddress().String(),
|
|
|
|
NewAdmin: newAdmin.Address.String(),
|
|
|
|
}
|
|
|
|
|
|
|
|
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
2022-04-20 08:27:19 -07:00
|
|
|
tx, err := helpers.GenSignedMockTx(
|
2022-01-21 02:52:26 -08:00
|
|
|
txGen,
|
|
|
|
[]sdk.Msg{&msg},
|
|
|
|
fees,
|
|
|
|
helpers.DefaultGenTxGas,
|
|
|
|
chainID,
|
|
|
|
[]uint64{account.GetAccountNumber()},
|
|
|
|
[]uint64{account.GetSequence()},
|
|
|
|
acc.PrivKey,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupAdmin, "unable to generate mock tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _, err = app.SimDeliver(txGen.TxEncoder(), tx)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SimulateMsgUpdateGroupMetadata generates a MsgUpdateGroupMetadata with random values
|
|
|
|
func SimulateMsgUpdateGroupMetadata(ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation {
|
|
|
|
return func(
|
|
|
|
r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
|
|
|
groupInfo, acc, account, err := randomGroup(r, k, ak, sdkCtx, accounts)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupMetadata, ""), nil, err
|
|
|
|
}
|
|
|
|
if groupInfo == nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupMetadata, ""), nil, nil
|
|
|
|
}
|
2022-02-14 05:48:17 -08:00
|
|
|
groupID := groupInfo.Id
|
2022-01-21 02:52:26 -08:00
|
|
|
|
|
|
|
spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress())
|
|
|
|
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupMetadata, "fee error"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := group.MsgUpdateGroupMetadata{
|
|
|
|
GroupId: groupID,
|
|
|
|
Admin: account.GetAddress().String(),
|
2022-03-01 00:35:37 -08:00
|
|
|
Metadata: simtypes.RandStringOfLength(r, 10),
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
2022-04-20 08:27:19 -07:00
|
|
|
tx, err := helpers.GenSignedMockTx(
|
2022-01-21 02:52:26 -08:00
|
|
|
txGen,
|
|
|
|
[]sdk.Msg{&msg},
|
|
|
|
fees,
|
|
|
|
helpers.DefaultGenTxGas,
|
|
|
|
chainID,
|
|
|
|
[]uint64{account.GetAccountNumber()},
|
|
|
|
[]uint64{account.GetSequence()},
|
|
|
|
acc.PrivKey,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupMetadata, "unable to generate mock tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _, err = app.SimDeliver(txGen.TxEncoder(), tx)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SimulateMsgUpdateGroupMembers generates a MsgUpdateGroupMembers with random values
|
|
|
|
func SimulateMsgUpdateGroupMembers(ak group.AccountKeeper,
|
|
|
|
bk group.BankKeeper, k keeper.Keeper) simtypes.Operation {
|
|
|
|
return func(
|
|
|
|
r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
|
|
|
groupInfo, acc, account, err := randomGroup(r, k, ak, sdkCtx, accounts)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupMembers, ""), nil, err
|
|
|
|
}
|
|
|
|
if groupInfo == nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupMembers, ""), nil, nil
|
|
|
|
}
|
2022-02-14 05:48:17 -08:00
|
|
|
groupID := groupInfo.Id
|
2022-01-21 02:52:26 -08:00
|
|
|
|
|
|
|
spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress())
|
|
|
|
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupMembers, "fee error"), nil, err
|
|
|
|
}
|
|
|
|
|
2022-02-18 05:47:04 -08:00
|
|
|
members := genGroupMembers(r, accounts)
|
|
|
|
ctx := sdk.UnwrapSDKContext(sdkCtx)
|
|
|
|
res, err := k.GroupMembers(ctx, &group.QueryGroupMembersRequest{GroupId: groupID})
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupMembers, "group members"), nil, err
|
|
|
|
}
|
|
|
|
|
2022-04-29 05:01:20 -07:00
|
|
|
// set existing random group member weight to zero to remove from the group
|
2022-02-18 05:47:04 -08:00
|
|
|
existigMembers := res.Members
|
|
|
|
if len(existigMembers) > 0 {
|
|
|
|
memberToRemove := existigMembers[r.Intn(len(existigMembers))]
|
|
|
|
var isDuplicateMember bool
|
|
|
|
for idx, m := range members {
|
|
|
|
if m.Address == memberToRemove.Member.Address {
|
|
|
|
members[idx].Weight = "0"
|
|
|
|
isDuplicateMember = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !isDuplicateMember {
|
|
|
|
m := memberToRemove.Member
|
|
|
|
m.Weight = "0"
|
2022-04-29 05:01:20 -07:00
|
|
|
members = append(members, group.MemberToMemberRequest(m))
|
2022-02-18 05:47:04 -08:00
|
|
|
}
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
msg := group.MsgUpdateGroupMembers{
|
|
|
|
GroupId: groupID,
|
|
|
|
Admin: acc.Address.String(),
|
|
|
|
MemberUpdates: members,
|
|
|
|
}
|
|
|
|
|
|
|
|
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
2022-04-20 08:27:19 -07:00
|
|
|
tx, err := helpers.GenSignedMockTx(
|
2022-01-21 02:52:26 -08:00
|
|
|
txGen,
|
|
|
|
[]sdk.Msg{&msg},
|
|
|
|
fees,
|
|
|
|
helpers.DefaultGenTxGas,
|
|
|
|
chainID,
|
|
|
|
[]uint64{account.GetAccountNumber()},
|
|
|
|
[]uint64{account.GetSequence()},
|
|
|
|
acc.PrivKey,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupMembers, "unable to generate mock tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _, err = app.SimDeliver(txGen.TxEncoder(), tx)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SimulateMsgUpdateGroupPolicyAdmin generates a MsgUpdateGroupPolicyAdmin with random values
|
|
|
|
func SimulateMsgUpdateGroupPolicyAdmin(ak group.AccountKeeper, bk group.BankKeeper, k keeper.Keeper) simtypes.Operation {
|
|
|
|
return func(
|
|
|
|
r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
|
|
|
_, groupPolicy, acc, account, err := randomGroupPolicy(r, k, ak, sdkCtx, accounts)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyAdmin, ""), nil, err
|
|
|
|
}
|
|
|
|
if groupPolicy == nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyAdmin, "no group policy found"), nil, nil
|
|
|
|
}
|
|
|
|
groupPolicyAddr := groupPolicy.Address
|
|
|
|
|
|
|
|
spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress())
|
|
|
|
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyAdmin, "fee error"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(accounts) == 1 {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyAdmin, "can't set a new admin with only one account"), nil, nil
|
|
|
|
}
|
|
|
|
newAdmin, _ := simtypes.RandomAcc(r, accounts)
|
|
|
|
// disallow setting current admin as new admin
|
|
|
|
for acc.PubKey.Equals(newAdmin.PubKey) {
|
|
|
|
newAdmin, _ = simtypes.RandomAcc(r, accounts)
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := group.MsgUpdateGroupPolicyAdmin{
|
2022-04-06 04:16:23 -07:00
|
|
|
Admin: acc.Address.String(),
|
|
|
|
GroupPolicyAddress: groupPolicyAddr,
|
|
|
|
NewAdmin: newAdmin.Address.String(),
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
2022-04-20 08:27:19 -07:00
|
|
|
tx, err := helpers.GenSignedMockTx(
|
2022-01-21 02:52:26 -08:00
|
|
|
txGen,
|
|
|
|
[]sdk.Msg{&msg},
|
|
|
|
fees,
|
|
|
|
helpers.DefaultGenTxGas,
|
|
|
|
chainID,
|
|
|
|
[]uint64{account.GetAccountNumber()},
|
|
|
|
[]uint64{account.GetSequence()},
|
|
|
|
acc.PrivKey,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyAdmin, "unable to generate mock tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _, err = app.SimDeliver(txGen.TxEncoder(), tx)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-15 03:35:45 -07:00
|
|
|
// // SimulateMsgUpdateGroupPolicyDecisionPolicy generates a NewMsgUpdateGroupPolicyDecisionPolicy with random values
|
2022-01-21 02:52:26 -08:00
|
|
|
func SimulateMsgUpdateGroupPolicyDecisionPolicy(ak group.AccountKeeper,
|
|
|
|
bk group.BankKeeper, k keeper.Keeper) simtypes.Operation {
|
|
|
|
return func(
|
|
|
|
r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
|
|
|
_, groupPolicy, acc, account, err := randomGroupPolicy(r, k, ak, sdkCtx, accounts)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyDecisionPolicy, ""), nil, err
|
|
|
|
}
|
|
|
|
if groupPolicy == nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyDecisionPolicy, "no group policy found"), nil, nil
|
|
|
|
}
|
|
|
|
groupPolicyAddr := groupPolicy.Address
|
|
|
|
|
|
|
|
spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress())
|
|
|
|
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyDecisionPolicy, "fee error"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
groupPolicyBech32, err := sdk.AccAddressFromBech32(groupPolicyAddr)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyDecisionPolicy, fmt.Sprintf("fail to decide bech32 address: %s", err.Error())), nil, nil
|
|
|
|
}
|
|
|
|
|
2022-04-15 03:35:45 -07:00
|
|
|
msg, err := group.NewMsgUpdateGroupPolicyDecisionPolicy(acc.Address, groupPolicyBech32, &group.ThresholdDecisionPolicy{
|
2022-02-18 05:47:04 -08:00
|
|
|
Threshold: fmt.Sprintf("%d", simtypes.RandIntBetween(r, 1, 10)),
|
2022-03-02 04:00:59 -08:00
|
|
|
Windows: &group.DecisionPolicyWindows{
|
|
|
|
VotingPeriod: time.Second * time.Duration(simtypes.RandIntBetween(r, 100, 1000)),
|
|
|
|
},
|
2022-01-21 02:52:26 -08:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyDecisionPolicy, err.Error()), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
2022-04-20 08:27:19 -07:00
|
|
|
tx, err := helpers.GenSignedMockTx(
|
2022-01-21 02:52:26 -08:00
|
|
|
txGen,
|
|
|
|
[]sdk.Msg{msg},
|
|
|
|
fees,
|
|
|
|
helpers.DefaultGenTxGas,
|
|
|
|
chainID,
|
|
|
|
[]uint64{account.GetAccountNumber()},
|
|
|
|
[]uint64{account.GetSequence()},
|
|
|
|
acc.PrivKey,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyDecisionPolicy, "unable to generate mock tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _, err = app.SimDeliver(txGen.TxEncoder(), tx)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err
|
|
|
|
}
|
|
|
|
return simtypes.NewOperationMsg(msg, true, "", nil), nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// // SimulateMsgUpdateGroupPolicyMetadata generates a MsgUpdateGroupPolicyMetadata with random values
|
|
|
|
func SimulateMsgUpdateGroupPolicyMetadata(ak group.AccountKeeper,
|
|
|
|
bk group.BankKeeper, k keeper.Keeper) simtypes.Operation {
|
|
|
|
return func(
|
|
|
|
r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
|
|
|
_, groupPolicy, acc, account, err := randomGroupPolicy(r, k, ak, sdkCtx, accounts)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyMetadata, ""), nil, err
|
|
|
|
}
|
|
|
|
if groupPolicy == nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyMetadata, "no group policy found"), nil, nil
|
|
|
|
}
|
|
|
|
groupPolicyAddr := groupPolicy.Address
|
|
|
|
|
|
|
|
spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress())
|
|
|
|
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyMetadata, "fee error"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := group.MsgUpdateGroupPolicyMetadata{
|
2022-04-06 04:16:23 -07:00
|
|
|
Admin: acc.Address.String(),
|
|
|
|
GroupPolicyAddress: groupPolicyAddr,
|
|
|
|
Metadata: simtypes.RandStringOfLength(r, 10),
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
2022-04-20 08:27:19 -07:00
|
|
|
tx, err := helpers.GenSignedMockTx(
|
2022-01-21 02:52:26 -08:00
|
|
|
txGen,
|
|
|
|
[]sdk.Msg{&msg},
|
|
|
|
fees,
|
|
|
|
helpers.DefaultGenTxGas,
|
|
|
|
chainID,
|
|
|
|
[]uint64{account.GetAccountNumber()},
|
|
|
|
[]uint64{account.GetSequence()},
|
|
|
|
acc.PrivKey,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyMetadata, "unable to generate mock tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _, err = app.SimDeliver(txGen.TxEncoder(), tx)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-04 00:37:45 -08:00
|
|
|
// SimulateMsgWithdrawProposal generates a MsgWithdrawProposal with random values
|
|
|
|
func SimulateMsgWithdrawProposal(ak group.AccountKeeper,
|
|
|
|
bk group.BankKeeper, k keeper.Keeper) simtypes.Operation {
|
|
|
|
return func(
|
|
|
|
r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
|
|
|
g, groupPolicy, _, _, err := randomGroupPolicy(r, k, ak, sdkCtx, accounts)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgWithdrawProposal, ""), nil, err
|
|
|
|
}
|
|
|
|
if g == nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgWithdrawProposal, "no group found"), nil, nil
|
|
|
|
}
|
|
|
|
if groupPolicy == nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgWithdrawProposal, "no group policy found"), nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
groupPolicyAddr := groupPolicy.Address
|
|
|
|
ctx := sdk.WrapSDKContext(sdkCtx)
|
|
|
|
|
2022-04-15 03:35:45 -07:00
|
|
|
policy, err := groupPolicy.GetDecisionPolicy()
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgWithdrawProposal, err.Error()), nil, nil
|
|
|
|
}
|
2022-03-02 04:00:59 -08:00
|
|
|
err = policy.Validate(*g, group.DefaultConfig())
|
2022-02-04 00:37:45 -08:00
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgWithdrawProposal, err.Error()), nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
proposalsResult, err := k.ProposalsByGroupPolicy(ctx, &group.QueryProposalsByGroupPolicyRequest{Address: groupPolicyAddr})
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgWithdrawProposal, "fail to query group info"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
proposals := proposalsResult.GetProposals()
|
|
|
|
if len(proposals) == 0 {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgWithdrawProposal, "no proposals found"), nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var proposal *group.Proposal
|
|
|
|
proposalID := -1
|
|
|
|
|
|
|
|
for _, p := range proposals {
|
2022-02-14 05:48:17 -08:00
|
|
|
if p.Status == group.PROPOSAL_STATUS_SUBMITTED {
|
2022-03-02 04:00:59 -08:00
|
|
|
timeout := p.VotingPeriodEnd
|
2022-02-04 00:37:45 -08:00
|
|
|
proposal = p
|
2022-02-14 05:48:17 -08:00
|
|
|
proposalID = int(p.Id)
|
2022-02-04 00:37:45 -08:00
|
|
|
if timeout.Before(sdkCtx.BlockTime()) || timeout.Equal(sdkCtx.BlockTime()) {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgWithdrawProposal, "voting period ended: skipping"), nil, nil
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// return no-op if no proposal found
|
|
|
|
if proposalID == -1 {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgWithdrawProposal, "no proposals found"), nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// select a random proposer
|
|
|
|
proposers := proposal.Proposers
|
|
|
|
n := randIntInRange(r, len(proposers))
|
|
|
|
proposerIdx := findAccount(accounts, proposers[n])
|
|
|
|
proposer := accounts[proposerIdx]
|
|
|
|
proposerAcc := ak.GetAccount(sdkCtx, proposer.Address)
|
|
|
|
|
|
|
|
spendableCoins := bk.SpendableCoins(sdkCtx, proposer.Address)
|
|
|
|
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgWithdrawProposal, "fee error"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := group.MsgWithdrawProposal{
|
|
|
|
ProposalId: uint64(proposalID),
|
|
|
|
Address: proposer.Address.String(),
|
|
|
|
}
|
|
|
|
|
|
|
|
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
2022-04-20 08:27:19 -07:00
|
|
|
tx, err := helpers.GenSignedMockTx(
|
2022-02-04 00:37:45 -08:00
|
|
|
txGen,
|
|
|
|
[]sdk.Msg{&msg},
|
|
|
|
fees,
|
|
|
|
helpers.DefaultGenTxGas,
|
|
|
|
chainID,
|
|
|
|
[]uint64{proposerAcc.GetAccountNumber()},
|
|
|
|
[]uint64{proposerAcc.GetSequence()},
|
|
|
|
proposer.PrivKey,
|
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyMetadata, "unable to generate mock tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _, err = app.SimDeliver(txGen.TxEncoder(), tx)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if strings.Contains(err.Error(), "group was modified") || strings.Contains(err.Error(), "group policy was modified") {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "no-op:group/group-policy was modified"), nil, nil
|
|
|
|
}
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-21 02:52:26 -08:00
|
|
|
// SimulateMsgVote generates a MsgVote with random values
|
|
|
|
func SimulateMsgVote(ak group.AccountKeeper,
|
|
|
|
bk group.BankKeeper, k keeper.Keeper) simtypes.Operation {
|
|
|
|
return func(
|
|
|
|
r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
|
|
|
g, groupPolicy, _, _, err := randomGroupPolicy(r, k, ak, sdkCtx, accounts)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgVote, ""), nil, err
|
|
|
|
}
|
|
|
|
if g == nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgVote, "no group found"), nil, nil
|
|
|
|
}
|
|
|
|
if groupPolicy == nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgVote, "no group policy found"), nil, nil
|
|
|
|
}
|
|
|
|
groupPolicyAddr := groupPolicy.Address
|
|
|
|
|
|
|
|
// Pick a random member from the group
|
|
|
|
ctx := sdk.WrapSDKContext(sdkCtx)
|
2022-02-14 05:48:17 -08:00
|
|
|
acc, account, err := randomMember(r, k, ak, ctx, accounts, g.Id)
|
2022-01-21 02:52:26 -08:00
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgVote, ""), nil, err
|
|
|
|
}
|
|
|
|
if account == nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgVote, "no group member found"), nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress())
|
|
|
|
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgVote, "fee error"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
proposalsResult, err := k.ProposalsByGroupPolicy(ctx, &group.QueryProposalsByGroupPolicyRequest{Address: groupPolicyAddr})
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgVote, "fail to query group info"), nil, err
|
|
|
|
}
|
|
|
|
proposals := proposalsResult.GetProposals()
|
|
|
|
if len(proposals) == 0 {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgVote, "no proposals found"), nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
proposalID := -1
|
|
|
|
|
|
|
|
for _, p := range proposals {
|
2022-02-14 05:48:17 -08:00
|
|
|
if p.Status == group.PROPOSAL_STATUS_SUBMITTED {
|
2022-03-02 04:00:59 -08:00
|
|
|
timeout := p.VotingPeriodEnd
|
2022-02-14 05:48:17 -08:00
|
|
|
proposalID = int(p.Id)
|
2022-01-21 02:52:26 -08:00
|
|
|
if timeout.Before(sdkCtx.BlockTime()) || timeout.Equal(sdkCtx.BlockTime()) {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgVote, "voting period ended: skipping"), nil, nil
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// return no-op if no proposal found
|
|
|
|
if proposalID == -1 {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgVote, "no proposals found"), nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure member hasn't already voted
|
|
|
|
res, _ := k.VoteByProposalVoter(ctx, &group.QueryVoteByProposalVoterRequest{
|
|
|
|
Voter: acc.Address.String(),
|
|
|
|
ProposalId: uint64(proposalID),
|
|
|
|
})
|
|
|
|
if res != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgVote, "member has already voted"), nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := group.MsgVote{
|
|
|
|
ProposalId: uint64(proposalID),
|
|
|
|
Voter: acc.Address.String(),
|
2022-02-14 05:48:17 -08:00
|
|
|
Option: group.VOTE_OPTION_YES,
|
2022-03-01 00:35:37 -08:00
|
|
|
Metadata: simtypes.RandStringOfLength(r, 10),
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
2022-04-20 08:27:19 -07:00
|
|
|
tx, err := helpers.GenSignedMockTx(
|
2022-01-21 02:52:26 -08:00
|
|
|
txGen,
|
|
|
|
[]sdk.Msg{&msg},
|
|
|
|
fees,
|
|
|
|
helpers.DefaultGenTxGas,
|
|
|
|
chainID,
|
|
|
|
[]uint64{account.GetAccountNumber()},
|
|
|
|
[]uint64{account.GetSequence()},
|
|
|
|
acc.PrivKey,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyMetadata, "unable to generate mock tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _, err = app.SimDeliver(txGen.TxEncoder(), tx)
|
|
|
|
|
|
|
|
if err != nil {
|
2022-02-04 00:37:45 -08:00
|
|
|
if strings.Contains(err.Error(), "group was modified") || strings.Contains(err.Error(), "group policy was modified") {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "no-op:group/group-policy was modified"), nil, nil
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// // SimulateMsgExec generates a MsgExec with random values
|
|
|
|
func SimulateMsgExec(ak group.AccountKeeper,
|
|
|
|
bk group.BankKeeper, k keeper.Keeper) simtypes.Operation {
|
|
|
|
return func(
|
|
|
|
r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
|
|
|
_, groupPolicy, acc, account, err := randomGroupPolicy(r, k, ak, sdkCtx, accounts)
|
|
|
|
if err != nil {
|
2022-03-02 04:00:59 -08:00
|
|
|
return simtypes.NoOpMsg(TypeMsgExec, TypeMsgExec, ""), nil, err
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
if groupPolicy == nil {
|
2022-03-02 04:00:59 -08:00
|
|
|
return simtypes.NoOpMsg(TypeMsgExec, TypeMsgExec, "no group policy found"), nil, nil
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
groupPolicyAddr := groupPolicy.Address
|
|
|
|
|
|
|
|
spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress())
|
|
|
|
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
|
|
|
|
if err != nil {
|
2022-03-02 04:00:59 -08:00
|
|
|
return simtypes.NoOpMsg(TypeMsgExec, TypeMsgExec, "fee error"), nil, err
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx := sdk.WrapSDKContext(sdkCtx)
|
|
|
|
proposalsResult, err := k.ProposalsByGroupPolicy(ctx, &group.QueryProposalsByGroupPolicyRequest{Address: groupPolicyAddr})
|
|
|
|
if err != nil {
|
2022-03-02 04:00:59 -08:00
|
|
|
return simtypes.NoOpMsg(TypeMsgExec, TypeMsgExec, "fail to query group info"), nil, err
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
proposals := proposalsResult.GetProposals()
|
|
|
|
if len(proposals) == 0 {
|
2022-03-02 04:00:59 -08:00
|
|
|
return simtypes.NoOpMsg(TypeMsgExec, TypeMsgExec, "no proposals found"), nil, nil
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
proposalID := -1
|
|
|
|
|
|
|
|
for _, proposal := range proposals {
|
2022-04-06 04:16:23 -07:00
|
|
|
if proposal.Status == group.PROPOSAL_STATUS_ACCEPTED {
|
2022-02-14 05:48:17 -08:00
|
|
|
proposalID = int(proposal.Id)
|
2022-01-21 02:52:26 -08:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// return no-op if no proposal found
|
|
|
|
if proposalID == -1 {
|
2022-03-02 04:00:59 -08:00
|
|
|
return simtypes.NoOpMsg(TypeMsgExec, TypeMsgExec, "no proposals found"), nil, nil
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
msg := group.MsgExec{
|
|
|
|
ProposalId: uint64(proposalID),
|
2022-04-06 04:16:23 -07:00
|
|
|
Executor: acc.Address.String(),
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
2022-04-20 08:27:19 -07:00
|
|
|
tx, err := helpers.GenSignedMockTx(
|
2022-01-21 02:52:26 -08:00
|
|
|
txGen,
|
|
|
|
[]sdk.Msg{&msg},
|
|
|
|
fees,
|
|
|
|
helpers.DefaultGenTxGas,
|
|
|
|
chainID,
|
|
|
|
[]uint64{account.GetAccountNumber()},
|
|
|
|
[]uint64{account.GetSequence()},
|
|
|
|
acc.PrivKey,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyMetadata, "unable to generate mock tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _, err = app.SimDeliver(txGen.TxEncoder(), tx)
|
|
|
|
if err != nil {
|
2022-02-04 00:37:45 -08:00
|
|
|
if strings.Contains(err.Error(), "group was modified") || strings.Contains(err.Error(), "group policy was modified") {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "no-op:group/group-policy was modified"), nil, nil
|
2022-01-21 02:52:26 -08:00
|
|
|
}
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-04 06:03:31 -08:00
|
|
|
// SimulateMsgLeaveGroup generates a MsgLeaveGroup with random values
|
|
|
|
func SimulateMsgLeaveGroup(k keeper.Keeper, ak group.AccountKeeper, bk group.BankKeeper) simtypes.Operation {
|
|
|
|
return func(
|
|
|
|
r *rand.Rand, app *baseapp.BaseApp, sdkCtx sdk.Context, accounts []simtypes.Account, chainID string) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
|
|
|
|
|
|
|
ctx := sdk.WrapSDKContext(sdkCtx)
|
|
|
|
groupInfo, policyInfo, _, _, err := randomGroupPolicy(r, k, ak, sdkCtx, accounts)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgLeaveGroup, ""), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if policyInfo == nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgLeaveGroup, "no policy found"), nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pick a random member from the group
|
|
|
|
acc, account, err := randomMember(r, k, ak, ctx, accounts, groupInfo.Id)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgLeaveGroup, ""), nil, err
|
|
|
|
}
|
|
|
|
if account == nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgLeaveGroup, "no group member found"), nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
spendableCoins := bk.SpendableCoins(sdkCtx, acc.Address)
|
|
|
|
fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgLeaveGroup, "fee error"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := &group.MsgLeaveGroup{
|
|
|
|
Address: acc.Address.String(),
|
|
|
|
GroupId: groupInfo.Id,
|
|
|
|
}
|
|
|
|
|
|
|
|
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
2022-04-20 08:27:19 -07:00
|
|
|
tx, err := helpers.GenSignedMockTx(
|
2022-03-04 06:03:31 -08:00
|
|
|
txGen,
|
|
|
|
[]sdk.Msg{msg},
|
|
|
|
fees,
|
|
|
|
helpers.DefaultGenTxGas,
|
|
|
|
chainID,
|
|
|
|
[]uint64{account.GetAccountNumber()},
|
|
|
|
[]uint64{account.GetSequence()},
|
|
|
|
acc.PrivKey,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, TypeMsgLeaveGroup, "unable to generate mock tx"), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _, err = app.SimDeliver(txGen.TxEncoder(), tx)
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.NoOpMsg(group.ModuleName, msg.Type(), err.Error()), nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return simtypes.NewOperationMsg(msg, true, "", nil), nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-21 02:52:26 -08:00
|
|
|
func randomGroup(r *rand.Rand, k keeper.Keeper, ak group.AccountKeeper,
|
|
|
|
ctx sdk.Context, accounts []simtypes.Account) (groupInfo *group.GroupInfo, acc simtypes.Account, account authtypes.AccountI, err error) {
|
|
|
|
groupID := k.GetGroupSequence(ctx)
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case groupID > initialGroupID:
|
|
|
|
// select a random ID between [initialGroupID, groupID]
|
|
|
|
groupID = uint64(simtypes.RandIntBetween(r, int(initialGroupID), int(groupID)))
|
|
|
|
|
|
|
|
default:
|
|
|
|
// This is called on the first call to this function
|
|
|
|
// in order to update the global variable
|
|
|
|
initialGroupID = groupID
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := k.GroupInfo(sdk.WrapSDKContext(ctx), &group.QueryGroupInfoRequest{GroupId: groupID})
|
|
|
|
if err != nil {
|
|
|
|
return nil, simtypes.Account{}, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
groupInfo = res.Info
|
|
|
|
groupAdmin := groupInfo.Admin
|
|
|
|
found := -1
|
|
|
|
for i := range accounts {
|
|
|
|
if accounts[i].Address.String() == groupAdmin {
|
|
|
|
found = i
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if found < 0 {
|
|
|
|
return nil, simtypes.Account{}, nil, nil
|
|
|
|
}
|
|
|
|
acc = accounts[found]
|
|
|
|
account = ak.GetAccount(ctx, acc.Address)
|
|
|
|
return groupInfo, acc, account, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func randomGroupPolicy(r *rand.Rand, k keeper.Keeper, ak group.AccountKeeper,
|
|
|
|
ctx sdk.Context, accounts []simtypes.Account) (groupInfo *group.GroupInfo, groupPolicyInfo *group.GroupPolicyInfo, acc simtypes.Account, account authtypes.AccountI, err error) {
|
|
|
|
groupInfo, _, _, err = randomGroup(r, k, ak, ctx, accounts)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, simtypes.Account{}, nil, err
|
|
|
|
}
|
|
|
|
if groupInfo == nil {
|
|
|
|
return nil, nil, simtypes.Account{}, nil, nil
|
|
|
|
}
|
2022-02-14 05:48:17 -08:00
|
|
|
groupID := groupInfo.Id
|
2022-01-21 02:52:26 -08:00
|
|
|
|
|
|
|
result, err := k.GroupPoliciesByGroup(sdk.WrapSDKContext(ctx), &group.QueryGroupPoliciesByGroupRequest{GroupId: groupID})
|
|
|
|
if err != nil {
|
|
|
|
return groupInfo, nil, simtypes.Account{}, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
n := randIntInRange(r, len(result.GroupPolicies))
|
|
|
|
if n < 0 {
|
|
|
|
return groupInfo, nil, simtypes.Account{}, nil, nil
|
|
|
|
}
|
|
|
|
groupPolicyInfo = result.GroupPolicies[n]
|
|
|
|
|
|
|
|
idx := findAccount(accounts, groupPolicyInfo.Admin)
|
|
|
|
if idx < 0 {
|
|
|
|
return groupInfo, nil, simtypes.Account{}, nil, nil
|
|
|
|
}
|
|
|
|
acc = accounts[idx]
|
|
|
|
account = ak.GetAccount(ctx, acc.Address)
|
|
|
|
return groupInfo, groupPolicyInfo, acc, account, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func randomMember(r *rand.Rand, k keeper.Keeper, ak group.AccountKeeper,
|
|
|
|
ctx context.Context, accounts []simtypes.Account, groupID uint64) (acc simtypes.Account, account authtypes.AccountI, err error) {
|
|
|
|
res, err := k.GroupMembers(ctx, &group.QueryGroupMembersRequest{
|
|
|
|
GroupId: groupID,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return simtypes.Account{}, nil, err
|
|
|
|
}
|
|
|
|
n := randIntInRange(r, len(res.Members))
|
|
|
|
if n < 0 {
|
|
|
|
return simtypes.Account{}, nil, err
|
|
|
|
}
|
|
|
|
idx := findAccount(accounts, res.Members[n].Member.Address)
|
|
|
|
if idx < 0 {
|
|
|
|
return simtypes.Account{}, nil, err
|
|
|
|
}
|
|
|
|
acc = accounts[idx]
|
|
|
|
account = ak.GetAccount(sdk.UnwrapSDKContext(ctx), acc.Address)
|
|
|
|
return acc, account, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func randIntInRange(r *rand.Rand, l int) int {
|
|
|
|
if l == 0 {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
if l == 1 {
|
|
|
|
return 0
|
|
|
|
} else {
|
|
|
|
return simtypes.RandIntBetween(r, 0, l-1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func findAccount(accounts []simtypes.Account, addr string) (idx int) {
|
|
|
|
idx = -1
|
|
|
|
for i := range accounts {
|
|
|
|
if accounts[i].Address.String() == addr {
|
|
|
|
idx = i
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return idx
|
|
|
|
}
|
2022-02-18 05:47:04 -08:00
|
|
|
|
2022-04-29 05:01:20 -07:00
|
|
|
func genGroupMembers(r *rand.Rand, accounts []simtypes.Account) []group.MemberRequest {
|
2022-02-18 05:47:04 -08:00
|
|
|
if len(accounts) == 1 {
|
2022-04-29 05:01:20 -07:00
|
|
|
return []group.MemberRequest{
|
2022-02-18 05:47:04 -08:00
|
|
|
{
|
|
|
|
Address: accounts[0].Address.String(),
|
2022-03-04 06:03:31 -08:00
|
|
|
Weight: fmt.Sprintf("%d", simtypes.RandIntBetween(r, 1, 10)),
|
2022-03-01 00:35:37 -08:00
|
|
|
Metadata: simtypes.RandStringOfLength(r, 10),
|
2022-02-18 05:47:04 -08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
max := 5
|
|
|
|
if len(accounts) < max {
|
|
|
|
max = len(accounts)
|
|
|
|
}
|
|
|
|
|
|
|
|
membersLen := simtypes.RandIntBetween(r, 1, max)
|
2022-04-29 05:01:20 -07:00
|
|
|
members := make([]group.MemberRequest, membersLen)
|
2022-02-18 05:47:04 -08:00
|
|
|
|
|
|
|
for i := 0; i < membersLen; i++ {
|
2022-04-29 05:01:20 -07:00
|
|
|
members[i] = group.MemberRequest{
|
2022-02-18 05:47:04 -08:00
|
|
|
Address: accounts[i].Address.String(),
|
2022-03-04 06:03:31 -08:00
|
|
|
Weight: fmt.Sprintf("%d", simtypes.RandIntBetween(r, 1, 10)),
|
2022-03-01 00:35:37 -08:00
|
|
|
Metadata: simtypes.RandStringOfLength(r, 10),
|
2022-02-18 05:47:04 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return members
|
|
|
|
}
|