Skip to content

Commit

Permalink
Add upgrade integration-tests checking gov proposal migration v45->v47 (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
ysv authored Sep 25, 2023
1 parent 1d83e35 commit fb8b046
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 1 deletion.
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

0 comments on commit fb8b046

Please sign in to comment.