Skip to content

Commit

Permalink
feat: add gov proposal execution for e2e testsuite (#2114)
Browse files Browse the repository at this point in the history
* add gov prop execution command

* add godoc
  • Loading branch information
colin-axner authored Aug 25, 2022
1 parent 5de67b2 commit 8911d8d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
14 changes: 14 additions & 0 deletions e2e/testsuite/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
40 changes: 40 additions & 0 deletions e2e/testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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),
}
}

Expand Down Expand Up @@ -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)
}

0 comments on commit 8911d8d

Please sign in to comment.