From d562b43025ce4c354e87f6b0ed60a09ec594e9a7 Mon Sep 17 00:00:00 2001 From: Youngtaek Yoon Date: Fri, 7 Apr 2023 18:23:39 +0900 Subject: [PATCH] fix: return nil where the parent not exists in x/collection Query/Parent (#955) * Do not return error where parent not exists * Update proto doc * Add the test * Update CHANGELOG.md --- CHANGELOG.md | 1 + docs/core/proto-docs.md | 2 +- proto/lbm/collection/v1/query.proto | 1 - x/collection/keeper/grpc_query.go | 2 +- x/collection/keeper/grpc_query_test.go | 14 +++++++++----- x/collection/query.pb.go | 1 - 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68665a7f5b..8e92859661 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 98d40bbae0..27f22b95d7 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -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. | diff --git a/proto/lbm/collection/v1/query.proto b/proto/lbm/collection/v1/query.proto index d9e96202e8..9f97a1c2f7 100644 --- a/proto/lbm/collection/v1/query.proto +++ b/proto/lbm/collection/v1/query.proto @@ -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]; } diff --git a/x/collection/keeper/grpc_query.go b/x/collection/keeper/grpc_query.go index ec308776c5..c5132ff934 100644 --- a/x/collection/keeper/grpc_query.go +++ b/x/collection/keeper/grpc_query.go @@ -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) diff --git a/x/collection/keeper/grpc_query_test.go b/x/collection/keeper/grpc_query_test.go index 363abafa77..8ce4b0381d 100644 --- a/x/collection/keeper/grpc_query_test.go +++ b/x/collection/keeper/grpc_query_test.go @@ -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, }, @@ -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 { @@ -751,7 +756,6 @@ func (s *KeeperTestSuite) TestQueryParent() { return } s.Require().NoError(err) - s.Require().NotNil(res) tc.postTest(res) }) } diff --git a/x/collection/query.pb.go b/x/collection/query.pb.go index 5a77c86ede..5f1e89a24e 100644 --- a/x/collection/query.pb.go +++ b/x/collection/query.pb.go @@ -1388,7 +1388,6 @@ func (m *QueryParentRequest) GetTokenId() string { // QueryParentResponse is the response type for the Query/Parent RPC method. type QueryParentResponse struct { // parent is the information of the parent token. - // if there is no parent for the token, it would return nil. Parent NFT `protobuf:"bytes,1,opt,name=parent,proto3" json:"parent"` }