-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
102 additions
and
1,073 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,88 @@ | ||
package simulation | ||
|
||
// | ||
//import ( | ||
// "math/rand" | ||
// "time" | ||
// | ||
// sdk "github.com/cosmos/cosmos-sdk/types" | ||
// "github.com/cosmos/cosmos-sdk/types/module" | ||
// sim "github.com/cosmos/cosmos-sdk/types/simulation" | ||
// govTypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
// govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" | ||
// stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
// | ||
// typesv1 "github.com/shentufoundation/shentu/v2/x/gov/types/v1" | ||
//) | ||
// | ||
//// RandomizedGenState creates a randomGenesis state for module simulation. | ||
//func RandomizedGenState(simState *module.SimulationState) { | ||
// r := simState.Rand | ||
// gs := typesv1.GenesisState{} | ||
// gs.StartingProposalId = uint64(simState.Rand.Intn(100)) | ||
// | ||
// a := GenerateADepositParams(r) | ||
// gs.DepositParams = &a | ||
// b := GenerateAVotingParams(r) | ||
// gs.VotingParams = &b | ||
// tallyParams := GenerateTallyParams(r) | ||
// gs.TallyParams = &tallyParams | ||
// gs.CustomParams = &typesv1.CustomParams{ | ||
// CertifierUpdateSecurityVoteTally: &tallyParams, | ||
// CertifierUpdateStakeVoteTally: &tallyParams, | ||
// } | ||
// | ||
// // For the shield module, locking period should be shorter than unbonding period. | ||
// stakingGenStatebz := simState.GenState[stakingtypes.ModuleName] | ||
// var stakingGenState stakingtypes.GenesisState | ||
// simState.Cdc.MustUnmarshalJSON(stakingGenStatebz, &stakingGenState) | ||
// ubdTime := stakingGenState.Params.UnbondingTime | ||
// if *gs.VotingParams.VotingPeriod*2 >= ubdTime { | ||
// votingPeriod := time.Duration(sim.RandIntBetween(r, int(ubdTime)/10, int(ubdTime)/2)) | ||
// gs.VotingParams.VotingPeriod = &votingPeriod | ||
// } | ||
// | ||
// simState.GenState[govTypes.ModuleName] = simState.Cdc.MustMarshalJSON(&gs) | ||
//} | ||
// | ||
//// GenerateADepositParams returns a DepositParams object with all of its fields randomized. | ||
//func GenerateADepositParams(r *rand.Rand) govtypesv1.DepositParams { | ||
// minDeposit := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, int64(sim.RandIntBetween(r, 1, 10)))) | ||
// maxDepositPeriod := sim.RandIntBetween(r, 1, 2*60*60*24*2) | ||
// return govtypesv1.NewDepositParams(minDeposit, time.Duration(maxDepositPeriod)*time.Second) | ||
//} | ||
// | ||
//// GenerateAVotingParams returns a VotingParams object with all of its fields randomized. | ||
//func GenerateAVotingParams(r *rand.Rand) govtypesv1.VotingParams { | ||
// votingPeriod := sim.RandIntBetween(r, 1, 2*60*60*24*2) | ||
// return govtypesv1.NewVotingParams(time.Duration(votingPeriod) * time.Second) | ||
//} | ||
// | ||
//// GenerateTallyParams returns a TallyParams object with all of its fields randomized. | ||
//func GenerateTallyParams(r *rand.Rand) govtypesv1.TallyParams { | ||
// quorum := sdk.NewDecWithPrec(int64(sim.RandIntBetween(r, 334, 500)), 3) | ||
// threshold := sdk.NewDecWithPrec(int64(sim.RandIntBetween(r, 450, 550)), 3) | ||
// veto := sdk.NewDecWithPrec(int64(sim.RandIntBetween(r, 250, 334)), 3) | ||
// return govtypesv1.NewTallyParams(quorum, threshold, veto) | ||
//} | ||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"math/rand" | ||
"time" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
govsim "github.com/cosmos/cosmos-sdk/x/gov/simulation" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" | ||
|
||
typesv1 "github.com/shentufoundation/shentu/v2/x/gov/types/v1" | ||
) | ||
|
||
// RandomizedGenState generates a random GenesisState for gov | ||
func RandomizedGenState(simState *module.SimulationState) { | ||
startingProposalID := uint64(simState.Rand.Intn(100)) | ||
|
||
var minDeposit sdk.Coins | ||
simState.AppParams.GetOrGenerate( | ||
simState.Cdc, govsim.DepositParamsMinDeposit, &minDeposit, simState.Rand, | ||
func(r *rand.Rand) { minDeposit = govsim.GenDepositParamsMinDeposit(r) }, | ||
) | ||
|
||
var depositPeriod time.Duration | ||
simState.AppParams.GetOrGenerate( | ||
simState.Cdc, govsim.DepositParamsDepositPeriod, &depositPeriod, simState.Rand, | ||
func(r *rand.Rand) { depositPeriod = govsim.GenDepositParamsDepositPeriod(r) }, | ||
) | ||
|
||
var minInitialDepositRatio sdk.Dec | ||
simState.AppParams.GetOrGenerate( | ||
simState.Cdc, govsim.DepositMinInitialRatio, &minInitialDepositRatio, simState.Rand, | ||
func(r *rand.Rand) { minInitialDepositRatio = govsim.GenDepositMinInitialDepositRatio(r) }, | ||
) | ||
|
||
var votingPeriod time.Duration | ||
simState.AppParams.GetOrGenerate( | ||
simState.Cdc, govsim.VotingParamsVotingPeriod, &votingPeriod, simState.Rand, | ||
func(r *rand.Rand) { votingPeriod = govsim.GenVotingParamsVotingPeriod(r) }, | ||
) | ||
|
||
var quorum sdk.Dec | ||
simState.AppParams.GetOrGenerate( | ||
simState.Cdc, govsim.TallyParamsQuorum, &quorum, simState.Rand, | ||
func(r *rand.Rand) { quorum = govsim.GenTallyParamsQuorum(r) }, | ||
) | ||
|
||
var threshold sdk.Dec | ||
simState.AppParams.GetOrGenerate( | ||
simState.Cdc, govsim.TallyParamsThreshold, &threshold, simState.Rand, | ||
func(r *rand.Rand) { threshold = govsim.GenTallyParamsThreshold(r) }, | ||
) | ||
|
||
var veto sdk.Dec | ||
simState.AppParams.GetOrGenerate( | ||
simState.Cdc, govsim.TallyParamsVeto, &veto, simState.Rand, | ||
func(r *rand.Rand) { veto = govsim.GenTallyParamsVeto(r) }, | ||
) | ||
|
||
tally := &govtypesv1.TallyParams{ | ||
Quorum: quorum.String(), | ||
Threshold: threshold.String(), | ||
VetoThreshold: veto.String(), | ||
} | ||
|
||
customParam := typesv1.CustomParams{ | ||
CertifierUpdateSecurityVoteTally: tally, | ||
CertifierUpdateStakeVoteTally: tally, | ||
} | ||
|
||
govGenesis := typesv1.NewGenesisState( | ||
startingProposalID, | ||
govtypesv1.NewParams(minDeposit, depositPeriod, votingPeriod, quorum.String(), threshold.String(), veto.String(), minInitialDepositRatio.String(), simState.Rand.Intn(2) == 0, simState.Rand.Intn(2) == 0, simState.Rand.Intn(2) == 0), | ||
customParam, | ||
) | ||
|
||
bz, err := json.MarshalIndent(&govGenesis, "", " ") | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Printf("Selected randomly generated governance parameters:\n%s\n", bz) | ||
simState.GenState[govtypes.ModuleName] = simState.Cdc.MustMarshalJSON(govGenesis) | ||
} | ||
|
Oops, something went wrong.