From 564a2a5ddb5e5240546030b8c552802c9dbe6469 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 28 Nov 2024 21:50:39 +0100 Subject: [PATCH] feat: integrate with v0.52.x (3/n) --- .../{{moduleName}}/module/depinject.go.plush | 12 ++----- .../x/{{moduleName}}/module/module.go.plush | 3 -- .../{{moduleName}}/module/simulation.go.plush | 24 ++++++-------- .../simulation/helpers.go.plush | 15 --------- .../simulation/msg_factory.go.plush | 19 +++++++++++ .../types/expected_keepers.go.plush | 32 +++++++------------ 6 files changed, 43 insertions(+), 62 deletions(-) delete mode 100644 ignite/templates/module/create/files/base/x/{{moduleName}}/simulation/helpers.go.plush create mode 100644 ignite/templates/module/create/files/base/x/{{moduleName}}/simulation/msg_factory.go.plush diff --git a/ignite/templates/module/create/files/base/x/{{moduleName}}/module/depinject.go.plush b/ignite/templates/module/create/files/base/x/{{moduleName}}/module/depinject.go.plush index 7335ce59ea..c1c6f72984 100644 --- a/ignite/templates/module/create/files/base/x/{{moduleName}}/module/depinject.go.plush +++ b/ignite/templates/module/create/files/base/x/{{moduleName}}/module/depinject.go.plush @@ -38,9 +38,8 @@ type ModuleInputs struct { Cdc codec.Codec AddressCodec address.Codec - AccountKeeper types.AccountKeeper - BankKeeper types.BankKeeper<%= for (dependency) in dependencies { %><%= if (dependency.Name != "Bank" && dependency.Name != "Account") { %> - <%= dependency.KeeperName() %> types.<%= dependency.KeeperName() %><% } %><% } %> + <%= for (dependency) in dependencies { %> + <%= dependency.KeeperName() %> types.<%= dependency.KeeperName() %><% } %> <%= if (isIBC) { %>IBCKeeperFn func() *ibckeeper.Keeper `optional:"true"` CapabilityScopedFn func(string) capabilitykeeper.ScopedKeeper `optional:"true"`<% } %> @@ -68,12 +67,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { in.CapabilityScopedFn,<% } %><%= for (dependency) in dependencies { %> in.<%= dependency.KeeperName() %>,<% } %> ) - m := NewAppModule( - in.Cdc, - k, - in.AccountKeeper, - in.BankKeeper, - ) + m := NewAppModule(in.Cdc, k,) return ModuleOutputs{<%= title(moduleName) %>Keeper: k, Module: m} } diff --git a/ignite/templates/module/create/files/base/x/{{moduleName}}/module/module.go.plush b/ignite/templates/module/create/files/base/x/{{moduleName}}/module/module.go.plush index c296a1bbc8..eab8ea0568 100644 --- a/ignite/templates/module/create/files/base/x/{{moduleName}}/module/module.go.plush +++ b/ignite/templates/module/create/files/base/x/{{moduleName}}/module/module.go.plush @@ -36,20 +36,17 @@ type AppModule struct { cdc codec.Codec keeper keeper.Keeper accountKeeper types.AccountKeeper - bankKeeper types.BankKeeper } func NewAppModule( cdc codec.Codec, keeper keeper.Keeper, accountKeeper types.AccountKeeper, - bankKeeper types.BankKeeper, ) AppModule { return AppModule{ cdc: cdc, keeper: keeper, accountKeeper: accountKeeper, - bankKeeper: bankKeeper, } } diff --git a/ignite/templates/module/create/files/base/x/{{moduleName}}/module/simulation.go.plush b/ignite/templates/module/create/files/base/x/{{moduleName}}/module/simulation.go.plush index 7cc773fe9d..c5d26153d2 100644 --- a/ignite/templates/module/create/files/base/x/{{moduleName}}/module/simulation.go.plush +++ b/ignite/templates/module/create/files/base/x/{{moduleName}}/module/simulation.go.plush @@ -7,20 +7,18 @@ import ( 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" + "github.com/cosmos/cosmos-sdk/simsx" "<%= modulePath %>/testutil/sample" - <%= moduleName %>simulation "<%= modulePath %>/x/<%= moduleName %>/simulation" + "<%= modulePath %>/x/<%= moduleName %>/simulation" "<%= modulePath %>/x/<%= moduleName %>/types" ) // avoid unused import issue var ( - _ = <%= moduleName %>simulation.FindAccount _ = rand.Rand{} _ = sample.AccAddress _ = sdk.AccAddress{} - _ = simulation.MsgEntryKind ) const ( @@ -44,18 +42,14 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { // RegisterStoreDecoder registers a decoder. func (am AppModule) RegisterStoreDecoder(_ simtypes.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) +// ProposalMsgsX returns msgs used for governance proposals for simulations. +func (AppModule) ProposalMsgsX(weights simsx.WeightSource, reg simsx.Registry) { + reg.Add(weights.Get("msg_update_params", 100), simulation.MsgUpdateParamsFactory()) - // this line is used by starport scaffolding # simapp/module/operation - - return operations + // this line is used by starport scaffolding # simapp/module/OpMsg } -// ProposalMsgs returns msgs used for governance proposals for simulations. -func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { - return []simtypes.WeightedProposalMsg{ - // this line is used by starport scaffolding # simapp/module/OpMsg - } +// WeightedOperations returns the all the module operations with their respective weights. +func (am AppModule) WeightedOperationsX(weights simsx.WeightSource, reg simsx.Registry) { + // this line is used by starport scaffolding # simapp/module/operation } diff --git a/ignite/templates/module/create/files/base/x/{{moduleName}}/simulation/helpers.go.plush b/ignite/templates/module/create/files/base/x/{{moduleName}}/simulation/helpers.go.plush deleted file mode 100644 index 92c437c0d1..0000000000 --- a/ignite/templates/module/create/files/base/x/{{moduleName}}/simulation/helpers.go.plush +++ /dev/null @@ -1,15 +0,0 @@ -package simulation - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" -) - -// FindAccount find a specific address from an account list -func FindAccount(accs []simtypes.Account, address string) (simtypes.Account, bool) { - creator, err := sdk.AccAddressFromBech32(address) - if err != nil { - panic(err) - } - return simtypes.FindAccount(accs, creator) -} diff --git a/ignite/templates/module/create/files/base/x/{{moduleName}}/simulation/msg_factory.go.plush b/ignite/templates/module/create/files/base/x/{{moduleName}}/simulation/msg_factory.go.plush new file mode 100644 index 0000000000..aaf187d23d --- /dev/null +++ b/ignite/templates/module/create/files/base/x/{{moduleName}}/simulation/msg_factory.go.plush @@ -0,0 +1,19 @@ +package simulation + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/simsx" +) + +// MsgUpdateParamsFactory creates a gov proposal for param updates +func MsgUpdateParamsFactory() simsx.SimMsgFactoryFn[*types.MsgUpdateParams] { + return func(_ context.Context, testData *simsx.ChainDataSource, reporter simsx.SimulationReporter) ([]simsx.SimAccount, *types.MsgUpdateParams) { + params := types.DefaultParams() + // add custom params here + return nil, &types.MsgUpdateParams{ + Authority: testData.ModuleAccountAddress(reporter, "gov"), + Params: params, + } + } +} diff --git a/ignite/templates/module/create/files/base/x/{{moduleName}}/types/expected_keepers.go.plush b/ignite/templates/module/create/files/base/x/{{moduleName}}/types/expected_keepers.go.plush index 4287d068ab..33dd515736 100644 --- a/ignite/templates/module/create/files/base/x/{{moduleName}}/types/expected_keepers.go.plush +++ b/ignite/templates/module/create/files/base/x/{{moduleName}}/types/expected_keepers.go.plush @@ -10,8 +10,18 @@ import ( ) <%= for (dependency) in dependencies { %> - <%= if (dependency.Name == "Account") { %> + <%= if (dependency.Name == "Auth") { %> + // AuthKeeper defines the expected interface for the Auth module. + type AuthKeeper interface { + GetAccount(context.Context, sdk.AccAddress) sdk.AccountI // only used for simulation + // Methods imported from account should be defined here + } <% } else if (dependency.Name == "Bank") { %> + // BankKeeper defines the expected interface for the Bank module. + type BankKeeper interface { + SpendableCoins(context.Context, sdk.AccAddress) sdk.Coins + // Methods imported from bank should be defined here + } <% } else if (dependency.Name == "Staking") { %> // StakingKeeper defines the expected interface for the Staking module. type StakingKeeper interface { @@ -68,22 +78,4 @@ import ( // TODO Add methods imported from <%= toLower(dependency.Name) %> should be defined here } <% } %> -<% } %> - -// AccountKeeper defines the expected interface for the Account module. -type AccountKeeper interface { - GetAccount(context.Context, sdk.AccAddress) sdk.AccountI // only used for simulation - // Methods imported from account should be defined here -} - -// BankKeeper defines the expected interface for the Bank module. -type BankKeeper interface { - SpendableCoins(context.Context, sdk.AccAddress) sdk.Coins - // Methods imported from bank should be defined here -} - -// ParamSubspace defines the expected Subspace interface for parameters. -type ParamSubspace interface { - Get(context.Context, []byte, interface{}) - Set(context.Context, []byte, interface{}) -} +<% } %> \ No newline at end of file