diff --git a/modules/apps/27-interchain-accounts/module.go b/modules/apps/27-interchain-accounts/module.go index 91d7706701c..346bed3b162 100644 --- a/modules/apps/27-interchain-accounts/module.go +++ b/modules/apps/27-interchain-accounts/module.go @@ -36,6 +36,7 @@ var ( _ module.AppModule = (*AppModule)(nil) _ module.AppModuleBasic = (*AppModuleBasic)(nil) _ module.AppModuleSimulation = (*AppModule)(nil) + _ module.HasProposalMsgs = AppModule{} _ appmodule.AppModule = (*AppModule)(nil) _ porttypes.IBCModule = (*host.IBCModule)(nil) @@ -218,6 +219,11 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } +// ProposalMsgs returns msgs used for governance proposals for simulations. +func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { + return simulation.ProposalMsgs() +} + // WeightedOperations is unimplemented. func (AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { return nil diff --git a/modules/apps/27-interchain-accounts/simulation/proposals.go b/modules/apps/27-interchain-accounts/simulation/proposals.go new file mode 100644 index 00000000000..a4850a81fe3 --- /dev/null +++ b/modules/apps/27-interchain-accounts/simulation/proposals.go @@ -0,0 +1,60 @@ +package simulation + +import ( + "math/rand" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" + + controllertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" + "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" +) + +// Simulation operation weights constants +const ( + DefaultWeightMsgUpdateParams int = 100 + + OpWeightMsgUpdateParams = "op_weight_msg_update_params" // #nosec +) + +// ProposalMsgs defines the module weighted proposals' contents +func ProposalMsgs() []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{ + simulation.NewWeightedProposalMsg( + OpWeightMsgUpdateParams, + DefaultWeightMsgUpdateParams, + SimulateHostMsgUpdateParams, + ), + simulation.NewWeightedProposalMsg( + OpWeightMsgUpdateParams, + DefaultWeightMsgUpdateParams, + SimulateControllerMsgUpdateParams, + ), + } +} + +// SimulateHostMsgUpdateParams returns a random MsgUpdateParams for the host module +func SimulateHostMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { + var signer sdk.AccAddress = address.Module("gov") + params := types.DefaultParams() + params.HostEnabled = false + + return &types.MsgUpdateParams{ + Signer: signer.String(), + Params: params, + } +} + +// SimulateControllerMsgUpdateParams returns a random MsgUpdateParams for the controller module +func SimulateControllerMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { + var signer sdk.AccAddress = address.Module("gov") + params := controllertypes.DefaultParams() + params.ControllerEnabled = false + + return &controllertypes.MsgUpdateParams{ + Signer: signer.String(), + Params: params, + } +} diff --git a/modules/apps/27-interchain-accounts/simulation/proposals_test.go b/modules/apps/27-interchain-accounts/simulation/proposals_test.go new file mode 100644 index 00000000000..7d301845965 --- /dev/null +++ b/modules/apps/27-interchain-accounts/simulation/proposals_test.go @@ -0,0 +1,56 @@ +package simulation_test + +import ( + "math/rand" + "testing" + + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + + controllertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" + "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" + "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/simulation" +) + +func TestProposalMsgs(t *testing.T) { + // initialize parameters + s := rand.NewSource(1) + r := rand.New(s) + + 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 w0 interface: + require.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey()) + require.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight()) + + msg := w0.MsgSimulatorFn()(r, ctx, accounts) + msgUpdateHostParams, ok := msg.(*types.MsgUpdateParams) + require.True(t, ok) + + require.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateHostParams.Signer) + require.Equal(t, msgUpdateHostParams.Params.HostEnabled, false) + + 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) +} diff --git a/modules/apps/transfer/module.go b/modules/apps/transfer/module.go index 52c54edfb3c..1d85d406c76 100644 --- a/modules/apps/transfer/module.go +++ b/modules/apps/transfer/module.go @@ -27,10 +27,11 @@ import ( ) var ( - _ module.AppModule = (*AppModule)(nil) - _ module.AppModuleBasic = (*AppModuleBasic)(nil) - _ appmodule.AppModule = (*AppModule)(nil) - _ porttypes.IBCModule = (*IBCModule)(nil) + _ module.AppModule = (*AppModule)(nil) + _ module.AppModuleBasic = (*AppModuleBasic)(nil) + _ module.HasProposalMsgs = AppModule{} + _ appmodule.AppModule = (*AppModule)(nil) + _ porttypes.IBCModule = (*IBCModule)(nil) ) // AppModuleBasic is the IBC Transfer AppModuleBasic @@ -154,6 +155,11 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } +// ProposalMsgs returns msgs used for governance proposals for simulations. +func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { + return simulation.ProposalMsgs() +} + // RegisterStoreDecoder registers a decoder for transfer module's types func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { sdr[types.StoreKey] = simulation.NewDecodeStore(am.keeper) diff --git a/modules/apps/transfer/simulation/proposals.go b/modules/apps/transfer/simulation/proposals.go new file mode 100644 index 00000000000..f97fcb9b33d --- /dev/null +++ b/modules/apps/transfer/simulation/proposals.go @@ -0,0 +1,42 @@ +package simulation + +import ( + "math/rand" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" + + "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" +) + +// Simulation operation weights constants +const ( + DefaultWeightMsgUpdateParams int = 100 + + OpWeightMsgUpdateParams = "op_weight_msg_update_params" // #nosec +) + +// ProposalMsgs defines the module weighted proposals' contents +func ProposalMsgs() []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{ + simulation.NewWeightedProposalMsg( + OpWeightMsgUpdateParams, + DefaultWeightMsgUpdateParams, + SimulateMsgUpdateParams, + ), + } +} + +// SimulateMsgUpdateParams returns a random MsgUpdateParams +func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { + var signer sdk.AccAddress = address.Module("gov") + params := types.DefaultParams() + params.SendEnabled = false + + return &types.MsgUpdateParams{ + Signer: signer.String(), + Params: params, + } +} diff --git a/modules/apps/transfer/simulation/proposals_test.go b/modules/apps/transfer/simulation/proposals_test.go new file mode 100644 index 00000000000..c70c2016ed3 --- /dev/null +++ b/modules/apps/transfer/simulation/proposals_test.go @@ -0,0 +1,43 @@ +package simulation_test + +import ( + "math/rand" + "testing" + + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + + "github.com/cosmos/ibc-go/v7/modules/apps/transfer/simulation" + "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" +) + +func TestProposalMsgs(t *testing.T) { + // initialize parameters + s := rand.NewSource(1) + r := rand.New(s) + + ctx := sdk.NewContext(nil, cmtproto.Header{}, true, nil) + accounts := simtypes.RandomAccounts(r, 3) + + // execute ProposalMsgs function + weightedProposalMsgs := simulation.ProposalMsgs() + require.Equal(t, len(weightedProposalMsgs), 1) + + w0 := weightedProposalMsgs[0] + + // tests w0 interface: + require.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey()) + require.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight()) + + msg := w0.MsgSimulatorFn()(r, ctx, accounts) + msgUpdateParams, ok := msg.(*types.MsgUpdateParams) + require.True(t, ok) + + require.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Signer) + require.EqualValues(t, msgUpdateParams.Params.SendEnabled, false) +} diff --git a/modules/core/module.go b/modules/core/module.go index 8c671b4b850..b21e6397f5a 100644 --- a/modules/core/module.go +++ b/modules/core/module.go @@ -36,6 +36,7 @@ var ( _ module.AppModule = (*AppModule)(nil) _ module.AppModuleBasic = (*AppModuleBasic)(nil) _ module.AppModuleSimulation = (*AppModule)(nil) + _ module.HasProposalMsgs = AppModule{} _ appmodule.AppModule = (*AppModule)(nil) ) @@ -193,6 +194,11 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } +// ProposalMsgs returns msgs used for governance proposals for simulations. +func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { + return simulation.ProposalMsgs() +} + // RegisterStoreDecoder registers a decoder for ibc module's types func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { sdr[exported.StoreKey] = simulation.NewDecodeStore(*am.keeper) diff --git a/modules/core/simulation/proposals.go b/modules/core/simulation/proposals.go new file mode 100644 index 00000000000..68546c716a8 --- /dev/null +++ b/modules/core/simulation/proposals.go @@ -0,0 +1,60 @@ +package simulation + +import ( + "math/rand" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" + + "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" +) + +// Simulation operation weights constants +const ( + DefaultWeightMsgUpdateParams int = 100 + + OpWeightMsgUpdateParams = "op_weight_msg_update_params" // #nosec +) + +// ProposalMsgs defines the module weighted proposals' contents +func ProposalMsgs() []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{ + simulation.NewWeightedProposalMsg( + OpWeightMsgUpdateParams, + DefaultWeightMsgUpdateParams, + SimulateClientMsgUpdateParams, + ), + simulation.NewWeightedProposalMsg( + OpWeightMsgUpdateParams, + DefaultWeightMsgUpdateParams, + SimulateConnectionMsgUpdateParams, + ), + } +} + +// SimulateClientMsgUpdateParams returns a random MsgUpdateParams for 02-client +func SimulateClientMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { + var signer sdk.AccAddress = address.Module("gov") + params := types.DefaultParams() + params.AllowedClients = []string{"06-solomachine", "07-tendermint"} + + return &types.MsgUpdateParams{ + Signer: signer.String(), + Params: params, + } +} + +// SimulateConnectionMsgUpdateParams returns a random MsgUpdateParams 03-connection +func SimulateConnectionMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { + var signer sdk.AccAddress = address.Module("gov") + params := connectiontypes.DefaultParams() + params.MaxExpectedTimePerBlock = uint64(100) + + return &connectiontypes.MsgUpdateParams{ + Signer: signer.String(), + Params: params, + } +} diff --git a/modules/core/simulation/proposals_test.go b/modules/core/simulation/proposals_test.go new file mode 100644 index 00000000000..18df7281cb6 --- /dev/null +++ b/modules/core/simulation/proposals_test.go @@ -0,0 +1,57 @@ +package simulation_test + +import ( + "math/rand" + "testing" + + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + + "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" + "github.com/cosmos/ibc-go/v7/modules/core/simulation" +) + +func TestProposalMsgs(t *testing.T) { + // initialize parameters + s := rand.NewSource(1) + r := rand.New(s) + + 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 w0 interface: + require.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey()) + require.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight()) + + msg := w0.MsgSimulatorFn()(r, ctx, accounts) + msgUpdateParams, ok := msg.(*types.MsgUpdateParams) + require.True(t, ok) + + require.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Signer) + require.EqualValues(t, []string{"06-solomachine", "07-tendermint"}, msgUpdateParams.Params.AllowedClients) + + 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) + msgUpdateConnectionParams, ok := msg1.(*connectiontypes.MsgUpdateParams) + require.True(t, ok) + + require.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Signer) + require.EqualValues(t, uint64(100), msgUpdateConnectionParams.Params.MaxExpectedTimePerBlock) +}