-
Notifications
You must be signed in to change notification settings - Fork 0
/
proposals.go
52 lines (44 loc) · 1.83 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
52
package simulation
import (
"math/rand"
simappparams "github.com/evoblockchain/evochain/libs/cosmos-sdk/simapp/params"
sdk "github.com/evoblockchain/evochain/libs/cosmos-sdk/types"
"github.com/evoblockchain/evochain/libs/cosmos-sdk/x/distribution/keeper"
"github.com/evoblockchain/evochain/libs/cosmos-sdk/x/distribution/types"
govtypes "github.com/evoblockchain/evochain/libs/cosmos-sdk/x/gov/types"
"github.com/evoblockchain/evochain/libs/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) []simulation.WeightedProposalContent {
return []simulation.WeightedProposalContent{
{
AppParamsKey: OpWeightSubmitCommunitySpendProposal,
DefaultWeight: simappparams.DefaultWeightCommunitySpendProposal,
ContentSimulatorFn: SimulateCommunityPoolSpendProposalContent(k),
},
}
}
// SimulateCommunityPoolSpendProposalContent generates random community-pool-spend proposal content
// nolint: funlen
func SimulateCommunityPoolSpendProposalContent(k keeper.Keeper) simulation.ContentSimulatorFn {
return func(r *rand.Rand, ctx sdk.Context, accs []simulation.Account) govtypes.Content {
simAccount, _ := simulation.RandomAcc(r, accs)
balance := k.GetFeePool(ctx).CommunityPool
if balance.Empty() {
return nil
}
denomIndex := r.Intn(len(balance))
amount, err := simulation.RandPositiveInt(r, balance[denomIndex].Amount)
if err != nil {
return nil
}
return types.NewCommunityPoolSpendProposal(
simulation.RandStringOfLength(r, 10),
simulation.RandStringOfLength(r, 100),
simAccount.Address,
sdk.NewCoins(sdk.NewCoin(balance[denomIndex].Denom, amount)),
)
}
}