Skip to content

Commit

Permalink
Add SudoContractProposal simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
pinosu committed Nov 25, 2022
1 parent 1b8cf7b commit 8faacec
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions x/wasm/simulation/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,23 @@ func ProposalContents(bk BankKeeper, wasmKeeper WasmKeeper) []simtypes.WeightedP
params.DefaultWeightClearAdminProposal,
SimulateClearAdminProposal(
wasmKeeper,
DefaultSimulateClearAdminProposalContractSelector,
DefaultSimulateContractSelector,
),
),
simulation.NewWeightedProposalContent(
WeightMigrateContractProposal,
params.DefaultWeightMigrateContractProposal,
SimulateMigrateContractProposal(
wasmKeeper,
DefaultSimulateMigrateContractProposalContractSelector,
DefaultSimulateContractSelector,
),
),
simulation.NewWeightedProposalContent(
WeightSudoContractProposal,
params.DefaultWeightSudoContractProposal,
SimulateMigrateContractProposal(
wasmKeeper,
DefaultSimulateContractSelector,
),
),
}
Expand Down Expand Up @@ -210,7 +218,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 {
Expand Down Expand Up @@ -240,18 +248,6 @@ func SimulateClearAdminProposal(wasmKeeper WasmKeeper, contractSelector ClearAdm

type MigrateContractProposalContractSelector func(sdk.Context, WasmKeeper) sdk.AccAddress

func DefaultSimulateMigrateContractProposalContractSelector(
ctx sdk.Context,
wasmKeeper WasmKeeper,
) sdk.AccAddress {
var contractAddr sdk.AccAddress
wasmKeeper.IterateContractInfo(ctx, func(address sdk.AccAddress, info types.ContractInfo) bool {
contractAddr = address
return true
})
return contractAddr
}

// Simulate migrate contract proposal
func SimulateMigrateContractProposal(wasmKeeper WasmKeeper, contractSelector MigrateContractProposalContractSelector) simtypes.ContentSimulatorFn {
return func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content {
Expand All @@ -274,3 +270,22 @@ func SimulateMigrateContractProposal(wasmKeeper WasmKeeper, contractSelector Mig
)
}
}

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(`{}`),
)
}
}

0 comments on commit 8faacec

Please sign in to comment.