Skip to content

Commit

Permalink
fix: allow zero amount of coin in x/collection Query/Balance (#953)
Browse files Browse the repository at this point in the history
* Allow zero amount of coin

* Update CHANGELOG.md

* Update the test
  • Loading branch information
0Tech authored Apr 7, 2023
1 parent e5d7b04 commit 15314e4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/foundation) [\#922](https://github.com/line/lbm-sdk/pull/922) Propagate events in x/foundation through sdk.Results
* (x/foundation) [\#946](https://github.com/line/lbm-sdk/pull/946) Fix broken x/foundation invariant on treasury
* (x/foundation) [\#947](https://github.com/line/lbm-sdk/pull/947) Unpack proposals in x/foundation import-genesis
* (x/collection) [\#953](https://github.com/line/lbm-sdk/pull/953) Allow zero amount of coin in x/collection Query/Balance

### Removed

Expand Down
5 changes: 4 additions & 1 deletion x/collection/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ func (s queryServer) Balance(c context.Context, req *collection.QueryBalanceRequ

ctx := sdk.UnwrapSDKContext(c)
balance := s.keeper.GetBalance(ctx, req.ContractId, addr, req.TokenId)
coin := collection.NewCoin(req.TokenId, balance)
coin := collection.Coin{
TokenId: req.TokenId,
Amount: balance,
}

return &collection.QueryBalanceResponse{Balance: coin}, nil
}
Expand Down
18 changes: 17 additions & 1 deletion x/collection/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,23 @@ func (s *KeeperTestSuite) TestQueryBalance() {
tokenID: tokenID,
valid: true,
postTest: func(res *collection.QueryBalanceResponse) {
expected := collection.NewCoin(tokenID, s.balance)
expected := collection.Coin{
TokenId: tokenID,
Amount: s.balance,
}
s.Require().Equal(expected, res.Balance)
},
},
"valid request with zero amount": {
contractID: s.contractID,
address: s.vendor,
tokenID: "deadbeefdeadbeef",
valid: true,
postTest: func(res *collection.QueryBalanceResponse) {
expected := collection.Coin{
TokenId: "deadbeefdeadbeef",
Amount: sdk.ZeroInt(),
}
s.Require().Equal(expected, res.Balance)
},
},
Expand Down

0 comments on commit 15314e4

Please sign in to comment.