Skip to content

Conversation

@mukundkumarjha
Copy link
Contributor

@mukundkumarjha mukundkumarjha commented Dec 17, 2025

Description:

Related issue(s):

Fixes #1097

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

Summary by CodeRabbit

  • New Features

    • AccountBalance now provides a human-friendly string and a developer-friendly repr showing HBAR and token balances.
  • Tests

    • Added unit tests validating string and repr outputs for HBAR-only and token-inclusive balances, including formatting checks.
  • Chores

    • Example usage simplified to print the full account balance object for clearer consolidated output.

✏️ Tip: You can customize this high-level summary in your review settings.

@exploreriii
Copy link
Contributor

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Dec 17, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link

coderabbitai bot commented Dec 17, 2025

Walkthrough

AccountBalance gains str and repr methods for human- and developer-friendly string output. An example was simplified to print the AccountBalance directly (removed per-token print loop). Unit tests and CHANGELOG were added/updated to validate and document the new formatting.

Changes

Cohort / File(s) Summary
AccountBalance string methods
src/hiero_sdk_python/account/account_balance.py
Added __str__() returning a human-friendly multi-line string with "HBAR Balance" and optional "Token Balances"; added __repr__() returning a developer-friendly one-line representation (hbars and token balances).
Example simplification
examples/query/account_balance_query_2.py
Removed manual per-token printing loop and associated prints; retained HBAR print and replaced token display with a note/print of the full account_balance object (leverages new __str__).
Unit tests for formatting
tests/unit/test_account_balance.py
Added tests covering __str__() and __repr__() for HBAR-only, with token balances, and empty token balances, asserting formatting details.
Changelog
CHANGELOG.md
Documented the addition of __str__ and __repr__ for AccountBalance under Unreleased -> Added.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Check formatting logic and edge cases in __str__/__repr__ (empty token balances, decimal formatting).
  • Verify tests match exact string expectations and won't be brittle across environments.
  • Confirm example change intentionally prints the object and has no behavioral side effects.

Suggested reviewers

  • exploreriii

Poem

🐰 I hopped through lines and shaped a phrase,

Now balances speak in friendly ways.
HBARs gleam and tokens line by line,
I print them neat — a rabbit's design. ✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding str and repr methods to the AccountBalance class.
Linked Issues check ✅ Passed The PR implements the core requirements from #1097: adds str and repr methods to AccountBalance, updates examples to use them, and includes comprehensive unit tests.
Out of Scope Changes check ✅ Passed All changes directly support the objectives stated in issue #1097, including method implementations, example updates, tests, and CHANGELOG documentation.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c72b631 and 06971ae.

📒 Files selected for processing (1)
  • examples/query/account_balance_query_2.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • examples/query/account_balance_query_2.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ec301a5 and 413da1f.

📒 Files selected for processing (3)
  • examples/query/account_balance_query_2.py (1 hunks)
  • src/hiero_sdk_python/account/account_balance.py (1 hunks)
  • tests/unit/test_account_balance.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
tests/unit/test_account_balance.py (3)
src/hiero_sdk_python/account/account_balance.py (1)
  • AccountBalance (14-82)
src/hiero_sdk_python/hbar.py (1)
  • Hbar (18-174)
src/hiero_sdk_python/tokens/token_id.py (1)
  • TokenId (21-180)
src/hiero_sdk_python/account/account_balance.py (2)
src/hiero_sdk_python/transaction/transaction_receipt.py (1)
  • token_id (56-68)
src/hiero_sdk_python/utils/subscription_handle.py (1)
  • join (30-35)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (3)
src/hiero_sdk_python/account/account_balance.py (2)

56-68: LGTM!

The __str__ implementation correctly formats the HBAR balance and conditionally includes token balances. The output format (e.g., "10.00000000 ℏ hbars") includes both the ℏ symbol and the word "hbars", which matches the examples in the linked issue requirements.


70-82: LGTM!

The __repr__ implementation correctly provides a developer-friendly representation showing the key attributes. The use of !r formatting and the conditional handling of empty/non-empty token balances is appropriate.

tests/unit/test_account_balance.py (1)

1-87: LGTM!

The test suite comprehensively validates both __str__ and __repr__ methods across multiple scenarios:

  • HBAR-only balances
  • Balances with tokens
  • Empty token balances

The tests verify formatting details, conditional sections, and expected string representations. Well-structured and thorough.

@github-actions
Copy link

Hi, this is WorkflowBot.
Your pull request cannot be merged as it is not passing all our workflow checks.
Please click on each check to review the logs and resolve issues so all checks pass.
To help you:

@codecov
Copy link

codecov bot commented Dec 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1122      +/-   ##
==========================================
+ Coverage   91.08%   91.09%   +0.01%     
==========================================
  Files         139      139              
  Lines        8423     8433      +10     
==========================================
+ Hits         7672     7682      +10     
  Misses        751      751              
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link

Hi, this is MergeConflictBot.
Your pull request cannot be merged because it contains merge conflicts.

Please resolve these conflicts locally and push the changes.

To assist you, please read:

Thank you for contributing!

From the Hiero Python SDK Team

Copy link

@coderabbitai coderabbitai bot left a 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 (1)
CHANGELOG.md (1)

43-43: Align CHANGELOG entry with established pattern for similar features.

This entry is less detailed than comparable __str__ additions (lines 22, 33), which explicitly mention updated examples and tests. Per the AI summary, this PR updates examples and tests as well. Also missing is a reference to the related issue (#1097), which helps with traceability.

🔎 Suggested CHANGELOG entry:
- Added __str__ and __repr__ to AccountBalance
+ Added __str__() and __repr__() to AccountBalance and updated examples and tests accordingly (#1097)
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 413da1f and 2fb6824.

📒 Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (2)
CHANGELOG.md (2)

46-46: Changelog entry for account_create_transaction_with_fallback_alias refactor is well-documented.

Clear description with specific function names and issue reference; this sets a good precedent that the AccountBalance entry could follow.


1-623: Actual code changes not provided for verification.

Only CHANGELOG.md was included for review. The PR objectives specify detailed requirements for AccountBalance.__str__() and __repr__() output formatting. To verify the implementation matches these specifications and that tests/examples are properly updated, please provide the code changes from:

  • src/hiero_sdk_python/account/account_balance.py
  • tests/unit/test_account_balance.py
  • examples/query/account_balance_query_2.py

Signed-off-by: mukundkumarjha <[email protected]>
Signed-off-by: mukundkumarjha <[email protected]>
Signed-off-by: mukundkumarjha <[email protected]>
@exploreriii exploreriii merged commit 0e3f795 into hiero-ledger:main Dec 18, 2025
20 checks passed
prajeeta15 pushed a commit to prajeeta15/hiero-sdk-python that referenced this pull request Dec 23, 2025
…er#1122)

Signed-off-by: mukundkumarjha <[email protected]>
Signed-off-by: Mukund Jha <[email protected]>
Signed-off-by: prajeeta pal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expand src/hiero_sdk_python/account/account_balance.py with __repr__ and __str__

3 participants