From 8911d8dcb4d122576ed2c5fa276b2771edf11dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 25 Aug 2022 12:47:50 +0200 Subject: [PATCH] feat: add gov proposal execution for e2e testsuite (#2114) * add gov prop execution command * add godoc --- e2e/testsuite/grpc_query.go | 14 +++++++++++++ e2e/testsuite/testsuite.go | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/e2e/testsuite/grpc_query.go b/e2e/testsuite/grpc_query.go index e3265bc1c86..97e33805ce4 100644 --- a/e2e/testsuite/grpc_query.go +++ b/e2e/testsuite/grpc_query.go @@ -3,6 +3,7 @@ package testsuite import ( "context" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" intertxtypes "github.com/cosmos/interchain-accounts/x/inter-tx/types" "github.com/strangelove-ventures/ibctest/chain/cosmos" "github.com/strangelove-ventures/ibctest/ibc" @@ -88,3 +89,16 @@ func (s *E2ETestSuite) QueryCounterPartyPayee(ctx context.Context, chain ibc.Cha } return res.CounterpartyPayee, nil } + +// QueryProposal queries the governance proposal on the given chain with the given proposal ID. +func (s *E2ETestSuite) QueryProposal(ctx context.Context, chain ibc.Chain, proposalID uint64) (govtypes.Proposal, error) { + queryClient := s.GetChainGRCPClients(chain).GovQueryClient + res, err := queryClient.Proposal(ctx, &govtypes.QueryProposalRequest{ + ProposalId: proposalID, + }) + if err != nil { + return govtypes.Proposal{}, err + } + + return res.Proposal, nil +} diff --git a/e2e/testsuite/testsuite.go b/e2e/testsuite/testsuite.go index 4f52cd3961d..e74055697c3 100644 --- a/e2e/testsuite/testsuite.go +++ b/e2e/testsuite/testsuite.go @@ -7,6 +7,7 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" intertxtypes "github.com/cosmos/interchain-accounts/x/inter-tx/types" dockerclient "github.com/docker/docker/client" "github.com/strangelove-ventures/ibctest" @@ -58,6 +59,9 @@ type GRPCClients struct { ChannelQueryClient channeltypes.QueryClient FeeQueryClient feetypes.QueryClient ICAQueryClient intertxtypes.QueryClient + + // SDK query clients + GovQueryClient govtypes.QueryClient } // path is a pairing of two chains which will be used in a test. @@ -295,6 +299,7 @@ func (s *E2ETestSuite) initGRPCClients(chain *cosmos.CosmosChain) { ChannelQueryClient: channeltypes.NewQueryClient(grpcConn), FeeQueryClient: feetypes.NewQueryClient(grpcConn), ICAQueryClient: intertxtypes.NewQueryClient(grpcConn), + GovQueryClient: govtypes.NewQueryClient(grpcConn), } } @@ -374,3 +379,38 @@ func GetNativeChainBalance(ctx context.Context, chain ibc.Chain, user *ibc.Walle } return bal, nil } + +// ExecuteGovProposal submits the given governance proposal using the provided user and uses all validators to vote yes on the proposal. +// It ensure the proposal successfully passes. +func (s *E2ETestSuite) ExecuteGovProposal(ctx context.Context, chain *cosmos.CosmosChain, user *ibc.Wallet, content govtypes.Content) { + sender, err := sdk.AccAddressFromBech32(user.Bech32Address(chain.Config().Bech32Prefix)) + s.Require().NoError(err) + + msgSubmitProposal, err := govtypes.NewMsgSubmitProposal(content, sdk.NewCoins(sdk.NewCoin(chain.Config().Denom, govtypes.DefaultMinDepositTokens)), sender) + s.Require().NoError(err) + + txResp, err := s.BroadcastMessages(ctx, chain, user, msgSubmitProposal) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + + // TODO: replace with parsed proposal ID from MsgSubmitProposalResponse + // https://github.com/cosmos/ibc-go/issues/2122 + + proposal, err := s.QueryProposal(ctx, chain, 1) + s.Require().NoError(err) + s.Require().Equal(govtypes.StatusVotingPeriod, proposal.Status) + + err = chain.VoteOnProposalAllValidators(ctx, "1", ibc.ProposalVoteYes) + s.Require().NoError(err) + + // ensure voting period has not passed before validators finished voting + proposal, err = s.QueryProposal(ctx, chain, 1) + s.Require().NoError(err) + s.Require().Equal(govtypes.StatusVotingPeriod, proposal.Status) + + time.Sleep(time.Second * 30) // pass proposal + + proposal, err = s.QueryProposal(ctx, chain, 1) + s.Require().NoError(err) + s.Require().Equal(govtypes.StatusPassed, proposal.Status) +}