Skip to content

Commit

Permalink
feat: define methods used for module simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulghangas committed Nov 8, 2022
1 parent 1f022bf commit c9a9302
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions x/payment/module_simulation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package payment

import (
"github.com/cosmos/cosmos-sdk/x/authz/codec"
"math/rand"

paymentsimulation "github.com/celestiaorg/celestia-app/x/payment/simulation"
"github.com/celestiaorg/celestia-app/x/payment/types"
"github.com/cosmos/cosmos-sdk/baseapp"
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
)

// avoid unused import issue
var (
_ = paymentsimulation.FindAccount
_ = simappparams.StakePerAccount
_ = simulation.MsgEntryKind
_ = baseapp.Paramspace
)

const (
// this line is used by starport scaffolding # simapp/module/const
)

// GenerateGenesisState creates a randomized GenState of the module
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
accs := make([]string, len(simState.Accounts))
for i, acc := range simState.Accounts {
accs[i] = acc.Address.String()
}
loanGenesis := types.GenesisState{
Params: types.DefaultParams(),
// this line is used by starport scaffolding # simapp/module/genesisState
}
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&loanGenesis)
}

// ProposalContents doesn't return any content functions for governance proposals
func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent {
return nil
}

// RandomizedParams creates randomized param changes for the simulator
func (am AppModule) RandomizedParams(_ *rand.Rand) []simtypes.ParamChange {
paymentParams := types.DefaultParams()
return []simtypes.ParamChange{
simulation.NewSimParamChange(types.ModuleName, string(types.KeyMinSquareSize), func(r *rand.Rand) string {
return string(codec.Amino.MustMarshalJSON(paymentParams.MinSquareSize))
}),
simulation.NewSimParamChange(types.ModuleName, string(types.KeyMaxSquareSize), func(r *rand.Rand) string {
return string(codec.Amino.MustMarshalJSON(paymentParams.MaxSquareSize))
}),
}
}

// RegisterStoreDecoder registers a decoder
func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {}

// WeightedOperations returns the all the gov module operations with their respective weights.
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
operations := make([]simtypes.WeightedOperation, 0)

// this line is used by starport scaffolding # simapp/module/operation

return operations
}

0 comments on commit c9a9302

Please sign in to comment.