2019-08-28 07:58:25 -07:00
|
|
|
package simulation
|
|
|
|
|
|
|
|
// DONTCOVER
|
|
|
|
|
|
|
|
import (
|
2020-08-26 02:39:38 -07:00
|
|
|
"encoding/json"
|
2019-08-28 07:58:25 -07:00
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Simulation parameter constants
|
|
|
|
const (
|
|
|
|
CommunityTax = "community_tax"
|
|
|
|
BaseProposerReward = "base_proposer_reward"
|
|
|
|
BonusProposerReward = "bonus_proposer_reward"
|
2019-10-23 02:14:45 -07:00
|
|
|
WithdrawEnabled = "withdraw_enabled"
|
2019-08-28 07:58:25 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// GenCommunityTax randomized CommunityTax
|
|
|
|
func GenCommunityTax(r *rand.Rand) sdk.Dec {
|
|
|
|
return sdk.NewDecWithPrec(1, 2).Add(sdk.NewDecWithPrec(int64(r.Intn(30)), 2))
|
|
|
|
}
|
|
|
|
|
|
|
|
// GenBaseProposerReward randomized BaseProposerReward
|
|
|
|
func GenBaseProposerReward(r *rand.Rand) sdk.Dec {
|
|
|
|
return sdk.NewDecWithPrec(1, 2).Add(sdk.NewDecWithPrec(int64(r.Intn(30)), 2))
|
|
|
|
}
|
|
|
|
|
|
|
|
// GenBonusProposerReward randomized BonusProposerReward
|
|
|
|
func GenBonusProposerReward(r *rand.Rand) sdk.Dec {
|
|
|
|
return sdk.NewDecWithPrec(1, 2).Add(sdk.NewDecWithPrec(int64(r.Intn(30)), 2))
|
|
|
|
}
|
|
|
|
|
2019-10-23 02:14:45 -07:00
|
|
|
// GenWithdrawEnabled returns a randomized WithdrawEnabled parameter.
|
|
|
|
func GenWithdrawEnabled(r *rand.Rand) bool {
|
|
|
|
return r.Int63n(101) <= 95 // 95% chance of withdraws being enabled
|
|
|
|
}
|
|
|
|
|
2019-08-28 07:58:25 -07:00
|
|
|
// RandomizedGenState generates a random GenesisState for distribution
|
|
|
|
func RandomizedGenState(simState *module.SimulationState) {
|
|
|
|
var communityTax sdk.Dec
|
|
|
|
simState.AppParams.GetOrGenerate(
|
|
|
|
simState.Cdc, CommunityTax, &communityTax, simState.Rand,
|
|
|
|
func(r *rand.Rand) { communityTax = GenCommunityTax(r) },
|
|
|
|
)
|
|
|
|
|
|
|
|
var baseProposerReward sdk.Dec
|
|
|
|
simState.AppParams.GetOrGenerate(
|
|
|
|
simState.Cdc, BaseProposerReward, &baseProposerReward, simState.Rand,
|
|
|
|
func(r *rand.Rand) { baseProposerReward = GenBaseProposerReward(r) },
|
|
|
|
)
|
|
|
|
|
|
|
|
var bonusProposerReward sdk.Dec
|
|
|
|
simState.AppParams.GetOrGenerate(
|
|
|
|
simState.Cdc, BonusProposerReward, &bonusProposerReward, simState.Rand,
|
|
|
|
func(r *rand.Rand) { bonusProposerReward = GenBonusProposerReward(r) },
|
|
|
|
)
|
|
|
|
|
2019-10-23 02:14:45 -07:00
|
|
|
var withdrawEnabled bool
|
|
|
|
simState.AppParams.GetOrGenerate(
|
|
|
|
simState.Cdc, WithdrawEnabled, &withdrawEnabled, simState.Rand,
|
|
|
|
func(r *rand.Rand) { withdrawEnabled = GenWithdrawEnabled(r) },
|
|
|
|
)
|
|
|
|
|
2019-08-28 07:58:25 -07:00
|
|
|
distrGenesis := types.GenesisState{
|
2020-01-10 12:08:14 -08:00
|
|
|
FeePool: types.InitialFeePool(),
|
|
|
|
Params: types.Params{
|
|
|
|
CommunityTax: communityTax,
|
|
|
|
BaseProposerReward: baseProposerReward,
|
|
|
|
BonusProposerReward: bonusProposerReward,
|
|
|
|
WithdrawAddrEnabled: withdrawEnabled,
|
|
|
|
},
|
2019-08-28 07:58:25 -07:00
|
|
|
}
|
|
|
|
|
2020-08-26 02:39:38 -07:00
|
|
|
bz, err := json.MarshalIndent(&distrGenesis, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
fmt.Printf("Selected randomly generated distribution parameters:\n%s\n", bz)
|
2020-08-13 06:20:02 -07:00
|
|
|
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&distrGenesis)
|
2019-08-28 07:58:25 -07:00
|
|
|
}
|