Fix committee Votes grpc query response (#1156)

* Append votes to queryResults, remove unused GetVotesByProposal

* Add Votes grpc_query test
This commit is contained in:
Derrick Lee 2022-02-01 20:16:53 -08:00 committed by GitHub
parent 4704817ce8
commit 9f73659274
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 14 deletions

View File

@ -36,6 +36,16 @@ func (suite *grpcQueryTestSuite) TestVote() {
suite.Require().Equal(vote.ProposalID, res.ProposalID) suite.Require().Equal(vote.ProposalID, res.ProposalID)
suite.Require().Equal(vote.VoteType, res.VoteType) suite.Require().Equal(vote.VoteType, res.VoteType)
suite.Require().Equal(vote.Voter.String(), res.Voter) suite.Require().Equal(vote.Voter.String(), res.Voter)
queryRes, err := queryClient.Votes(context.Background(), &types.QueryVotesRequest{
ProposalId: vote.ProposalID,
})
suite.Require().NoError(err)
suite.Require().Len(queryRes.Votes, 1)
suite.Require().Equal(vote.ProposalID, queryRes.Votes[0].ProposalID)
suite.Require().Equal(vote.VoteType, queryRes.Votes[0].VoteType)
suite.Require().Equal(vote.Voter.String(), queryRes.Votes[0].Voter)
} }
func TestGrpcQueryTestSuite(t *testing.T) { func TestGrpcQueryTestSuite(t *testing.T) {

View File

@ -66,14 +66,15 @@ func (s queryServer) Proposals(c context.Context, req *types.QueryProposalsReque
ctx := sdk.UnwrapSDKContext(c) ctx := sdk.UnwrapSDKContext(c)
proposals := s.keeper.GetProposalsByCommittee(ctx, req.CommitteeId) proposals := s.keeper.GetProposalsByCommittee(ctx, req.CommitteeId)
proposalsResp := types.QueryProposalsResponse{ var proposalsResp []types.QueryProposalResponse
Proposals: make([]types.QueryProposalResponse, len(proposals)),
} for _, proposal := range proposals {
for i, proposal := range proposals { proposalsResp = append(proposalsResp, s.proposalResponseFromProposal(proposal))
proposalsResp.Proposals[i] = s.proposalResponseFromProposal(proposal)
} }
return &proposalsResp, nil return &types.QueryProposalsResponse{
Proposals: proposalsResp,
}, nil
} }
// Proposal implements the Query/Proposal gRPC method // Proposal implements the Query/Proposal gRPC method
@ -113,13 +114,6 @@ func (s queryServer) Votes(c context.Context, req *types.QueryVotesRequest) (*ty
} }
ctx := sdk.UnwrapSDKContext(c) ctx := sdk.UnwrapSDKContext(c)
votes := s.keeper.GetVotesByProposal(ctx, req.ProposalId)
votesResp := types.QueryVotesResponse{
Votes: make([]types.QueryVoteResponse, len(votes)),
}
for i, vote := range votes {
votesResp.Votes[i] = s.votesResponseFromVote(vote)
}
var queryResults []types.QueryVoteResponse var queryResults []types.QueryVoteResponse
store := ctx.KVStore(s.keeper.storeKey) store := ctx.KVStore(s.keeper.storeKey)
@ -130,7 +124,7 @@ func (s queryServer) Votes(c context.Context, req *types.QueryVotesRequest) (*ty
return err return err
} }
votes = append(votes, vote) queryResults = append(queryResults, s.votesResponseFromVote(vote))
return nil return nil
}) })
if err != nil { if err != nil {