Skip to content

Commit

Permalink
fix: return nil where the parent not exists in x/collection Query/Par…
Browse files Browse the repository at this point in the history
…ent (#955)

* Do not return error where parent not exists

* Update proto doc

* Add the test

* Update CHANGELOG.md
  • Loading branch information
0Tech authored Apr 7, 2023
1 parent 4fe8ae8 commit d562b43
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (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
* (x/collection) [\#954](https://github.com/line/lbm-sdk/pull/954) Remove duplicated events in x/collection Msg/Modify
* (x/collection) [\#955](https://github.com/line/lbm-sdk/pull/955) Return nil where the parent not exists in x/collection Query/Parent

### Removed

Expand Down
2 changes: 1 addition & 1 deletion docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -10461,7 +10461,7 @@ QueryParentResponse is the response type for the Query/Parent RPC method.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `parent` | [NFT](#lbm.collection.v1.NFT) | | parent is the information of the parent token. if there is no parent for the token, it would return nil. |
| `parent` | [NFT](#lbm.collection.v1.NFT) | | parent is the information of the parent token. |



Expand Down
1 change: 0 additions & 1 deletion proto/lbm/collection/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ message QueryParentRequest {
// QueryParentResponse is the response type for the Query/Parent RPC method.
message QueryParentResponse {
// parent is the information of the parent token.
// if there is no parent for the token, it would return nil.
NFT parent = 1 [(gogoproto.nullable) = false];
}

Expand Down
2 changes: 1 addition & 1 deletion x/collection/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func (s queryServer) Parent(c context.Context, req *collection.QueryParentReques

parent, err := s.keeper.GetParent(ctx, req.ContractId, req.TokenId)
if err != nil {
return nil, err
return nil, nil
}

token, err := s.keeper.GetNFT(ctx, req.ContractId, *parent)
Expand Down
14 changes: 9 additions & 5 deletions x/collection/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,9 +720,18 @@ func (s *KeeperTestSuite) TestQueryParent() {
tokenID: tokenID,
valid: true,
postTest: func(res *collection.QueryParentResponse) {
s.Require().NotNil(res)
s.Require().Equal(collection.NewNFTID(s.nftClassID, 1), res.Parent.TokenId)
},
},
"valid request with no parent": {
contractID: s.contractID,
tokenID: collection.NewNFTID(s.nftClassID, 1),
valid: true,
postTest: func(res *collection.QueryParentResponse) {
s.Require().Nil(res)
},
},
"invalid contract id": {
tokenID: tokenID,
},
Expand All @@ -733,10 +742,6 @@ func (s *KeeperTestSuite) TestQueryParent() {
contractID: s.contractID,
tokenID: collection.NewNFTID("deadbeef", 1),
},
"no parent": {
contractID: s.contractID,
tokenID: collection.NewNFTID(s.nftClassID, 1),
},
}

for name, tc := range testCases {
Expand All @@ -751,7 +756,6 @@ func (s *KeeperTestSuite) TestQueryParent() {
return
}
s.Require().NoError(err)
s.Require().NotNil(res)
tc.postTest(res)
})
}
Expand Down
1 change: 0 additions & 1 deletion x/collection/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d562b43

Please sign in to comment.