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

Add upgrade integration-tests checking gov proposal migration v45->v47 #655

Merged
merged 8 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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: 1 addition & 1 deletion integration-tests/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func NewChain(grpcClient *grpc.ClientConn, rpcClient *rpchttp.HTTP, chainSetting
WithKeyring(newConcurrentSafeKeyring(keyring.NewInMemory(encodingConfig.Codec))).
WithBroadcastMode(flags.BroadcastSync).
WithGRPCClient(grpcClient).
WithRPCClient(rpcClient).
WithClient(rpcClient).
WithAwaitTx(true)

chainCtx := NewChainContext(encodingConfig, clientCtx, chainSettings)
Expand Down
128 changes: 128 additions & 0 deletions integration-tests/upgrade/gov_migration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
//go:build integrationtests

package upgrade

import (
"testing"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/stretchr/testify/require"

integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests"
"github.com/CoreumFoundation/coreum/v3/pkg/client"
)

var (
fundAmount = sdkmath.NewInt(1_000_000)
missingDepositAmount = sdkmath.NewInt(10)
)

type govMigrationTest struct {
onDepositProposalID uint64
proposer sdk.AccAddress
communityPoolRecipient sdk.AccAddress
}

func (gmt *govMigrationTest) Before(t *testing.T) {
ctx, chain := integrationtests.NewCoreumTestingContext(t)
requireT := require.New(t)

// Fund community pool.
communityPoolFunder := chain.GenAccount()
msgFundCommunityPool := &distributiontypes.MsgFundCommunityPool{
Amount: sdk.NewCoins(chain.NewCoin(fundAmount)),
Depositor: communityPoolFunder.String(),
}

chain.FundAccountWithOptions(ctx, t, communityPoolFunder,
integrationtests.BalancesOptions{
Messages: []sdk.Msg{
msgFundCommunityPool,
},
Amount: fundAmount,
})
_, err := client.BroadcastTx(
ctx,
chain.ClientContext.WithFromAddress(communityPoolFunder),
chain.TxFactory().WithGas(chain.GasLimitByMsgs(msgFundCommunityPool)),
msgFundCommunityPool,
)
requireT.NoError(err)

// Propose community pool spend but keep proposal in deposit status.
proposer := chain.GenAccount()
proposerBalance, err := chain.LegacyGovernance.ComputeProposerBalance(ctx)
requireT.NoError(err)
chain.Faucet.FundAccounts(ctx, t, integrationtests.NewFundedAccount(proposer, proposerBalance))

communityPoolRecipient := chain.GenAccount()
proposalMsg, err := chain.LegacyGovernance.NewMsgSubmitProposalV1Beta1(
ctx,
proposer,
&distributiontypes.CommunityPoolSpendProposal{ //nolint:staticcheck
Title: "Community pool spend created before upgrade",
Description: "Community pool spend created before upgrade",
Recipient: communityPoolRecipient.String(),
Amount: sdk.NewCoins(chain.NewCoin(fundAmount)),
},
)

// Subtract 10udevcore from initial deposit amount, so proposal stays on deposit status.
proposalMsg.InitialDeposit = proposalMsg.InitialDeposit.Sub(chain.NewCoin(missingDepositAmount))
requireT.NoError(err)
proposalID, err := chain.LegacyGovernance.Propose(ctx, t, proposalMsg)
requireT.NoError(err)

proposal, err := chain.LegacyGovernance.GetProposal(ctx, proposalID)
requireT.NoError(err)
requireT.Equal(govtypesv1beta1.StatusDepositPeriod, proposal.Status)

gmt.onDepositProposalID = proposalID
gmt.proposer = proposer
gmt.communityPoolRecipient = communityPoolRecipient
}

func (gmt *govMigrationTest) After(t *testing.T) {
ctx, chain := integrationtests.NewCoreumTestingContext(t)
requireT := require.New(t)

proposal, err := chain.Governance.GetProposal(ctx, gmt.onDepositProposalID)
requireT.NoError(err)
requireT.Equal(govtypesv1.StatusDepositPeriod, proposal.Status)
// Proposer could be set as optional step during the upgrade, but we decided to not implement it
// since proposal fails anyway.
requireT.Equal("", proposal.Proposer)

depositor := chain.GenAccount()
requireT.NoError(err)

chain.FundAccountWithOptions(ctx, t, depositor, integrationtests.BalancesOptions{
Messages: []sdk.Msg{&govtypesv1.MsgDeposit{}},
Amount: missingDepositAmount,
})

depositMsg := govtypesv1.NewMsgDeposit(depositor, gmt.onDepositProposalID, sdk.NewCoins(chain.NewCoin(missingDepositAmount)))
_, err = client.BroadcastTx(
ctx,
chain.ClientContext.WithFromAddress(depositor),
chain.TxFactory().WithGas(chain.GasLimitByMsgs(depositMsg)),
depositMsg,
)
requireT.NoError(err)

proposal, err = chain.Governance.GetProposal(ctx, gmt.onDepositProposalID)
requireT.NoError(err)
requireT.Equal(govtypesv1.StatusVotingPeriod, proposal.Status)

requireT.NoError(chain.Governance.VoteAll(ctx, govtypesv1.OptionYes, gmt.onDepositProposalID))

proposalStatus, err := chain.Governance.WaitForVotingToFinalize(ctx, gmt.onDepositProposalID)
requireT.NoError(err)
requireT.Equal(govtypesv1.StatusFailed, proposalStatus)
// Logs produced inside cored for such a proposal:
// "proposal tallied module=x/gov proposal=1 results="passed, but msg 0 (/cosmos.gov.v1.MsgExecLegacyContent) failed on execution: distribution: no handler exists for proposal type"
}
1 change: 1 addition & 0 deletions integration-tests/upgrade/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func upgradeV3(t *testing.T) {
&paramsMigrationTest{},
&wasmMigrationTest{},
&ibcUpgradeTest{},
&govMigrationTest{},
}

for _, test := range tests {
Expand Down