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

Update ica simulated proposals to check which modules are instantianted. #6377

Merged
Merged
Show file tree
Hide file tree
Changes from 8 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 @@ -71,6 +71,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
Taztingo marked this conversation as resolved.
Show resolved Hide resolved
}

// SimulateHostMsgUpdateParams returns a MsgUpdateParams for the host module
Expand Down
75 changes: 52 additions & 23 deletions modules/apps/27-interchain-accounts/simulation/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ 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"
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"
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/simulation"
)
Expand All @@ -25,32 +27,59 @@ 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 {
Taztingo marked this conversation as resolved.
Show resolved Hide resolved
controller *controllerkeeper.Keeper
host *hostkeeper.Keeper
proposalMsgs int
isHost []bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

happy with this, but could also maybe do expMsgs []interface where test case 1 has []interface{msgHostUpdateParams, msgControllerUpdateParams} (we can create the expected host and controller msgs at the top of the test since they are predictable)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great idea. I also updated the tests to match your others so they include a name and run in a goroutine. Let me know if there is anything else.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use []sdk.Msg or []proto.Message instead of []interface to have stronger typing?

}{
{
controller: &controllerkeeper.Keeper{},
host: &hostkeeper.Keeper{},
proposalMsgs: 2,
isHost: []bool{true, false},
},
{
controller: nil,
host: nil,
proposalMsgs: 0,
},
{
controller: &controllerkeeper.Keeper{},
proposalMsgs: 1,
isHost: []bool{false},
},
{
host: &hostkeeper.Keeper{},
proposalMsgs: 1,
isHost: []bool{true},
},
}

// tests w0 interface:
require.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey())
require.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight())
for _, test := range tests {
// execute ProposalMsgs function
weightedProposalMsgs := simulation.ProposalMsgs(test.controller, test.host)
require.Equal(t, test.proposalMsgs, 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)
if test.isHost[idx] {
msgUpdateHostParams, ok := msg.(*types.MsgUpdateParams)
require.True(t, ok)

w1 := weightedProposalMsgs[1]
require.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateHostParams.Signer)
require.Equal(t, msgUpdateHostParams.Params.HostEnabled, false)
} else {
msgUpdateControllerParams, ok := msg.(*controllertypes.MsgUpdateParams)
require.True(t, ok)

// 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)
require.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateControllerParams.Signer)
require.Equal(t, msgUpdateControllerParams.Params.ControllerEnabled, false)
}
}
}
Taztingo marked this conversation as resolved.
Show resolved Hide resolved
}
Loading