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

feat: add gov proposal execution for e2e testsuite #2114

Merged
merged 3 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
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
chatton marked this conversation as resolved.
Show resolved Hide resolved

proposal, err = s.QueryProposal(ctx, chain, 1)
s.Require().NoError(err)
s.Require().Equal(govtypes.StatusPassed, proposal.Status)
}