Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/27-interchain-accounts/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 12 additions & 6 deletions modules/apps/27-interchain-accounts/simulation/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
Expand Down
95 changes: 70 additions & 25 deletions modules/apps/27-interchain-accounts/simulation/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
}
}
})
}
}