chore: Added unit test and __repr__ for NftId class#1747
chore: Added unit test and __repr__ for NftId class#1747om12prakash wants to merge 4 commits intohiero-ledger:mainfrom
Conversation
Signed-off-by: om12prakash <ompyiiitg@gmail.com>
Signed-off-by: om12prakash <ompyiiitg@gmail.com>
Signed-off-by: om12prakash <ompyiiitg@gmail.com>
|
Hi, this is MergeConflictBot. Please resolve these conflicts locally and push the changes. Quick Fix for CHANGELOG.md ConflictsIf your conflict is only in CHANGELOG.md, you can resolve it easily using the GitHub web editor:
For all other merge conflicts, please read: Thank you for contributing! |
Signed-off-by: om12prakash <55754034+om12prakash@users.noreply.github.com>
WalkthroughAdded a Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| def __repr__(self) -> str: | ||
|
|
||
| return f"NftId(token_id = {self.token_id}, serial_number = {self.serial_number})" No newline at end of file |
There was a problem hiding this comment.
__repr__ format deviates from issue spec and Python convention.
Issue #1627 specifies the format as NftId(token_id=0.0.123, serial_number=5) (no spaces around =), and Python's convention for __repr__ is to mimic constructor-call syntax (PEP 257), which also omits spaces around = in keyword arguments. The current output has extra spaces.
Proposed fix
def __repr__(self) -> str:
-
- return f"NftId(token_id = {self.token_id}, serial_number = {self.serial_number})"
+ return f"NftId(token_id={self.token_id}, serial_number={self.serial_number})"| def test_nft_id_repr(): | ||
| token_id = TokenId(0, 0, 123) | ||
| nft_id = NftId(token_id, 5) | ||
| assert repr(nft_id) == "NftId(token_id = 0.0.123, serial_number = 5)" No newline at end of file |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major
Expand test coverage with edge cases and boundary conditions.
A single happy-path test is insufficient. Per coding guidelines: cover boundary conditions, verify return type, and test additional scenarios. Consider adding cases for serial_number=0 (boundary), different token_id values, and verifying repr returns a str.
Suggested additional tests
def test_nft_id_repr_zero_serial():
token_id = TokenId(0, 0, 1)
nft_id = NftId(token_id, 0)
result = repr(nft_id)
assert isinstance(result, str)
assert "serial_number=0" in result
def test_nft_id_repr_large_values():
token_id = TokenId(1, 2, 999999)
nft_id = NftId(token_id, 2**53)
result = repr(nft_id)
assert "token_id=1.2.999999" in result
assert f"serial_number={2**53}" in resultAs per coding guidelines, "Unit tests should be extensive - test even if we don't expect users to use it currently. Cover happy paths AND unhappy paths/edge cases. Test boundary conditions, null/None values, empty collections, etc."
manishdait
left a comment
There was a problem hiding this comment.
@om12prakash, Thanks for PR, I have added a change request, rest of the PR looks good.
| pytestmark = pytest.mark.unit | ||
|
|
||
|
|
||
| def test_nft_id_repr(): |
There was a problem hiding this comment.
this can be move to tests/unit/nft_id_test.py
Description:
Related issue(s):
Fixes #1627
Notes for reviewer:
Checklist