simulation genesis

This commit is contained in:
0xmuralik
2022-10-27 12:44:59 +05:30
parent 9f31e1b556
commit d4b13e2859
10 changed files with 209 additions and 2 deletions
+25
View File
@@ -4,15 +4,18 @@ import (
"context"
"encoding/json"
"fmt"
"math/rand"
"github.com/cerc-io/laconicd/x/bond/client/cli"
"github.com/cerc-io/laconicd/x/bond/keeper"
"github.com/cerc-io/laconicd/x/bond/simulation"
"github.com/cerc-io/laconicd/x/bond/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
@@ -99,6 +102,28 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
return cdc.MustMarshalJSON(&gs)
}
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
simulation.RandomizedGenState(simState)
}
// WeightedOperations returns the all the fee market module operations with their respective weights.
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
return nil
}
// RandomizedParams creates randomized fee market param changes for the simulator.
func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange {
return nil
}
// RegisterStoreDecoder registers a decoder for fee market module's types
func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {}
// ProposalContents doesn't return any content functions for governance proposals.
func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent {
return nil
}
func (am AppModule) RegisterInvariants(registry sdk.InvariantRegistry) {
keeper.RegisterInvariants(registry, am.keeper)
}
+23
View File
@@ -0,0 +1,23 @@
package simulation
import (
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cerc-io/laconicd/x/bond/types"
)
// RandomizedGenState generates a random GenesisState
func RandomizedGenState(simState *module.SimulationState) {
bondGenesis := types.DefaultGenesisState()
bz, err := json.MarshalIndent(bondGenesis, "", " ")
if err != nil {
panic(err)
}
fmt.Printf("Selected randomly generated %s parameters:\n%s\n", types.ModuleName, bz)
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(bondGenesis)
}
+1
View File
@@ -5,5 +5,6 @@ package types
func DefaultGenesisState() *GenesisState {
return &GenesisState{
Params: DefaultParams(),
Bonds: []*Bond{},
}
}