Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LSM simulation tests #16

Merged
merged 2 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions simapp/params/weights.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ const (
DefaultWeightMsgDelegate int = 100
DefaultWeightMsgUndelegate int = 100
DefaultWeightMsgBeginRedelegate int = 100
DefaultWeightMsgCancelUnbondingDelegation int = 100
DefaultWeightMsgTokenizeShares int = 100
DefaultWeightMsgRedeemTokensforShares int = 100
DefaultWeightMsgTransferTokenizeShareRecord int = 50
DefaultWeightMsgEnableTokenizeShares int = 100
DefaultWeightMsgDisableTokenizeShares int = 100
DefaultWeightMsgCancelUnbondingDelegation int = 5
DefaultWeightMsgValidatorBond int = 100
DefaultWeightMsgTokenizeShares int = 25
DefaultWeightMsgRedeemTokensforShares int = 25
DefaultWeightMsgTransferTokenizeShareRecord int = 5
DefaultWeightMsgEnableTokenizeShares int = 1
DefaultWeightMsgDisableTokenizeShares int = 1

DefaultWeightCommunitySpendProposal int = 5
DefaultWeightTextProposal int = 5
Expand Down
4 changes: 3 additions & 1 deletion x/staking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,9 @@ func (k msgServer) RedeemTokensForShares(goCtx context.Context, msg *types.MsgRe
_, found = k.GetDelegation(ctx, record.GetModuleAddress(), valAddr)
if !found {
if k.hooks != nil {
return nil, k.hooks.BeforeTokenizeShareRecordRemoved(ctx, record.Id)
if err := k.hooks.BeforeTokenizeShareRecordRemoved(ctx, record.Id); err != nil {
return nil, err
}
}

err = k.DeleteTokenizeShareRecord(ctx, record.Id)
Expand Down
61 changes: 46 additions & 15 deletions x/staking/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/types/simulation"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)

// Simulation parameter constants
const (
unbondingTime = "unbonding_time"
maxValidators = "max_validators"
historicalEntries = "historical_entries"
UnbondingTime = "unbonding_time"
MaxValidators = "max_validators"
HistoricalEntries = "historical_entries"
ValidatorBondFactor = "validator_bond_factor"
GlobalLiquidStakingCap = "global_liquid_staking_cap"
ValidatorLiquidStakingCap = "validator_liquid_staking_cap"
)

// genUnbondingTime returns randomized UnbondingTime
Expand All @@ -36,41 +40,68 @@ func getHistEntries(r *rand.Rand) uint32 {
return uint32(r.Intn(int(types.DefaultHistoricalEntries + 1)))
}

// getGlobalLiquidStakingCap returns randomized GlobalLiquidStakingCap between 0-1.
func getGlobalLiquidStakingCap(r *rand.Rand) sdk.Dec {
return simtypes.RandomDecAmount(r, sdk.OneDec())
}

// getValidatorLiquidStakingCap returns randomized ValidatorLiquidStakingCap between 0-1.
func getValidatorLiquidStakingCap(r *rand.Rand) sdk.Dec {
return simtypes.RandomDecAmount(r, sdk.OneDec())
}

// getValidatorBondFactor returns randomized ValidatorBondCap between -1 and 300.
func getValidatorBondFactor(r *rand.Rand) sdk.Dec {
return sdk.NewDec(int64(simtypes.RandIntBetween(r, -1, 300)))
}

// RandomizedGenState generates a random GenesisState for staking
func RandomizedGenState(simState *module.SimulationState) {
// params
var (
unbondTime time.Duration
maxVals uint32
histEntries uint32
unbondingTime time.Duration
maxValidators uint32
historicalEntries uint32
validatorBondFactor sdk.Dec
globalLiquidStakingCap sdk.Dec
validatorLiquidStakingCap sdk.Dec
)

simState.AppParams.GetOrGenerate(
simState.Cdc, unbondingTime, &unbondTime, simState.Rand,
func(r *rand.Rand) { unbondTime = genUnbondingTime(r) },
simState.Cdc, UnbondingTime, &unbondingTime, simState.Rand,
func(r *rand.Rand) { unbondingTime = genUnbondingTime(r) },
)

simState.AppParams.GetOrGenerate(
simState.Cdc, maxValidators, &maxVals, simState.Rand,
func(r *rand.Rand) { maxVals = genMaxValidators(r) },
simState.Cdc, MaxValidators, &maxValidators, simState.Rand,
func(r *rand.Rand) { maxValidators = genMaxValidators(r) },
)

simState.AppParams.GetOrGenerate(
simState.Cdc, historicalEntries, &histEntries, simState.Rand,
func(r *rand.Rand) { histEntries = getHistEntries(r) },
simState.Cdc, HistoricalEntries, &historicalEntries, simState.Rand,
func(r *rand.Rand) { historicalEntries = getHistEntries(r) },
)
simState.AppParams.GetOrGenerate(
simState.Cdc, ValidatorBondFactor, &validatorBondFactor, simState.Rand,
func(r *rand.Rand) { validatorBondFactor = getValidatorBondFactor(r) },
)
simState.AppParams.GetOrGenerate(
simState.Cdc, GlobalLiquidStakingCap, &globalLiquidStakingCap, simState.Rand,
func(r *rand.Rand) { globalLiquidStakingCap = getGlobalLiquidStakingCap(r) },
)
simState.AppParams.GetOrGenerate(
simState.Cdc, ValidatorLiquidStakingCap, &validatorLiquidStakingCap, simState.Rand,
func(r *rand.Rand) { validatorLiquidStakingCap = getValidatorLiquidStakingCap(r) },
)

// NOTE: the slashing module need to be defined after the staking module on the
// NewSimulationManager constructor for this to work
simState.UnbondTime = unbondTime
simState.UnbondTime = unbondingTime
params := types.NewParams(
simState.UnbondTime,
maxVals,
maxValidators,
7,
histEntries,
historicalEntries,
sdk.DefaultBondDenom,
validatorBondFactor,
globalLiquidStakingCap,
Expand Down
Loading