mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-25 07:45:18 +00:00
add simulation stubs to make tests pass (#408)
This commit is contained in:
parent
2721ba3889
commit
f3e2e7e585
@ -334,6 +334,7 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
|
|||||||
cdp.NewAppModule(app.cdpKeeper, app.pricefeedKeeper, app.supplyKeeper), // TODO how is the order be decided here? Is this order correct?
|
cdp.NewAppModule(app.cdpKeeper, app.pricefeedKeeper, app.supplyKeeper), // TODO how is the order be decided here? Is this order correct?
|
||||||
pricefeed.NewAppModule(app.pricefeedKeeper),
|
pricefeed.NewAppModule(app.pricefeedKeeper),
|
||||||
auction.NewAppModule(app.auctionKeeper, app.supplyKeeper),
|
auction.NewAppModule(app.auctionKeeper, app.supplyKeeper),
|
||||||
|
bep3.NewAppModule(app.bep3Keeper, app.supplyKeeper),
|
||||||
kavadist.NewAppModule(app.kavadistKeeper, app.supplyKeeper),
|
kavadist.NewAppModule(app.kavadistKeeper, app.supplyKeeper),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2,22 +2,26 @@ package bep3
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"math/rand"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client/context"
|
"github.com/cosmos/cosmos-sdk/client/context"
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/module"
|
"github.com/cosmos/cosmos-sdk/types/module"
|
||||||
|
sim "github.com/cosmos/cosmos-sdk/x/simulation"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
|
|
||||||
"github.com/kava-labs/kava/x/bep3/client/cli"
|
"github.com/kava-labs/kava/x/bep3/client/cli"
|
||||||
"github.com/kava-labs/kava/x/bep3/client/rest"
|
"github.com/kava-labs/kava/x/bep3/client/rest"
|
||||||
|
"github.com/kava-labs/kava/x/bep3/simulation"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_ module.AppModule = AppModule{}
|
_ module.AppModule = AppModule{}
|
||||||
_ module.AppModuleBasic = AppModuleBasic{}
|
_ module.AppModuleBasic = AppModuleBasic{}
|
||||||
|
_ module.AppModuleSimulation = AppModuleSimulation{}
|
||||||
)
|
)
|
||||||
|
|
||||||
// AppModuleBasic defines the basic application module used by the bep3 module.
|
// AppModuleBasic defines the basic application module used by the bep3 module.
|
||||||
@ -64,9 +68,32 @@ func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
|
|||||||
return cli.GetQueryCmd(StoreKey, cdc)
|
return cli.GetQueryCmd(StoreKey, cdc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//____________________________________________________________________________
|
||||||
|
|
||||||
|
// AppModuleSimulation defines the module simulation functions used by the auction module.
|
||||||
|
type AppModuleSimulation struct{}
|
||||||
|
|
||||||
|
// RegisterStoreDecoder registers a decoder for auction module's types
|
||||||
|
func (AppModuleSimulation) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
|
||||||
|
sdr[StoreKey] = simulation.DecodeStore
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenerateGenesisState creates a randomized GenState of the auction module
|
||||||
|
func (AppModuleSimulation) GenerateGenesisState(simState *module.SimulationState) {
|
||||||
|
simulation.RandomizedGenState(simState)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RandomizedParams creates randomized auction param changes for the simulator.
|
||||||
|
func (AppModuleSimulation) RandomizedParams(r *rand.Rand) []sim.ParamChange {
|
||||||
|
return simulation.ParamChanges(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
//____________________________________________________________________________
|
||||||
|
|
||||||
// AppModule implements the sdk.AppModule interface.
|
// AppModule implements the sdk.AppModule interface.
|
||||||
type AppModule struct {
|
type AppModule struct {
|
||||||
AppModuleBasic
|
AppModuleBasic
|
||||||
|
AppModuleSimulation
|
||||||
|
|
||||||
keeper Keeper
|
keeper Keeper
|
||||||
supplyKeeper SupplyKeeper
|
supplyKeeper SupplyKeeper
|
||||||
|
12
x/bep3/simulation/decoder.go
Normal file
12
x/bep3/simulation/decoder.go
Normal file
@ -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 module's corresponding type
|
||||||
|
func DecodeStore(cdc *codec.Codec, kvA, kvB cmn.KVPair) string {
|
||||||
|
// TODO implement this
|
||||||
|
return ""
|
||||||
|
}
|
22
x/bep3/simulation/genesis.go
Normal file
22
x/bep3/simulation/genesis.go
Normal file
@ -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/bep3/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RandomizedGenState generates a random GenesisState
|
||||||
|
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)
|
||||||
|
}
|
14
x/bep3/simulation/params.go
Normal file
14
x/bep3/simulation/params.go
Normal file
@ -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{}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user