-
Notifications
You must be signed in to change notification settings - Fork 197
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(ibc-nft): add duplicate token id validation in packet data #325
fix(ibc-nft): add duplicate token id validation in packet data #325
Conversation
📝 WalkthroughWalkthroughThe pull request introduces an enhancement to the NFT transfer packet validation in the IBC (Inter-Blockchain Communication) module. A new validation check has been added to the Changes
Poem
Tip CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
x/ibc/nft-transfer/types/packet.go (2)
65-74
: Fix indentation in the token validation loopThe duplicate token check implementation is good, but the indentation is inconsistent with the rest of the codebase.
Apply this diff to fix the indentation:
seenTokens := make(map[string]struct{}) for _, tokenId := range nftpd.TokenIds { - if len(tokenId) == 0 { - return errors.Wrap(ErrInvalidTokenIds, "invalid zero length token id") - } - // check duplicate - if _, exists := seenTokens[tokenId]; exists { - return errors.Wrapf(ErrInvalidTokenIds, "duplicate token id: %s", tokenId) - } - seenTokens[tokenId] = struct{}{} + if len(tokenId) == 0 { + return errors.Wrap(ErrInvalidTokenIds, "invalid zero length token id") + } + // check duplicate + if _, exists := seenTokens[tokenId]; exists { + return errors.Wrapf(ErrInvalidTokenIds, "duplicate token id: %s", tokenId) + } + seenTokens[tokenId] = struct{}{} }
71-72
: Consider extracting error message as a constantFor consistency and maintainability, consider extracting the error message "duplicate token id: %s" as a constant.
Add this at the package level with other error-related constants:
+const ( + ErrMsgDuplicateTokenId = "duplicate token id: %s" +) func (nftpd NonFungibleTokenPacketData) ValidateBasic() error { // ... - return errors.Wrapf(ErrInvalidTokenIds, "duplicate token id: %s", tokenId) + return errors.Wrapf(ErrInvalidTokenIds, ErrMsgDuplicateTokenId, tokenId) // ... }x/ibc/nft-transfer/types/packet_test.go (1)
30-30
: Enhance test coverage with additional duplicate scenariosWhile the current test case covers basic duplicate detection, consider adding more scenarios:
- Multiple duplicates of the same token
- Different tokens being duplicated
- Duplicates at different positions (start, middle, end)
Add these test cases:
{"duplicate token ids", NewNonFungibleTokenPacketData(classId, "", "", []string{"1", "2", "3", "1"}, []string{"", "", "", ""}, []string{"", "", "", ""}, addr1, addr2, ""), false}, + {"multiple duplicates of same token", NewNonFungibleTokenPacketData(classId, "", "", []string{"1", "2", "1", "1"}, []string{"", "", "", ""}, []string{"", "", "", ""}, addr1, addr2, ""), false}, + {"different tokens duplicated", NewNonFungibleTokenPacketData(classId, "", "", []string{"1", "2", "1", "2"}, []string{"", "", "", ""}, []string{"", "", "", ""}, addr1, addr2, ""), false}, + {"duplicate at start", NewNonFungibleTokenPacketData(classId, "", "", []string{"1", "1", "2", "3"}, []string{"", "", "", ""}, []string{"", "", "", ""}, addr1, addr2, ""), false},
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
x/ibc/nft-transfer/types/packet.go
(1 hunks)x/ibc/nft-transfer/types/packet_test.go
(1 hunks)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeReviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...