Skip to content

Commit

Permalink
fix: query handlers are ignoring accumulate flag
Browse files Browse the repository at this point in the history
  • Loading branch information
charymalloju committed Jan 9, 2025
1 parent decc8ec commit e84608f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
16 changes: 12 additions & 4 deletions modules/core/02-client/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ func (q *queryServer) ClientStates(ctx context.Context, req *types.QueryClientSt
return false, err
}

identifiedClient := types.NewIdentifiedClientState(clientID, clientState)
clientStates = append(clientStates, identifiedClient)
if accumulate {
identifiedClient := types.NewIdentifiedClientState(clientID, clientState)
clientStates = append(clientStates, identifiedClient)
}
return true, nil
})
if err != nil {
Expand Down Expand Up @@ -184,7 +186,10 @@ func (q *queryServer) ConsensusStates(ctx context.Context, req *types.QueryConse
return false, err
}

consensusStates = append(consensusStates, types.NewConsensusStateWithHeight(height, consensusState))
if accumulate {
consensusStates = append(consensusStates, types.NewConsensusStateWithHeight(height, consensusState))
}

return true, nil
})
if err != nil {
Expand Down Expand Up @@ -221,7 +226,10 @@ func (q *queryServer) ConsensusStateHeights(ctx context.Context, req *types.Quer
return false, err
}

consensusStateHeights = append(consensusStateHeights, height)
if accumulate {
consensusStateHeights = append(consensusStateHeights, height)
}

return true, nil
})
if err != nil {
Expand Down
31 changes: 30 additions & 1 deletion modules/core/02-client/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,15 @@ func (suite *KeeperTestSuite) TestQueryClientStates() {
msg string
malleate func()
expErr error
expTotal int
}{
{
"req is nil",
func() {
req = nil
},
status.Error(codes.InvalidArgument, "empty request"),
0,
},
{
"empty pagination",
Expand All @@ -131,6 +133,7 @@ func (suite *KeeperTestSuite) TestQueryClientStates() {
req = &types.QueryClientStatesRequest{}
},
nil,
0,
},
{
"success",
Expand All @@ -157,6 +160,31 @@ func (suite *KeeperTestSuite) TestQueryClientStates() {
}
},
nil,
2,
},
{
"success request with pagination limit",
func() {
path1 := ibctesting.NewPath(suite.chainA, suite.chainB)
path1.SetupClients()

path2 := ibctesting.NewPath(suite.chainA, suite.chainB)
path2.SetupClients()

clientStateA1 := path1.EndpointA.GetClientState()

idcs := types.NewIdentifiedClientState(path1.EndpointA.ClientID, clientStateA1)

expClientStates = types.IdentifiedClientStates{idcs}.Sort()
req = &types.QueryClientStatesRequest{
Pagination: &query.PageRequest{
Limit: 1,
CountTotal: true,
},
}
},
nil,
2,
},
}

Expand All @@ -174,7 +202,8 @@ func (suite *KeeperTestSuite) TestQueryClientStates() {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(expClientStates.Sort(), res.ClientStates)
suite.Require().Equal(len(expClientStates), int(res.Pagination.Total))
suite.Require().Equal(tc.expTotal, int(res.Pagination.Total))

} else {
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expErr)
Expand Down

0 comments on commit e84608f

Please sign in to comment.