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

feat(campaign): add simulation for MsgUpdateSpecialAllocations #817

Merged
merged 5 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
72 changes: 42 additions & 30 deletions x/campaign/module_simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,29 @@ import (
)

const (
defaultWeightMsgCreateCampaign = 25
defaultWeightMsgEditCampaign = 20
defaultWeightMsgUpdateTotalSupply = 20
defaultWeightMsgInitializeMainnet = 15
defaultWeightMsgAddShares = 20
defaultWeightMsgAddVestingOptions = 20
defaultWeightMsgMintVouchers = 20
defaultWeightMsgBurnVouchers = 20
defaultWeightMsgRedeemVouchers = 20
defaultWeightMsgUnredeemVouchers = 20
defaultWeightMsgCreateCampaign = 25
defaultWeightMsgEditCampaign = 20
defaultWeightMsgUpdateTotalSupply = 20
defaultWeightMsgInitializeMainnet = 15
defaultWeightMsgUpdateSpecialAllocations = 20
defaultWeightMsgAddShares = 20
defaultWeightMsgAddVestingOptions = 20
defaultWeightMsgMintVouchers = 20
defaultWeightMsgBurnVouchers = 20
defaultWeightMsgRedeemVouchers = 20
defaultWeightMsgUnredeemVouchers = 20

opWeightMsgCreateCampaign = "op_weight_msg_create_campaign"
opWeightMsgEditCampaign = "op_weight_msg_edit_campaign"
opWeightMsgUpdateTotalSupply = "op_weight_msg_update_total_supply"
opWeightMsgInitializeMainnet = "op_weight_msg_initialize_mainnet"
opWeightMsgAddShares = "op_weight_msg_add_shares"
opWeightMsgAddVestingOptions = "op_weight_msg_add_vesting_options"
opWeightMsgMintVouchers = "op_weight_msg_mint_vouchers"
opWeightMsgBurnVouchers = "op_weight_msg_burn_vouchers"
opWeightMsgRedeemVouchers = "op_weight_msg_redeem_vouchers"
opWeightMsgUnredeemVouchers = "op_weight_msg_unredeem_vouchers"
opWeightMsgCreateCampaign = "op_weight_msg_create_campaign"
opWeightMsgEditCampaign = "op_weight_msg_edit_campaign"
opWeightMsgUpdateTotalSupply = "op_weight_msg_update_total_supply"
opWeightMsgInitializeMainnet = "op_weight_msg_initialize_mainnet"
opWeightMsgUpdateSpecialAllocations = "op_weight_msg_update_special_allocations"
opWeightMsgAddShares = "op_weight_msg_add_shares"
opWeightMsgAddVestingOptions = "op_weight_msg_add_vesting_options"
opWeightMsgMintVouchers = "op_weight_msg_mint_vouchers"
opWeightMsgBurnVouchers = "op_weight_msg_burn_vouchers"
opWeightMsgRedeemVouchers = "op_weight_msg_redeem_vouchers"
opWeightMsgUnredeemVouchers = "op_weight_msg_unredeem_vouchers"

// this line is used by starport scaffolding # simapp/module/const
)
Expand Down Expand Up @@ -69,16 +71,17 @@ func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {}
// WeightedOperations returns the all the gov module operations with their respective weights.
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
var (
weightMsgCreateCampaign int
weightMsgEditCampaign int
weightMsgUpdateTotalSupply int
weightMsgInitializeMainnet int
weightMsgAddShares int
weightMsgAddVestingOptions int
weightMsgMintVouchers int
weightMsgBurnVouchers int
weightMsgRedeemVouchers int
weightMsgUnredeemVouchers int
weightMsgCreateCampaign int
weightMsgEditCampaign int
weightMsgUpdateTotalSupply int
weightMsgInitializeMainnet int
weightMsgUpdateSpecialAllocations int
weightMsgAddShares int
weightMsgAddVestingOptions int
weightMsgMintVouchers int
weightMsgBurnVouchers int
weightMsgRedeemVouchers int
weightMsgUnredeemVouchers int
)

appParams := simState.AppParams
Expand All @@ -103,6 +106,11 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp
weightMsgInitializeMainnet = defaultWeightMsgInitializeMainnet
},
)
appParams.GetOrGenerate(cdc, opWeightMsgUpdateSpecialAllocations, &weightMsgUpdateSpecialAllocations, nil,
func(_ *rand.Rand) {
weightMsgInitializeMainnet = defaultWeightMsgUpdateSpecialAllocations
},
)
appParams.GetOrGenerate(cdc, opWeightMsgAddShares, &weightMsgAddShares, nil,
func(_ *rand.Rand) {
weightMsgAddShares = defaultWeightMsgAddShares
Expand Down Expand Up @@ -155,6 +163,10 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp
weightMsgAddShares,
campaignsim.SimulateMsgAddShares(am.accountKeeper, am.bankKeeper, am.profileKeeper, am.keeper),
),
simulation.NewWeightedOperation(
weightMsgAddShares,
campaignsim.SimulateMsgUpdateSpecialAllocations(am.accountKeeper, am.bankKeeper, am.profileKeeper, am.keeper),
),
simulation.NewWeightedOperation(
weightMsgMintVouchers,
campaignsim.SimulateMsgMintVouchers(am.accountKeeper, am.bankKeeper, am.profileKeeper, am.keeper),
Expand Down
43 changes: 43 additions & 0 deletions x/campaign/simulation/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,49 @@ func SimulateMsgInitializeMainnet(
}
}

// SimulateMsgUpdateSpecialAllocations simulates a MsgUpdateSpecialAllocations message
func SimulateMsgUpdateSpecialAllocations(ak types.AccountKeeper,
bk types.BankKeeper,
pk types.ProfileKeeper,
k keeper.Keeper,
) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
simAccount, campID, found := GetCoordSimAccountWithCampaignID(r, ctx, pk, k, accs, false, true)
if !found {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUpdateSpecialAllocations, "skip update special allocations"), nil, nil
}

// get shares for both genesis distribution and claimable airdrop
genesisDistribution, getShares := GetSharesFromCampaign(r, ctx, k, campID)
if !getShares {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUpdateSpecialAllocations, "skip update special allocations"), nil, nil
}
claimableAirdrop, getShares := GetSharesFromCampaign(r, ctx, k, campID)
if !getShares {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUpdateSpecialAllocations, "skip update special allocations"), nil, nil
}

// GetSharesFromCampaign returns a number of available shares for a campaign
// potentially genesisDistribution + claimableAirdrop can overflow the available shares
// we divide by two all amounts to avoid overflowing available shares
for i, s := range genesisDistribution {
genesisDistribution[i].Amount = s.Amount.QuoRaw(2)
}
for i, s := range claimableAirdrop {
claimableAirdrop[i].Amount = s.Amount.QuoRaw(2)
}

msg := types.NewMsgUpdateSpecialAllocations(
simAccount.Address.String(),
campID,
types.NewSpecialAllocations(genesisDistribution, claimableAirdrop),
)
return deliverSimTx(r, app, ctx, ak, bk, simAccount, msg, sdk.NewCoins())
}
}

// SimulateMsgAddShares simulates a MsgAddShares message
func SimulateMsgAddShares(
ak types.AccountKeeper,
Expand Down