Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return nil where the parent not exists in x/collection Query/Parent #955

Merged
merged 6 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) [\#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 @@ -427,7 +427,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 @@ -704,9 +704,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 @@ -717,10 +726,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 @@ -735,7 +740,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.