diff --git a/CHANGELOG.md b/CHANGELOG.md index e0dac6413e8..ec0ff639f78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (apps/27-interchain-accounts) [\#6377](https://github.com/cosmos/ibc-go/pull/6377) Generate ICA simtest proposals only for provided keepers. + ## [v8.3.0](https://github.com/cosmos/ibc-go/releases/tag/v8.3.0) - 2024-05-16 ### Dependencies diff --git a/modules/apps/27-interchain-accounts/module.go b/modules/apps/27-interchain-accounts/module.go index 62e2c3e0333..d3b7d00d1e1 100644 --- a/modules/apps/27-interchain-accounts/module.go +++ b/modules/apps/27-interchain-accounts/module.go @@ -195,8 +195,8 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { } // ProposalMsgs returns msgs used for governance proposals for simulations. -func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { - return simulation.ProposalMsgs() +func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { + return simulation.ProposalMsgs(am.controllerKeeper, am.hostKeeper) } // WeightedOperations is unimplemented. diff --git a/modules/apps/27-interchain-accounts/simulation/proposals.go b/modules/apps/27-interchain-accounts/simulation/proposals.go index cc12948ef27..7437a2a1825 100644 --- a/modules/apps/27-interchain-accounts/simulation/proposals.go +++ b/modules/apps/27-interchain-accounts/simulation/proposals.go @@ -8,7 +8,9 @@ import ( simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" + controllerkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper" controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" + hostkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper" "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" ) @@ -20,19 +22,23 @@ const ( ) // ProposalMsgs defines the module weighted proposals' contents -func ProposalMsgs() []simtypes.WeightedProposalMsg { - return []simtypes.WeightedProposalMsg{ - simulation.NewWeightedProposalMsg( +func ProposalMsgs(controllerKeeper *controllerkeeper.Keeper, hostKeeper *hostkeeper.Keeper) []simtypes.WeightedProposalMsg { + msgs := make([]simtypes.WeightedProposalMsg, 0, 2) + if hostKeeper != nil { + msgs = append(msgs, simulation.NewWeightedProposalMsg( OpWeightMsgUpdateParams, DefaultWeightMsgUpdateParams, SimulateHostMsgUpdateParams, - ), - simulation.NewWeightedProposalMsg( + )) + } + if controllerKeeper != nil { + msgs = append(msgs, simulation.NewWeightedProposalMsg( OpWeightMsgUpdateParams, DefaultWeightMsgUpdateParams, SimulateControllerMsgUpdateParams, - ), + )) } + return msgs } // SimulateHostMsgUpdateParams returns a MsgUpdateParams for the host module diff --git a/modules/apps/27-interchain-accounts/simulation/proposals_test.go b/modules/apps/27-interchain-accounts/simulation/proposals_test.go index 29d8eae0ebf..c001a919765 100644 --- a/modules/apps/27-interchain-accounts/simulation/proposals_test.go +++ b/modules/apps/27-interchain-accounts/simulation/proposals_test.go @@ -12,8 +12,10 @@ import ( cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + controllerkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper" controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" - "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" + hostkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper" + hosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/simulation" ) @@ -25,32 +27,75 @@ func TestProposalMsgs(t *testing.T) { ctx := sdk.NewContext(nil, cmtproto.Header{}, true, nil) accounts := simtypes.RandomAccounts(r, 3) - // execute ProposalMsgs function - weightedProposalMsgs := simulation.ProposalMsgs() - require.Equal(t, 2, len(weightedProposalMsgs)) - w0 := weightedProposalMsgs[0] + tests := []struct { + name string + controller *controllerkeeper.Keeper + host *hostkeeper.Keeper + expMsgs []sdk.Msg + }{ + { + name: "host and controller keepers are both enabled", + controller: &controllerkeeper.Keeper{}, + host: &hostkeeper.Keeper{}, + expMsgs: []sdk.Msg{ + hosttypes.NewMsgUpdateParams( + sdk.AccAddress(address.Module("gov")).String(), + hosttypes.NewParams(false, []string{hosttypes.AllowAllHostMsgs}), + ), + controllertypes.NewMsgUpdateParams( + sdk.AccAddress(address.Module("gov")).String(), + controllertypes.NewParams(false), + ), + }, + }, + { + name: "host and controller keepers are not enabled", + controller: nil, + host: nil, + }, + { + name: "only controller keeper is enabled", + controller: &controllerkeeper.Keeper{}, + expMsgs: []sdk.Msg{ + controllertypes.NewMsgUpdateParams( + sdk.AccAddress(address.Module("gov")).String(), + controllertypes.NewParams(false), + ), + }, + }, + { + name: "only host keeper is enabled", + host: &hostkeeper.Keeper{}, + expMsgs: []sdk.Msg{ + hosttypes.NewMsgUpdateParams( + sdk.AccAddress(address.Module("gov")).String(), + hosttypes.NewParams(false, []string{hosttypes.AllowAllHostMsgs}), + ), + }, + }, + } - // tests w0 interface: - require.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey()) - require.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight()) + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + // execute ProposalMsgs function + weightedProposalMsgs := simulation.ProposalMsgs(tc.controller, tc.host) + require.Equal(t, len(tc.expMsgs), len(weightedProposalMsgs)) - msg := w0.MsgSimulatorFn()(r, ctx, accounts) - msgUpdateHostParams, ok := msg.(*types.MsgUpdateParams) - require.True(t, ok) + for idx, weightedMsg := range weightedProposalMsgs { + // tests weighted interface: + require.Equal(t, simulation.OpWeightMsgUpdateParams, weightedMsg.AppParamsKey()) + require.Equal(t, simulation.DefaultWeightMsgUpdateParams, weightedMsg.DefaultWeight()) - require.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateHostParams.Signer) - require.Equal(t, msgUpdateHostParams.Params.HostEnabled, false) + msg := weightedMsg.MsgSimulatorFn()(r, ctx, accounts) - w1 := weightedProposalMsgs[1] - - // tests w1 interface: - require.Equal(t, simulation.OpWeightMsgUpdateParams, w1.AppParamsKey()) - require.Equal(t, simulation.DefaultWeightMsgUpdateParams, w1.DefaultWeight()) - - msg1 := w1.MsgSimulatorFn()(r, ctx, accounts) - msgUpdateControllerParams, ok := msg1.(*controllertypes.MsgUpdateParams) - require.True(t, ok) - - require.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateControllerParams.Signer) - require.Equal(t, msgUpdateControllerParams.Params.ControllerEnabled, false) + if msgUpdateHostParams, ok := msg.(*hosttypes.MsgUpdateParams); ok { + require.Equal(t, tc.expMsgs[idx], msgUpdateHostParams) + } else { + msgUpdateControllerParams, ok := msg.(*controllertypes.MsgUpdateParams) + require.True(t, ok) + require.Equal(t, tc.expMsgs[idx], msgUpdateControllerParams) + } + } + }) + } }