Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(simulations): allow simulations to pass even if Interchain Accounts simulation handlers are nonexistent #202

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ func New(
ibc.NewAppModule(app.IBCKeeper),
didmodule.NewAppModule(appCodec, app.DidKeeper, app.AccountKeeper, app.BankKeeper),
app.transferModule,
NewICAHostSimModule(icaModule, appCodec),
// this line is used by starport scaffolding # stargate/app/appModule
)
app.sm.RegisterStoreDecoders()
Expand Down
69 changes: 69 additions & 0 deletions app/icahost_sim_helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package app

import (
"encoding/json"
"fmt"
"math/rand"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
ica "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts"
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
)

type ICAHostSimModule struct {
ica.AppModule
ica.AppModuleBasic
cdc codec.Codec
}

var (
_ module.AppModule = ICAHostSimModule{}
_ module.AppModuleBasic = ICAHostSimModule{}
_ module.AppModuleSimulation = ICAHostSimModule{}
)

func NewICAHostSimModule(baseModule ica.AppModule, cdc codec.Codec) ICAHostSimModule {
return ICAHostSimModule{
cdc: cdc,
AppModule: baseModule,
AppModuleBasic: baseModule.AppModuleBasic,
}
}

// ICAHostSimModuleSimulation functions
// This thing does the bare minimum to avoid simulation panic-ing for missing state data.

// GenerateGenesisState creates a randomized GenState of the ica module.
func (i ICAHostSimModule) GenerateGenesisState(simState *module.SimulationState) {
genesis := icatypes.DefaultGenesis()

bz, err := json.MarshalIndent(&genesis, "", " ")
if err != nil {
panic(err)
}
fmt.Printf("Selected randomly generated %s parameters:\n%s\n", icatypes.ModuleName, bz)
simState.GenState[icatypes.ModuleName] = simState.Cdc.MustMarshalJSON(genesis)
}

// ProposalContents returns all the ica content functions used to
// simulate governance proposals.
func (ICAHostSimModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent {
return nil
}

// RandomizedParams creates randomized ica param changes for the simulator.
func (ICAHostSimModule) RandomizedParams(*rand.Rand) []simtypes.ParamChange {
return nil
}

// RegisterStoreDecoder registers a decoder for ica module's types
func (ICAHostSimModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
}

// WeightedOperations returns the all the gov module operations with their respective weights.
func (ICAHostSimModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation {
return nil
}