Skip to content

Commit 431877f

Browse files
committed
Update ica simulated proposals to check which modules are instantianted.
1 parent 9b6567b commit 431877f

File tree

3 files changed

+66
-31
lines changed

3 files changed

+66
-31
lines changed

modules/apps/27-interchain-accounts/module.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
216216
}
217217

218218
// ProposalMsgs returns msgs used for governance proposals for simulations.
219-
func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg {
220-
return simulation.ProposalMsgs()
219+
func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg {
220+
return simulation.ProposalMsgs(am.controllerKeeper, am.hostKeeper)
221221
}
222222

223223
// WeightedOperations is unimplemented.

modules/apps/27-interchain-accounts/simulation/proposals.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import (
88
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
99
"github.com/cosmos/cosmos-sdk/x/simulation"
1010

11+
controllerkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper"
1112
controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
13+
hostkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper"
1214
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
1315
)
1416

@@ -20,19 +22,23 @@ const (
2022
)
2123

2224
// ProposalMsgs defines the module weighted proposals' contents
23-
func ProposalMsgs() []simtypes.WeightedProposalMsg {
24-
return []simtypes.WeightedProposalMsg{
25-
simulation.NewWeightedProposalMsg(
25+
func ProposalMsgs(controllerKeeper *controllerkeeper.Keeper, hostKeeper *hostkeeper.Keeper) []simtypes.WeightedProposalMsg {
26+
msgs := make([]simtypes.WeightedProposalMsg, 0, 2)
27+
if hostKeeper != nil {
28+
msgs = append(msgs, simulation.NewWeightedProposalMsg(
2629
OpWeightMsgUpdateParams,
2730
DefaultWeightMsgUpdateParams,
2831
SimulateHostMsgUpdateParams,
29-
),
30-
simulation.NewWeightedProposalMsg(
32+
))
33+
}
34+
if controllerKeeper != nil {
35+
msgs = append(msgs, simulation.NewWeightedProposalMsg(
3136
OpWeightMsgUpdateParams,
3237
DefaultWeightMsgUpdateParams,
3338
SimulateControllerMsgUpdateParams,
34-
),
39+
))
3540
}
41+
return msgs
3642
}
3743

3844
// SimulateHostMsgUpdateParams returns a MsgUpdateParams for the host module

modules/apps/27-interchain-accounts/simulation/proposals_test.go

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import (
1212

1313
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
1414

15+
controllerkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper"
1516
controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
17+
hostkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper"
1618
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
1719
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/simulation"
1820
)
@@ -25,32 +27,59 @@ func TestProposalMsgs(t *testing.T) {
2527
ctx := sdk.NewContext(nil, cmtproto.Header{}, true, nil)
2628
accounts := simtypes.RandomAccounts(r, 3)
2729

28-
// execute ProposalMsgs function
29-
weightedProposalMsgs := simulation.ProposalMsgs()
30-
require.Equal(t, 2, len(weightedProposalMsgs))
31-
w0 := weightedProposalMsgs[0]
30+
tests := []struct {
31+
controller *controllerkeeper.Keeper
32+
host *hostkeeper.Keeper
33+
proposalMsgs int
34+
isHost []bool
35+
}{
36+
{
37+
controller: &controllerkeeper.Keeper{},
38+
host: &hostkeeper.Keeper{},
39+
proposalMsgs: 2,
40+
isHost: []bool{true, false},
41+
},
42+
{
43+
controller: nil,
44+
host: nil,
45+
proposalMsgs: 0,
46+
},
47+
{
48+
controller: &controllerkeeper.Keeper{},
49+
proposalMsgs: 1,
50+
isHost: []bool{false},
51+
},
52+
{
53+
host: &hostkeeper.Keeper{},
54+
proposalMsgs: 1,
55+
isHost: []bool{true},
56+
},
57+
}
3258

33-
// tests w0 interface:
34-
require.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey())
35-
require.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight())
59+
for _, test := range tests {
60+
// execute ProposalMsgs function
61+
weightedProposalMsgs := simulation.ProposalMsgs(test.controller, test.host)
62+
require.Equal(t, test.proposalMsgs, len(weightedProposalMsgs))
3663

37-
msg := w0.MsgSimulatorFn()(r, ctx, accounts)
38-
msgUpdateHostParams, ok := msg.(*types.MsgUpdateParams)
39-
require.True(t, ok)
64+
for idx, weightedMsg := range weightedProposalMsgs {
65+
// tests weighted interface:
66+
require.Equal(t, simulation.OpWeightMsgUpdateParams, weightedMsg.AppParamsKey())
67+
require.Equal(t, simulation.DefaultWeightMsgUpdateParams, weightedMsg.DefaultWeight())
4068

41-
require.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateHostParams.Signer)
42-
require.Equal(t, msgUpdateHostParams.Params.HostEnabled, false)
69+
msg := weightedMsg.MsgSimulatorFn()(r, ctx, accounts)
70+
if test.isHost[idx] {
71+
msgUpdateHostParams, ok := msg.(*types.MsgUpdateParams)
72+
require.True(t, ok)
4373

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

46-
// tests w1 interface:
47-
require.Equal(t, simulation.OpWeightMsgUpdateParams, w1.AppParamsKey())
48-
require.Equal(t, simulation.DefaultWeightMsgUpdateParams, w1.DefaultWeight())
49-
50-
msg1 := w1.MsgSimulatorFn()(r, ctx, accounts)
51-
msgUpdateControllerParams, ok := msg1.(*controllertypes.MsgUpdateParams)
52-
require.True(t, ok)
53-
54-
require.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateControllerParams.Signer)
55-
require.Equal(t, msgUpdateControllerParams.Params.ControllerEnabled, false)
80+
require.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateControllerParams.Signer)
81+
require.Equal(t, msgUpdateControllerParams.Params.ControllerEnabled, false)
82+
}
83+
}
84+
}
5685
}

0 commit comments

Comments
 (0)