From 6626915ca8c0189a58ebb74e80bcea20daa16bd1 Mon Sep 17 00:00:00 2001 From: Derrick Lee Date: Thu, 29 Sep 2022 12:28:10 -0700 Subject: [PATCH] Return empty coins instead of error when query x/hard total supplied and total borrowed (#1319) --- x/hard/keeper/grpc_query.go | 6 ++++-- x/hard/keeper/grpc_query_test.go | 20 ++++++++++++++++++++ x/hard/keeper/querier.go | 4 ++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/x/hard/keeper/grpc_query.go b/x/hard/keeper/grpc_query.go index a9a77657..22e43fc4 100644 --- a/x/hard/keeper/grpc_query.go +++ b/x/hard/keeper/grpc_query.go @@ -373,7 +373,8 @@ func (s queryServer) TotalBorrowed(ctx context.Context, req *types.QueryTotalBor borrowedCoins, found := s.keeper.GetBorrowedCoins(sdkCtx) if !found { - return nil, types.ErrBorrowedCoinsNotFound + // Use empty coins instead of returning an error + borrowedCoins = sdk.NewCoins() } // If user specified a denom only return coins of that denom type @@ -395,7 +396,8 @@ func (s queryServer) TotalDeposited(ctx context.Context, req *types.QueryTotalDe suppliedCoins, found := s.keeper.GetSuppliedCoins(sdkCtx) if !found { - return nil, types.ErrSuppliedCoinsNotFound + // Use empty coins instead of returning an error + suppliedCoins = sdk.NewCoins() } // If user specified a denom only return coins of that denom type diff --git a/x/hard/keeper/grpc_query_test.go b/x/hard/keeper/grpc_query_test.go index a330c3be..1a0faf67 100644 --- a/x/hard/keeper/grpc_query_test.go +++ b/x/hard/keeper/grpc_query_test.go @@ -364,6 +364,26 @@ func (suite *grpcQueryTestSuite) TestGrpcQueryTotalDeposited() { }, totalDeposited) } +func (suite *grpcQueryTestSuite) TestGrpcQueryTotalDeposited_Empty() { + totalDeposited, err := suite.queryServer.TotalDeposited(sdk.WrapSDKContext(suite.ctx), &types.QueryTotalDepositedRequest{}) + suite.Require().NoError(err) + + suite.Equal(&types.QueryTotalDepositedResponse{ + SuppliedCoins: cs(), + }, totalDeposited) +} + +func (suite *grpcQueryTestSuite) TestGrpcQueryTotalDeposited_Denom_Empty() { + totalDeposited, err := suite.queryServer.TotalDeposited(sdk.WrapSDKContext(suite.ctx), &types.QueryTotalDepositedRequest{ + Denom: "bnb", + }) + suite.Require().NoError(err) + + suite.Equal(&types.QueryTotalDepositedResponse{ + SuppliedCoins: cs(), + }, totalDeposited) +} + func (suite *grpcQueryTestSuite) TestGrpcQueryTotalDeposited_Denom() { suite.addDeposits() diff --git a/x/hard/keeper/querier.go b/x/hard/keeper/querier.go index 3c33b08b..810e54cd 100644 --- a/x/hard/keeper/querier.go +++ b/x/hard/keeper/querier.go @@ -350,7 +350,7 @@ func queryGetTotalBorrowed(ctx sdk.Context, req abci.RequestQuery, k Keeper, leg borrowedCoins, found := k.GetBorrowedCoins(ctx) if !found { - return nil, types.ErrBorrowedCoinsNotFound + borrowedCoins = sdk.NewCoins() } // If user specified a denom only return coins of that denom type @@ -375,7 +375,7 @@ func queryGetTotalDeposited(ctx sdk.Context, req abci.RequestQuery, k Keeper, le suppliedCoins, found := k.GetSuppliedCoins(ctx) if !found { - return nil, types.ErrSuppliedCoinsNotFound + suppliedCoins = sdk.NewCoins() } // If user specified a denom only return coins of that denom type