Skip to content

Commit

Permalink
Problem: query nft owner returns error when user has NFTs transferr…
Browse files Browse the repository at this point in the history
…ed over IBC (#903)

Solution: Fixed denomID and tokenID splitting logic when denom has `ibc`.

* Fix lint errors
  • Loading branch information
devashishdxt authored Nov 29, 2022
1 parent 0192445 commit 49976e2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
24 changes: 20 additions & 4 deletions x/nft/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,28 @@ func SplitKeyOwner(key []byte) (address sdk.AccAddress, denomID, tokenID string,

func SplitKeyDenom(key []byte) (denomID, tokenID string, err error) {
keys := bytes.Split(key, delimiter)
if len(keys) != 2 {
return denomID, tokenID, errors.New("wrong KeyOwner")

switch len(keys) {
case 2:
{
denomID = string(keys[0])
tokenID = string(keys[1])
}
case 3:
{
if string(keys[0]) == "ibc" {
denomID = "ibc/" + string(keys[1])
tokenID = string(keys[2])
} else {
return denomID, tokenID, errors.New("wrong KeyOwner")
}
}
default:
{
return denomID, tokenID, errors.New("wrong KeyOwner")
}
}

denomID = string(keys[0])
tokenID = string(keys[1])
return
}

Expand Down
30 changes: 30 additions & 0 deletions x/nft/types/keys_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package types_test

import (
"testing"

"github.com/crypto-org-chain/chain-main/v4/x/nft/types"
"github.com/stretchr/testify/require"
)

func TestSplitKeyDenomWithoutIBC(t *testing.T) {
keyDenom := []byte("testdenomid/testtokenid")

// nolint: govet
denomID, tokenID, err := types.SplitKeyDenom(keyDenom)

require.NoError(t, err)
require.Equal(t, "testdenomid", denomID)
require.Equal(t, "testtokenid", tokenID)
}

func TestSplitKeyDenomWithIBC(t *testing.T) {
keyDenom := []byte("ibc/testdenomid/testtokenid")

// nolint: govet
denomID, tokenID, err := types.SplitKeyDenom(keyDenom)

require.NoError(t, err)
require.Equal(t, "ibc/testdenomid", denomID)
require.Equal(t, "testtokenid", tokenID)
}

0 comments on commit 49976e2

Please sign in to comment.