From 8faacec8ae71fb291f1f7f2104df3734a22f6a84 Mon Sep 17 00:00:00 2001 From: Pino' Surace Date: Fri, 25 Nov 2022 12:56:56 +0100 Subject: [PATCH] Add SudoContractProposal simulation --- x/wasm/simulation/proposals.go | 45 ++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/x/wasm/simulation/proposals.go b/x/wasm/simulation/proposals.go index 1eaac42be7..9cef89d708 100644 --- a/x/wasm/simulation/proposals.go +++ b/x/wasm/simulation/proposals.go @@ -66,7 +66,7 @@ func ProposalContents(bk BankKeeper, wasmKeeper WasmKeeper) []simtypes.WeightedP params.DefaultWeightClearAdminProposal, SimulateClearAdminProposal( wasmKeeper, - DefaultSimulateClearAdminProposalContractSelector, + DefaultSimulateContractSelector, ), ), simulation.NewWeightedProposalContent( @@ -74,7 +74,15 @@ func ProposalContents(bk BankKeeper, wasmKeeper WasmKeeper) []simtypes.WeightedP params.DefaultWeightMigrateContractProposal, SimulateMigrateContractProposal( wasmKeeper, - DefaultSimulateMigrateContractProposalContractSelector, + DefaultSimulateContractSelector, + ), + ), + simulation.NewWeightedProposalContent( + WeightSudoContractProposal, + params.DefaultWeightSudoContractProposal, + SimulateMigrateContractProposal( + wasmKeeper, + DefaultSimulateContractSelector, ), ), } @@ -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 { @@ -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 { @@ -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(`{}`), + ) + } +}