Skip to content

Commit

Permalink
feat: adding public plan proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
jaybxyz committed Sep 6, 2021
1 parent a7d3e70 commit 9fcb8e3
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 17 deletions.
39 changes: 39 additions & 0 deletions x/farming/simulation/operations.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package simulation

import (
"fmt"
"math/rand"

"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -357,6 +358,44 @@ func SimulateMsgHarvest(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Ke
}
}

// SimulateMsgSubmitFixedAmountPlanProposal simulates creating a msg CreateFixedAmountPlan Proposal
// voting on the proposal, and subsequently slashing the proposal. It is implemented using
// future operations.
func SimulateMsgSubmitFixedAmountPlanProposal(
ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, contentSim simtypes.ContentSimulatorFn,
) simtypes.Operation {
// The states are:
// column 1: All validators vote
// column 2: 90% vote
// column 3: 75% vote
// column 4: 40% vote
// column 5: 15% vote
// column 6: noone votes
// All columns sum to 100 for simplicity, values chosen by @valardragon semi-arbitrarily,
// feel free to change.
numVotesTransitionMatrix, _ := simulation.CreateTransitionMatrix([][]int{
{20, 10, 0, 0, 0, 0},
{55, 50, 20, 10, 0, 0},
{25, 25, 30, 25, 30, 15},
{0, 15, 30, 25, 30, 30},
{0, 0, 20, 30, 30, 30},
{0, 0, 0, 10, 10, 25},
})

statePercentageArray := []float64{1, .9, .75, .4, .15, 0}
curNumVotesState := 1

return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context,
accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
fmt.Println("numVotesTransitionMatrix: ", numVotesTransitionMatrix)
fmt.Println("statePercentageArray: ", statePercentageArray)
fmt.Println("curNumVotesState: ", curNumVotesState)
return simtypes.OperationMsg{}, nil, nil
}
}

// mintPoolCoins mints random amount of coins with the provided pool coin denoms and
// send them to the simulated account.
func mintPoolCoins(ctx sdk.Context, r *rand.Rand, bk types.BankKeeper, acc simtypes.Account) (mintCoins sdk.Coins, err error) {
Expand Down
43 changes: 26 additions & 17 deletions x/farming/simulation/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,41 @@ package simulation
import (
"math/rand"

simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/simulation"

"github.com/tendermint/farming/x/farming/keeper"
)

// OpWeightSubmitPublicPlanProposals app params key for public plan proposals
const OpWeightSubmitPublicPlanProposals = "op_weight_submit_public_plan_proposals"
// Simulation operation weights constants.
const (
OpWeightSubmitPublicFixedAmountPlanProposal = "op_weight_submit_public_fixed_amount_plan_proposal"
OpWeightSubmitPublicRatioPlanProposal = "op_weight_submit_public_ratio_plan_proposal"
)

// ProposalContents defines the module weighted proposals' contents
func ProposalContents(k keeper.Keeper) []simtypes.WeightedProposalContent {
// TODO: not implemented yet
return nil
// return []simtypes.WeightedProposalContent{
// simulation.NewWeightedProposalContent(
// OpWeightSubmitPublicPlanProposals,
// simappparams.DefaultWeightPublicPlanProposals,
// SimulateCommunityPoolSpendProposalContent(k),
// ),
// }
return []simtypes.WeightedProposalContent{
simulation.NewWeightedProposalContent(
OpWeightSubmitPublicFixedAmountPlanProposal,
simappparams.DefaultWeightTextProposal,
SimulateTextProposalContent,
),
// simulation.NewWeightedProposalContent(
// OpWeightSubmitPublicRatioPlanProposal,
// simappparams.DefaultWeightTextProposal,
// SimulateTextProposalContent(k),
// ),
}
}

// SimulatePublicPlanProposalsProposalContent generates random public plan proposals proposal content
func SimulatePublicPlanProposalsProposalContent(k keeper.Keeper) simtypes.ContentSimulatorFn {
return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content {
// TODO: not implemented yet
return nil
}
// SimulateTextProposalContent returns a random text proposal content.
func SimulateTextProposalContent(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) simtypes.Content {
return govtypes.NewTextProposal(
simtypes.RandStringOfLength(r, 140),
simtypes.RandStringOfLength(r, 5000),
)
}

0 comments on commit 9fcb8e3

Please sign in to comment.