forked from cosmos/cosmos-sdk
/
proposals.go
51 lines (43 loc) · 1.67 KB
/
proposals.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package simulation
import (
"math/rand"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/distribution/keeper"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/x/simulation"
)
// OpWeightSubmitCommunitySpendProposal app params key for community spend proposal
const OpWeightSubmitCommunitySpendProposal = "op_weight_submit_community_spend_proposal"
// ProposalContents defines the module weighted proposals' contents
func ProposalContents(k keeper.Keeper) []simtypes.WeightedProposalContent {
return []simtypes.WeightedProposalContent{
simulation.NewWeightedProposalContent(
OpWeightSubmitCommunitySpendProposal,
simtestutil.DefaultWeightCommunitySpendProposal,
SimulateCommunityPoolSpendProposalContent(k),
),
}
}
// SimulateCommunityPoolSpendProposalContent generates random community-pool-spend proposal content
func SimulateCommunityPoolSpendProposalContent(k keeper.Keeper) simtypes.ContentSimulatorFn {
return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content {
simAccount, _ := simtypes.RandomAcc(r, accs)
balance := k.GetFeePool(ctx).CommunityPool
if balance.Empty() {
return nil
}
denomIndex := r.Intn(len(balance))
amount, err := simtypes.RandPositiveInt(r, balance[denomIndex].Amount.TruncateInt())
if err != nil {
return nil
}
return types.NewCommunityPoolSpendProposal(
simtypes.RandStringOfLength(r, 10),
simtypes.RandStringOfLength(r, 100),
simAccount.Address,
sdk.NewCoins(sdk.NewCoin(balance[denomIndex].Denom, amount)),
)
}
}