mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-24 15:25:18 +00:00
Return empty coins instead of error when query x/hard total supplied and total borrowed (#1319)
This commit is contained in:
parent
b0932f7062
commit
6626915ca8
@ -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
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user