Return empty coins instead of error when query x/hard total supplied and total borrowed (#1319)

This commit is contained in:
Derrick Lee 2022-09-29 12:28:10 -07:00 committed by GitHub
parent b0932f7062
commit 6626915ca8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 4 deletions

View File

@ -373,7 +373,8 @@ func (s queryServer) TotalBorrowed(ctx context.Context, req *types.QueryTotalBor
borrowedCoins, found := s.keeper.GetBorrowedCoins(sdkCtx) borrowedCoins, found := s.keeper.GetBorrowedCoins(sdkCtx)
if !found { 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 // 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) suppliedCoins, found := s.keeper.GetSuppliedCoins(sdkCtx)
if !found { 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 // If user specified a denom only return coins of that denom type

View File

@ -364,6 +364,26 @@ func (suite *grpcQueryTestSuite) TestGrpcQueryTotalDeposited() {
}, totalDeposited) }, 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() { func (suite *grpcQueryTestSuite) TestGrpcQueryTotalDeposited_Denom() {
suite.addDeposits() suite.addDeposits()

View File

@ -350,7 +350,7 @@ func queryGetTotalBorrowed(ctx sdk.Context, req abci.RequestQuery, k Keeper, leg
borrowedCoins, found := k.GetBorrowedCoins(ctx) borrowedCoins, found := k.GetBorrowedCoins(ctx)
if !found { if !found {
return nil, types.ErrBorrowedCoinsNotFound borrowedCoins = sdk.NewCoins()
} }
// If user specified a denom only return coins of that denom type // 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) suppliedCoins, found := k.GetSuppliedCoins(ctx)
if !found { if !found {
return nil, types.ErrSuppliedCoinsNotFound suppliedCoins = sdk.NewCoins()
} }
// If user specified a denom only return coins of that denom type // If user specified a denom only return coins of that denom type