Skip to content

Commit

Permalink
chore: remove gov v1beta1 from simapp (cosmos#6798)
Browse files Browse the repository at this point in the history
* chore: remove gov v1beta1 router from simapps

* fix ica gov test failing intermittently

* Remove usage of gov v1beta1 from relay test
  • Loading branch information
gjermundgaraba authored Jul 10, 2024
1 parent 575902b commit 07316fa
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 134 deletions.
2 changes: 2 additions & 0 deletions e2e/tests/interchain_accounts/gov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ func (s *InterchainAccountsGovTestSuite) TestInterchainAccountsGovIntegration()
s.ExecuteAndPassGovV1Proposal(ctx, msgSendTx, chainA, controllerAccount)
})

s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB)) // wait for the ica tx to be relayed

t.Run("verify tokens transferred", func(t *testing.T) {
balance, err := query.Balance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom)
s.Require().NoError(err)
Expand Down
129 changes: 44 additions & 85 deletions modules/apps/27-interchain-accounts/host/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ package keeper_test
import (
"fmt"
"strings"
"time"

"github.com/cosmos/gogoproto/proto"

sdkmath "cosmossdk.io/math"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
Expand Down Expand Up @@ -44,27 +45,18 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID)
suite.Require().True(found)

// Populate the gov keeper in advance with an active proposal
testProposal := &govtypes.TextProposal{
Title: "IBC Gov Proposal",
Description: "tokens for all!",
}

proposalMsg, err := govv1.NewLegacyContent(testProposal, interchainAccountAddr)
suite.Require().NoError(err)

proposal, err := govv1.NewProposal([]sdk.Msg{proposalMsg}, govtypes.DefaultStartingProposalID, suite.chainA.GetContext().BlockTime(), suite.chainA.GetContext().BlockTime(), "test proposal", "title", "Description", sdk.AccAddress(interchainAccountAddr), false)
proposal, err := govtypesv1.NewProposal([]sdk.Msg{getTestProposalMessage()}, govtypesv1.DefaultStartingProposalID, time.Now(), time.Now().Add(time.Hour), "test proposal", "title", "Description", sdk.AccAddress(interchainAccountAddr), false)
suite.Require().NoError(err)

err = suite.chainB.GetSimApp().GovKeeper.SetProposal(suite.chainB.GetContext(), proposal)
suite.Require().NoError(err)
err = suite.chainB.GetSimApp().GovKeeper.ActivateVotingPeriod(suite.chainB.GetContext(), proposal)
suite.Require().NoError(err)

msg := &govtypes.MsgVote{
ProposalId: govtypes.DefaultStartingProposalID,
msg := &govtypesv1.MsgVote{
ProposalId: govtypesv1.DefaultStartingProposalID,
Voter: interchainAccountAddr,
Option: govtypes.OptionYes,
Option: govtypesv1.OptionYes,
}

data, err := icatypes.SerializeCosmosTx(suite.chainA.GetSimApp().AppCodec(), []proto.Message{msg}, encoding)
Expand Down Expand Up @@ -172,25 +164,14 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
nil,
},
{
"interchain account successfully executes govtypes.MsgSubmitProposal",
"interchain account successfully executes govtypesv1.MsgSubmitProposal",
func(encoding string) {
interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID)
suite.Require().True(found)

testProposal := &govtypes.TextProposal{
Title: "IBC Gov Proposal",
Description: "tokens for all!",
}

protoAny, err := codectypes.NewAnyWithValue(testProposal)
msg, err := govtypesv1.NewMsgSubmitProposal([]sdk.Msg{}, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100000))), interchainAccountAddr, "metadata", "title", "summary", false)
suite.Require().NoError(err)

msg := &govtypes.MsgSubmitProposal{
Content: protoAny,
InitialDeposit: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100000))),
Proposer: interchainAccountAddr,
}

data, err := icatypes.SerializeCosmosTx(suite.chainA.GetSimApp().AppCodec(), []proto.Message{msg}, encoding)
suite.Require().NoError(err)

Expand All @@ -207,32 +188,23 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
nil,
},
{
"interchain account successfully executes govtypes.MsgVote",
"interchain account successfully executes govtypesv1.MsgVote",
func(encoding string) {
interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID)
suite.Require().True(found)

// Populate the gov keeper in advance with an active proposal
testProposal := &govtypes.TextProposal{
Title: "IBC Gov Proposal",
Description: "tokens for all!",
}

proposalMsg, err := govv1.NewLegacyContent(testProposal, interchainAccountAddr)
suite.Require().NoError(err)

proposal, err := govv1.NewProposal([]sdk.Msg{proposalMsg}, govtypes.DefaultStartingProposalID, suite.chainA.GetContext().BlockTime(), suite.chainA.GetContext().BlockTime(), "test proposal", "title", "description", sdk.AccAddress(interchainAccountAddr), false)
proposal, err := govtypesv1.NewProposal([]sdk.Msg{getTestProposalMessage()}, govtypesv1.DefaultStartingProposalID, time.Now(), time.Now().Add(time.Hour), "test proposal", "title", "Description", sdk.AccAddress(interchainAccountAddr), false)
suite.Require().NoError(err)

err = suite.chainB.GetSimApp().GovKeeper.SetProposal(suite.chainB.GetContext(), proposal)
suite.Require().NoError(err)
err = suite.chainB.GetSimApp().GovKeeper.ActivateVotingPeriod(suite.chainB.GetContext(), proposal)
suite.Require().NoError(err)

msg := &govtypes.MsgVote{
ProposalId: govtypes.DefaultStartingProposalID,
msg := &govtypesv1.MsgVote{
ProposalId: govtypesv1.DefaultStartingProposalID,
Voter: interchainAccountAddr,
Option: govtypes.OptionYes,
Option: govtypesv1.OptionYes,
}

data, err := icatypes.SerializeCosmosTx(suite.chainA.GetSimApp().AppCodec(), []proto.Message{msg}, encoding)
Expand Down Expand Up @@ -601,16 +573,7 @@ func (suite *KeeperTestSuite) TestJSONOnRecvPacket() {
{
"interchain account successfully executes an arbitrary message type using the * (allow all message types) param",
func(icaAddress string) {
// Populate the gov keeper in advance with an active proposal
testProposal := &govtypes.TextProposal{
Title: "IBC Gov Proposal",
Description: "tokens for all!",
}

proposalMsg, err := govv1.NewLegacyContent(testProposal, interchainAccountAddr)
suite.Require().NoError(err)

proposal, err := govv1.NewProposal([]sdk.Msg{proposalMsg}, govtypes.DefaultStartingProposalID, suite.chainA.GetContext().BlockTime(), suite.chainA.GetContext().BlockTime(), "test proposal", "title", "Description", sdk.AccAddress(interchainAccountAddr), false)
proposal, err := govtypesv1.NewProposal([]sdk.Msg{getTestProposalMessage()}, govtypesv1.DefaultStartingProposalID, suite.chainA.GetContext().BlockTime(), suite.chainA.GetContext().BlockTime(), "test proposal", "title", "Description", sdk.AccAddress(interchainAccountAddr), false)
suite.Require().NoError(err)

err = suite.chainB.GetSimApp().GovKeeper.SetProposal(suite.chainB.GetContext(), proposal)
Expand All @@ -621,7 +584,7 @@ func (suite *KeeperTestSuite) TestJSONOnRecvPacket() {
msgBytes := []byte(`{
"messages": [
{
"@type": "/cosmos.gov.v1beta1.MsgVote",
"@type": "/cosmos.gov.v1.MsgVote",
"voter": "` + icaAddress + `",
"proposal_id": 1,
"option": 1
Expand Down Expand Up @@ -668,17 +631,17 @@ func (suite *KeeperTestSuite) TestJSONOnRecvPacket() {
nil,
},
{
"interchain account successfully executes govtypes.MsgSubmitProposal",
"interchain account successfully executes govtypesv1.MsgSubmitProposal",
func(icaAddress string) {
msgBytes := []byte(`{
"messages": [
{
"@type": "/cosmos.gov.v1beta1.MsgSubmitProposal",
"content": {
"@type": "/cosmos.gov.v1beta1.TextProposal",
"title": "IBC Gov Proposal",
"description": "tokens for all!"
},
"@type": "/cosmos.gov.v1.MsgSubmitProposal",
"messages": [],
"metadata": "ipfs://CID",
"title": "IBC Gov Proposal",
"summary": "tokens for all!",
"expedited": false,
"initial_deposit": [{ "denom": "stake", "amount": "100000" }],
"proposer": "` + icaAddress + `"
}
Expand All @@ -691,24 +654,15 @@ func (suite *KeeperTestSuite) TestJSONOnRecvPacket() {
"data":` + byteArrayString + `
}`)

params := types.NewParams(true, []string{sdk.MsgTypeURL((*govtypes.MsgSubmitProposal)(nil))})
params := types.NewParams(true, []string{sdk.MsgTypeURL((*govtypesv1.MsgSubmitProposal)(nil))})
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params)
},
nil,
},
{
"interchain account successfully executes govtypes.MsgVote",
"interchain account successfully executes govtypesv1.MsgVote",
func(icaAddress string) {
// Populate the gov keeper in advance with an active proposal
testProposal := &govtypes.TextProposal{
Title: "IBC Gov Proposal",
Description: "tokens for all!",
}

proposalMsg, err := govv1.NewLegacyContent(testProposal, interchainAccountAddr)
suite.Require().NoError(err)

proposal, err := govv1.NewProposal([]sdk.Msg{proposalMsg}, govtypes.DefaultStartingProposalID, suite.chainA.GetContext().BlockTime(), suite.chainA.GetContext().BlockTime(), "test proposal", "title", "description", sdk.AccAddress(interchainAccountAddr), false)
proposal, err := govtypesv1.NewProposal([]sdk.Msg{getTestProposalMessage()}, govtypesv1.DefaultStartingProposalID, suite.chainA.GetContext().BlockTime(), suite.chainA.GetContext().BlockTime(), "test proposal", "title", "Description", sdk.AccAddress(interchainAccountAddr), false)
suite.Require().NoError(err)

err = suite.chainB.GetSimApp().GovKeeper.SetProposal(suite.chainB.GetContext(), proposal)
Expand All @@ -719,7 +673,7 @@ func (suite *KeeperTestSuite) TestJSONOnRecvPacket() {
msgBytes := []byte(`{
"messages": [
{
"@type": "/cosmos.gov.v1beta1.MsgVote",
"@type": "/cosmos.gov.v1.MsgVote",
"voter": "` + icaAddress + `",
"proposal_id": 1,
"option": 1
Expand All @@ -733,34 +687,34 @@ func (suite *KeeperTestSuite) TestJSONOnRecvPacket() {
"data":` + byteArrayString + `
}`)

params := types.NewParams(true, []string{sdk.MsgTypeURL((*govtypes.MsgVote)(nil))})
params := types.NewParams(true, []string{sdk.MsgTypeURL((*govtypesv1.MsgVote)(nil))})
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params)
},
nil,
},
{
"interchain account successfully executes govtypes.MsgSubmitProposal, govtypes.MsgDeposit, and then govtypes.MsgVote sequentially",
"interchain account successfully executes govtypesv1.MsgSubmitProposal, govtypesv1.MsgDeposit, and then govtypesv1.MsgVote sequentially",
func(icaAddress string) {
msgBytes := []byte(`{
"messages": [
{
"@type": "/cosmos.gov.v1beta1.MsgSubmitProposal",
"content": {
"@type": "/cosmos.gov.v1beta1.TextProposal",
"title": "IBC Gov Proposal",
"description": "tokens for all!"
},
"@type": "/cosmos.gov.v1.MsgSubmitProposal",
"messages": [],
"metadata": "ipfs://CID",
"title": "IBC Gov Proposal",
"summary": "tokens for all!",
"expedited": false,
"initial_deposit": [{ "denom": "stake", "amount": "100000" }],
"proposer": "` + icaAddress + `"
},
{
"@type": "/cosmos.gov.v1beta1.MsgDeposit",
"@type": "/cosmos.gov.v1.MsgDeposit",
"proposal_id": 1,
"depositor": "` + icaAddress + `",
"amount": [{ "denom": "stake", "amount": "10000000" }]
},
{
"@type": "/cosmos.gov.v1beta1.MsgVote",
"@type": "/cosmos.gov.v1.MsgVote",
"voter": "` + icaAddress + `",
"proposal_id": 1,
"option": 1
Expand All @@ -774,7 +728,7 @@ func (suite *KeeperTestSuite) TestJSONOnRecvPacket() {
"data":` + byteArrayString + `
}`)

params := types.NewParams(true, []string{sdk.MsgTypeURL((*govtypes.MsgSubmitProposal)(nil)), sdk.MsgTypeURL((*govtypes.MsgDeposit)(nil)), sdk.MsgTypeURL((*govtypes.MsgVote)(nil))})
params := types.NewParams(true, []string{sdk.MsgTypeURL((*govtypesv1.MsgSubmitProposal)(nil)), sdk.MsgTypeURL((*govtypesv1.MsgDeposit)(nil)), sdk.MsgTypeURL((*govtypesv1.MsgVote)(nil))})
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params)
},
nil,
Expand Down Expand Up @@ -946,3 +900,8 @@ func (suite *KeeperTestSuite) fundICAWallet(ctx sdk.Context, portID string, amou
suite.Require().NotEmpty(res)
suite.Require().NoError(err)
}

func getTestProposalMessage() sdk.Msg {
_, _, addr := testdata.KeyTestPubAddr()
return banktypes.NewMsgSend(authtypes.NewModuleAddress("gov"), addr, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(1000))))
}
13 changes: 0 additions & 13 deletions modules/apps/callbacks/testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ import (
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/cosmos/cosmos-sdk/x/group"
groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper"
groupmodule "github.com/cosmos/cosmos-sdk/x/group/module"
Expand All @@ -93,7 +92,6 @@ import (
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
Expand Down Expand Up @@ -414,14 +412,6 @@ func NewSimApp(
// Real applications should not use the mock ContractKeeper
app.MockContractKeeper = NewContractKeeper(memKeys[ibcmock.MemStoreKey])

// Register the proposal types
// Deprecated: Avoid adding new handlers, instead use the new proposal flow
// by granting the governance module the right to execute the message.
// See: https://docs.cosmos.network/main/modules/gov#proposal-messages
govRouter := govv1beta1.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper))

govConfig := govtypes.DefaultConfig()
/*
Example of setting gov params:
Expand All @@ -432,9 +422,6 @@ func NewSimApp(
app.StakingKeeper, app.DistrKeeper, app.MsgServiceRouter(), govConfig, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// Set legacy router for backwards compatibility with gov v1beta1
govKeeper.SetLegacyRouter(govRouter)

app.GovKeeper = *govKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// register the governance hooks
Expand Down
12 changes: 0 additions & 12 deletions modules/light-clients/08-wasm/testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ import (
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/cosmos/cosmos-sdk/x/group"
groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper"
groupmodule "github.com/cosmos/cosmos-sdk/x/group/module"
Expand All @@ -95,7 +94,6 @@ import (
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
Expand Down Expand Up @@ -418,13 +416,6 @@ func NewSimApp(
appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), ibctm.NewConsensusHost(app.StakingKeeper), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// Register the proposal types
// Deprecated: Avoid adding new handlers, instead use the new proposal flow
// by granting the governance module the right to execute the message.
// See: https://docs.cosmos.network/main/modules/gov#proposal-messages
govRouter := govv1beta1.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper))
govConfig := govtypes.DefaultConfig()
/*
Example of setting gov params:
Expand All @@ -435,9 +426,6 @@ func NewSimApp(
app.StakingKeeper, app.DistrKeeper, app.MsgServiceRouter(), govConfig, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// Set legacy router for backwards compatibility with gov v1beta1
govKeeper.SetLegacyRouter(govRouter)

app.GovKeeper = *govKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// register the governance hooks
Expand Down
Loading

0 comments on commit 07316fa

Please sign in to comment.