mirror of
https://github.com/0glabs/0g-chain.git
synced 2025-01-12 16:25:17 +00:00
Fix committee Votes grpc query response (#1156)
* Append votes to queryResults, remove unused GetVotesByProposal * Add Votes grpc_query test
This commit is contained in:
parent
4704817ce8
commit
9f73659274
@ -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) {
|
||||||
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user