From fb8b04687180467c7a3c998936daafed3f9fbf33 Mon Sep 17 00:00:00 2001 From: Yaroslav Savchuk Date: Mon, 25 Sep 2023 10:41:17 +0200 Subject: [PATCH] Add upgrade integration-tests checking gov proposal migration v45->v47 (#655) This PR adds upgrade integration-test where we: 1. create gov proposal on deposit status 2. run upgrade of chain 3. deposit funds to previously create proposal 4. vote for the proposal 5. check final proposal status --- integration-tests/chain.go | 2 +- .../upgrade/gov_migration_test.go | 128 ++++++++++++++++++ integration-tests/upgrade/upgrade_test.go | 1 + 3 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 integration-tests/upgrade/gov_migration_test.go diff --git a/integration-tests/chain.go b/integration-tests/chain.go index 8080b8c98..934e1948c 100644 --- a/integration-tests/chain.go +++ b/integration-tests/chain.go @@ -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) diff --git a/integration-tests/upgrade/gov_migration_test.go b/integration-tests/upgrade/gov_migration_test.go new file mode 100644 index 000000000..ac25e300d --- /dev/null +++ b/integration-tests/upgrade/gov_migration_test.go @@ -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" +} diff --git a/integration-tests/upgrade/upgrade_test.go b/integration-tests/upgrade/upgrade_test.go index a31161fab..c2ee077d1 100644 --- a/integration-tests/upgrade/upgrade_test.go +++ b/integration-tests/upgrade/upgrade_test.go @@ -46,6 +46,7 @@ func upgradeV3(t *testing.T) { ¶msMigrationTest{}, &wasmMigrationTest{}, &ibcUpgradeTest{}, + &govMigrationTest{}, } for _, test := range tests {