mirror of https://github.com/certusone/wasmd.git
Add gov proposal simulations (#1107)
* Add weights * Add helper functions to create new proposals * Add MigrateContractProposal simulation * Add SudoContractProposal simulation * Add PinContractProposal simulation * Add UnpinContractProposal simulation * Add UpdateInstantiateConfigProposal simulation * Add StoreAndInstantiateContractProposal simulation * Comment out failing simulations * Fix comments
This commit is contained in:
parent
299d4223af
commit
c5abd338e3
|
@ -28,9 +28,15 @@ const (
|
|||
DefaultWeightMsgClearAdmin int = 10
|
||||
DefaultWeightMsgMigrateContract int = 50
|
||||
|
||||
DefaultWeightStoreCodeProposal int = 5
|
||||
DefaultWeightInstantiateContractProposal int = 5
|
||||
DefaultWeightUpdateAdminProposal int = 5
|
||||
DefaultWeightExecuteContractProposal int = 5
|
||||
DefaultWeightClearAdminProposal int = 5
|
||||
DefaultWeightStoreCodeProposal int = 5
|
||||
DefaultWeightInstantiateContractProposal int = 5
|
||||
DefaultWeightUpdateAdminProposal int = 5
|
||||
DefaultWeightExecuteContractProposal int = 5
|
||||
DefaultWeightClearAdminProposal int = 5
|
||||
DefaultWeightMigrateContractProposal int = 5
|
||||
DefaultWeightSudoContractProposal int = 5
|
||||
DefaultWeightPinCodesProposal int = 5
|
||||
DefaultWeightUnpinCodesProposal int = 5
|
||||
DefaultWeightUpdateInstantiateConfigProposal int = 5
|
||||
DefaultWeightStoreAndInstantiateContractProposal int = 5
|
||||
)
|
||||
|
|
|
@ -13,11 +13,17 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
WeightStoreCodeProposal = "weight_store_code_proposal"
|
||||
WeightInstantiateContractProposal = "weight_instantiate_contract_proposal"
|
||||
WeightUpdateAdminProposal = "weight_update_admin_proposal"
|
||||
WeightExeContractProposal = "weight_execute_contract_proposal"
|
||||
WeightClearAdminProposal = "weight_clear_admin_proposal"
|
||||
WeightStoreCodeProposal = "weight_store_code_proposal"
|
||||
WeightInstantiateContractProposal = "weight_instantiate_contract_proposal"
|
||||
WeightUpdateAdminProposal = "weight_update_admin_proposal"
|
||||
WeightExeContractProposal = "weight_execute_contract_proposal"
|
||||
WeightClearAdminProposal = "weight_clear_admin_proposal"
|
||||
WeightMigrateContractProposal = "weight_migrate_contract_proposal"
|
||||
WeightSudoContractProposal = "weight_sudo_contract_proposal"
|
||||
WeightPinCodesProposal = "weight_pin_codes_proposal"
|
||||
WeightUnpinCodesProposal = "weight_unpin_codes_proposal"
|
||||
WeightUpdateInstantiateConfigProposal = "weight_update_instantiate_config_proposal"
|
||||
WeightStoreAndInstantiateContractProposal = "weight_store_and_instantiate_contract_proposal"
|
||||
)
|
||||
|
||||
func ProposalContents(bk BankKeeper, wasmKeeper WasmKeeper) []simtypes.WeightedProposalContent {
|
||||
|
@ -60,9 +66,57 @@ func ProposalContents(bk BankKeeper, wasmKeeper WasmKeeper) []simtypes.WeightedP
|
|||
params.DefaultWeightClearAdminProposal,
|
||||
SimulateClearAdminProposal(
|
||||
wasmKeeper,
|
||||
DefaultSimulateClearAdminProposalContractSelector,
|
||||
DefaultSimulateContractSelector,
|
||||
),
|
||||
),
|
||||
simulation.NewWeightedProposalContent(
|
||||
WeightMigrateContractProposal,
|
||||
params.DefaultWeightMigrateContractProposal,
|
||||
SimulateMigrateContractProposal(
|
||||
wasmKeeper,
|
||||
DefaultSimulateContractSelector,
|
||||
DefaultSimulationCodeIDSelector,
|
||||
),
|
||||
),
|
||||
// simulation.NewWeightedProposalContent(
|
||||
// WeightSudoContractProposal,
|
||||
// params.DefaultWeightSudoContractProposal,
|
||||
// SimulateSudoContractProposal(
|
||||
// wasmKeeper,
|
||||
// DefaultSimulateContractSelector,
|
||||
// ),
|
||||
// ),
|
||||
simulation.NewWeightedProposalContent(
|
||||
WeightPinCodesProposal,
|
||||
params.DefaultWeightPinCodesProposal,
|
||||
SimulatePinContractProposal(
|
||||
wasmKeeper,
|
||||
DefaultSimulationCodeIDSelector,
|
||||
),
|
||||
),
|
||||
simulation.NewWeightedProposalContent(
|
||||
WeightUnpinCodesProposal,
|
||||
params.DefaultWeightUnpinCodesProposal,
|
||||
SimulateUnpinContractProposal(
|
||||
wasmKeeper,
|
||||
DefaultSimulationCodeIDSelector,
|
||||
),
|
||||
),
|
||||
simulation.NewWeightedProposalContent(
|
||||
WeightUpdateInstantiateConfigProposal,
|
||||
params.DefaultWeightUpdateInstantiateConfigProposal,
|
||||
SimulateUpdateInstantiateConfigProposal(
|
||||
wasmKeeper,
|
||||
DefaultSimulationCodeIDSelector,
|
||||
),
|
||||
),
|
||||
// simulation.NewWeightedProposalContent(
|
||||
// WeightStoreAndInstantiateContractProposal,
|
||||
// params.DefaultWeightStoreAndInstantiateContractProposal,
|
||||
// SimulateStoreAndInstantiateContractProposal(
|
||||
// wasmKeeper,
|
||||
// ),
|
||||
// ),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,7 +250,7 @@ func SimulateUpdateAdminProposal(wasmKeeper WasmKeeper, contractSelector UpdateA
|
|||
|
||||
type ClearAdminContractSelector func(sdk.Context, WasmKeeper) sdk.AccAddress
|
||||
|
||||
func DefaultSimulateClearAdminProposalContractSelector(
|
||||
func DefaultSimulateContractSelector(
|
||||
ctx sdk.Context,
|
||||
wasmKeeper WasmKeeper,
|
||||
) sdk.AccAddress {
|
||||
|
@ -223,3 +277,130 @@ func SimulateClearAdminProposal(wasmKeeper WasmKeeper, contractSelector ClearAdm
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
type MigrateContractProposalContractSelector func(sdk.Context, WasmKeeper) sdk.AccAddress
|
||||
|
||||
// Simulate migrate contract proposal
|
||||
func SimulateMigrateContractProposal(wasmKeeper WasmKeeper, contractSelector MigrateContractProposalContractSelector, codeSelector CodeIDSelector) simtypes.ContentSimulatorFn {
|
||||
return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content {
|
||||
ctAddress := contractSelector(ctx, wasmKeeper)
|
||||
if ctAddress == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
codeID := codeSelector(ctx, wasmKeeper)
|
||||
if codeID == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return types.NewMigrateContractProposal(
|
||||
simtypes.RandStringOfLength(r, 10),
|
||||
simtypes.RandStringOfLength(r, 10),
|
||||
ctAddress.String(),
|
||||
codeID,
|
||||
[]byte(`{}`),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
type SudoContractProposalContractSelector func(sdk.Context, WasmKeeper) sdk.AccAddress
|
||||
|
||||
// Simulate sudo contract proposal
|
||||
func SimulateSudoContractProposal(wasmKeeper WasmKeeper, contractSelector SudoContractProposalContractSelector) simtypes.ContentSimulatorFn {
|
||||
return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content {
|
||||
ctAddress := contractSelector(ctx, wasmKeeper)
|
||||
if ctAddress == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return types.NewSudoContractProposal(
|
||||
simtypes.RandStringOfLength(r, 10),
|
||||
simtypes.RandStringOfLength(r, 10),
|
||||
ctAddress.String(),
|
||||
[]byte(`{}`),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Simulate pin contract proposal
|
||||
func SimulatePinContractProposal(wasmKeeper WasmKeeper, codeSelector CodeIDSelector) simtypes.ContentSimulatorFn {
|
||||
return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content {
|
||||
codeID := codeSelector(ctx, wasmKeeper)
|
||||
if codeID == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return types.NewPinCodesProposal(
|
||||
simtypes.RandStringOfLength(r, 10),
|
||||
simtypes.RandStringOfLength(r, 10),
|
||||
[]uint64{codeID},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Simulate unpin contract proposal
|
||||
func SimulateUnpinContractProposal(wasmKeeper WasmKeeper, codeSelector CodeIDSelector) simtypes.ContentSimulatorFn {
|
||||
return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content {
|
||||
codeID := codeSelector(ctx, wasmKeeper)
|
||||
if codeID == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return types.NewUnpinCodesProposal(
|
||||
simtypes.RandStringOfLength(r, 10),
|
||||
simtypes.RandStringOfLength(r, 10),
|
||||
[]uint64{codeID},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Simulate update instantiate config proposal
|
||||
func SimulateUpdateInstantiateConfigProposal(wasmKeeper WasmKeeper, codeSelector CodeIDSelector) simtypes.ContentSimulatorFn {
|
||||
return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content {
|
||||
codeID := codeSelector(ctx, wasmKeeper)
|
||||
if codeID == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
simAccount, _ := simtypes.RandomAcc(r, accs)
|
||||
permission := wasmKeeper.GetParams(ctx).InstantiateDefaultPermission
|
||||
config := permission.With(simAccount.Address)
|
||||
|
||||
configUpdate := types.AccessConfigUpdate{
|
||||
CodeID: codeID,
|
||||
InstantiatePermission: config,
|
||||
}
|
||||
|
||||
return types.NewUpdateInstantiateConfigProposal(
|
||||
simtypes.RandStringOfLength(r, 10),
|
||||
simtypes.RandStringOfLength(r, 10),
|
||||
configUpdate,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func SimulateStoreAndInstantiateContractProposal(wasmKeeper WasmKeeper) simtypes.ContentSimulatorFn {
|
||||
return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content {
|
||||
simAccount, _ := simtypes.RandomAcc(r, accs)
|
||||
adminAccount, _ := simtypes.RandomAcc(r, accs)
|
||||
|
||||
wasmBz := testdata.ReflectContractWasm()
|
||||
permission := wasmKeeper.GetParams(ctx).InstantiateDefaultPermission.With(simAccount.Address)
|
||||
|
||||
return types.NewStoreAndInstantiateContractProposal(
|
||||
simtypes.RandStringOfLength(r, 10),
|
||||
simtypes.RandStringOfLength(r, 10),
|
||||
simAccount.Address.String(),
|
||||
wasmBz,
|
||||
"",
|
||||
"",
|
||||
[]byte{},
|
||||
&permission,
|
||||
false,
|
||||
adminAccount.Address.String(),
|
||||
simtypes.RandStringOfLength(r, 10),
|
||||
[]byte(`{}`),
|
||||
sdk.Coins{},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -523,6 +523,22 @@ func (p StoreAndInstantiateContractProposal) MarshalYAML() (interface{}, error)
|
|||
}, nil
|
||||
}
|
||||
|
||||
func NewMigrateContractProposal(
|
||||
title string,
|
||||
description string,
|
||||
contract string,
|
||||
codeID uint64,
|
||||
msg RawContractMessage,
|
||||
) *MigrateContractProposal {
|
||||
return &MigrateContractProposal{
|
||||
Title: title,
|
||||
Description: description,
|
||||
Contract: contract,
|
||||
CodeID: codeID,
|
||||
Msg: msg,
|
||||
}
|
||||
}
|
||||
|
||||
// ProposalRoute returns the routing key of a parameter change proposal.
|
||||
func (p MigrateContractProposal) ProposalRoute() string { return RouterKey }
|
||||
|
||||
|
@ -580,6 +596,20 @@ func (p MigrateContractProposal) MarshalYAML() (interface{}, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func NewSudoContractProposal(
|
||||
title string,
|
||||
description string,
|
||||
contract string,
|
||||
msg RawContractMessage,
|
||||
) *SudoContractProposal {
|
||||
return &SudoContractProposal{
|
||||
Title: title,
|
||||
Description: description,
|
||||
Contract: contract,
|
||||
Msg: msg,
|
||||
}
|
||||
}
|
||||
|
||||
// ProposalRoute returns the routing key of a parameter change proposal.
|
||||
func (p SudoContractProposal) ProposalRoute() string { return RouterKey }
|
||||
|
||||
|
@ -790,6 +820,18 @@ func (p ClearAdminProposal) String() string {
|
|||
`, p.Title, p.Description, p.Contract)
|
||||
}
|
||||
|
||||
func NewPinCodesProposal(
|
||||
title string,
|
||||
description string,
|
||||
codeIDs []uint64,
|
||||
) *PinCodesProposal {
|
||||
return &PinCodesProposal{
|
||||
Title: title,
|
||||
Description: description,
|
||||
CodeIDs: codeIDs,
|
||||
}
|
||||
}
|
||||
|
||||
// ProposalRoute returns the routing key of a parameter change proposal.
|
||||
func (p PinCodesProposal) ProposalRoute() string { return RouterKey }
|
||||
|
||||
|
@ -822,6 +864,18 @@ func (p PinCodesProposal) String() string {
|
|||
`, p.Title, p.Description, p.CodeIDs)
|
||||
}
|
||||
|
||||
func NewUnpinCodesProposal(
|
||||
title string,
|
||||
description string,
|
||||
codeIDs []uint64,
|
||||
) *UnpinCodesProposal {
|
||||
return &UnpinCodesProposal{
|
||||
Title: title,
|
||||
Description: description,
|
||||
CodeIDs: codeIDs,
|
||||
}
|
||||
}
|
||||
|
||||
// ProposalRoute returns the routing key of a parameter change proposal.
|
||||
func (p UnpinCodesProposal) ProposalRoute() string { return RouterKey }
|
||||
|
||||
|
@ -876,6 +930,18 @@ func validateProposalCommons(title, description string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func NewUpdateInstantiateConfigProposal(
|
||||
title string,
|
||||
description string,
|
||||
accessConfigUpdates ...AccessConfigUpdate,
|
||||
) *UpdateInstantiateConfigProposal {
|
||||
return &UpdateInstantiateConfigProposal{
|
||||
Title: title,
|
||||
Description: description,
|
||||
AccessConfigUpdates: accessConfigUpdates,
|
||||
}
|
||||
}
|
||||
|
||||
// ProposalRoute returns the routing key of a parameter change proposal.
|
||||
func (p UpdateInstantiateConfigProposal) ProposalRoute() string { return RouterKey }
|
||||
|
||||
|
|
Loading…
Reference in New Issue