From 058e3981c5cfb91c0fb5861018a262ef5a17d2a9 Mon Sep 17 00:00:00 2001 From: rhuairahrighairigh Date: Sun, 29 Mar 2020 20:50:32 +0100 Subject: [PATCH] add simulation stubs to make tests pass --- x/committee/module.go | 40 ++++++++++++++++--------------- x/committee/simulation/decoder.go | 12 ++++++++++ x/committee/simulation/genesis.go | 22 +++++++++++++++++ x/committee/simulation/params.go | 14 +++++++++++ 4 files changed, 69 insertions(+), 19 deletions(-) create mode 100644 x/committee/simulation/decoder.go create mode 100644 x/committee/simulation/genesis.go create mode 100644 x/committee/simulation/params.go diff --git a/x/committee/module.go b/x/committee/module.go index 12e95b56..f39e8c44 100644 --- a/x/committee/module.go +++ b/x/committee/module.go @@ -2,6 +2,7 @@ package committee import ( "encoding/json" + "math/rand" "github.com/gorilla/mux" "github.com/spf13/cobra" @@ -10,16 +11,18 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + sim "github.com/cosmos/cosmos-sdk/x/simulation" abci "github.com/tendermint/tendermint/abci/types" "github.com/kava-labs/kava/x/committee/client/cli" "github.com/kava-labs/kava/x/committee/client/rest" + "github.com/kava-labs/kava/x/committee/simulation" ) var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} - // TODO_ module.AppModuleSimulation = AppModuleSimulation{} + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleSimulation = AppModuleSimulation{} ) // AppModuleBasic app module basics object @@ -67,31 +70,30 @@ func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { //____________________________________________________________________________ -// TODO -// // AppModuleSimulation defines the module simulation functions used by the module. -// type AppModuleSimulation struct{} +// AppModuleSimulation defines the module simulation functions used by the module. +type AppModuleSimulation struct{} -// // RegisterStoreDecoder registers a decoder for the module's types -// func (AppModuleSimulation) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { -// sdr[StoreKey] = simulation.DecodeStore -// } +// RegisterStoreDecoder registers a decoder for the module's types +func (AppModuleSimulation) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { + sdr[StoreKey] = simulation.DecodeStore +} -// // GenerateGenesisState creates a randomized GenState of the module -// func (AppModuleSimulation) GenerateGenesisState(simState *module.SimulationState) { -// simulation.RandomizedGenState(simState) -// } +// GenerateGenesisState creates a randomized GenState of the module +func (AppModuleSimulation) GenerateGenesisState(simState *module.SimulationState) { + simulation.RandomizedGenState(simState) +} -// // RandomizedParams creates randomized param changes for the simulator. -// func (AppModuleSimulation) RandomizedParams(r *rand.Rand) []sim.ParamChange { -// return simulation.ParamChanges(r) -// } +// RandomizedParams creates randomized param changes for the simulator. +func (AppModuleSimulation) RandomizedParams(r *rand.Rand) []sim.ParamChange { + return simulation.ParamChanges(r) +} //____________________________________________________________________________ // AppModule app module type type AppModule struct { AppModuleBasic - // TODO AppModuleSimulation + AppModuleSimulation keeper Keeper } diff --git a/x/committee/simulation/decoder.go b/x/committee/simulation/decoder.go new file mode 100644 index 00000000..2cdd439b --- /dev/null +++ b/x/committee/simulation/decoder.go @@ -0,0 +1,12 @@ +package simulation + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cmn "github.com/tendermint/tendermint/libs/common" +) + +// DecodeStore unmarshals the KVPair's Value to the corresponding module type +func DecodeStore(cdc *codec.Codec, kvA, kvB cmn.KVPair) string { + // TODO implement this + return "" +} diff --git a/x/committee/simulation/genesis.go b/x/committee/simulation/genesis.go new file mode 100644 index 00000000..5f11ea53 --- /dev/null +++ b/x/committee/simulation/genesis.go @@ -0,0 +1,22 @@ +package simulation + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/kava-labs/kava/x/auction/types" +) + +// RandomizedGenState generates a random GenesisState for the module +func RandomizedGenState(simState *module.SimulationState) { + + // TODO implement this fully + // - randomly generating the genesis params + // - overwriting with genesis provided to simulation + genesisState := types.DefaultGenesisState() + + fmt.Printf("Selected randomly generated %s parameters:\n%s\n", types.ModuleName, codec.MustMarshalJSONIndent(simState.Cdc, genesisState)) + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(genesisState) +} diff --git a/x/committee/simulation/params.go b/x/committee/simulation/params.go new file mode 100644 index 00000000..8c1f7aff --- /dev/null +++ b/x/committee/simulation/params.go @@ -0,0 +1,14 @@ +package simulation + +import ( + "math/rand" + + "github.com/cosmos/cosmos-sdk/x/simulation" +) + +// ParamChanges defines the parameters that can be modified by param change proposals +// on the simulation +func ParamChanges(r *rand.Rand) []simulation.ParamChange { + // TODO implement this + return []simulation.ParamChange{} +}