-
Notifications
You must be signed in to change notification settings - Fork 176
feat(account): add __str__ and __repr__ to AccountBalance #1122
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f010b6e
chore:Added '__repr__()' and '__str__()' to AccountBalance class
mukundkumarjha 70e6076
.env file deleted by mistake
mukundkumarjha 821af4e
Merge branch 'main' into main
mukundkumarjha 652a7d5
changes as per the reivew
mukundkumarjha 4e509fd
Merge branch 'hiero-ledger:main' into main
mukundkumarjha d6fcfb3
Merge branch 'main' into main
mukundkumarjha 413da1f
test updation
mukundkumarjha e8a4c13
Merge branch 'hiero-ledger:main' into main
mukundkumarjha 2fb6824
changelog.md updation
mukundkumarjha a5a8a0c
merge conflict
mukundkumarjha c72b631
changelog.md change
mukundkumarjha 06971ae
raw object print removed
mukundkumarjha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| """Tests for the AccountBalance class.""" | ||
|
|
||
| import pytest | ||
|
|
||
| from hiero_sdk_python.account.account_balance import AccountBalance | ||
| from hiero_sdk_python.hbar import Hbar | ||
| from hiero_sdk_python.tokens.token_id import TokenId | ||
|
|
||
| pytestmark = pytest.mark.unit | ||
|
|
||
|
|
||
| def test_account_balance_str_with_hbars_only(): | ||
| """Test __str__ method with only hbars.""" | ||
| hbars = Hbar(10) | ||
| account_balance = AccountBalance(hbars=hbars) | ||
|
|
||
| result = str(account_balance) | ||
|
|
||
| assert "HBAR Balance:" in result | ||
| assert "10.00000000 ℏ" in result | ||
| assert "hbars" in result | ||
| # Should not include token balances section when empty | ||
| assert "Token Balances:" not in result | ||
|
|
||
|
|
||
| def test_account_balance_str_with_token_balances(): | ||
| """Test __str__ method with hbars and token balances.""" | ||
| hbars = Hbar(10) | ||
| token_id_1 = TokenId(0, 0, 100) | ||
| token_id_2 = TokenId(0, 0, 200) | ||
| token_balances = {token_id_1: 1000, token_id_2: 500} | ||
| account_balance = AccountBalance(hbars=hbars, token_balances=token_balances) | ||
|
|
||
| result = str(account_balance) | ||
|
|
||
| assert "HBAR Balance:" in result | ||
| assert "10.00000000 ℏ" in result | ||
| assert " hbars" in result | ||
| assert "Token Balances:" in result | ||
| assert " - Token ID 0.0.100: 1000 units" in result | ||
| assert " - Token ID 0.0.200: 500 units" in result | ||
|
|
||
|
|
||
| def test_account_balance_str_with_empty_token_balances(): | ||
| """Test __str__ method with empty token balances dict.""" | ||
| hbars = Hbar(5.5) | ||
| account_balance = AccountBalance(hbars=hbars, token_balances={}) | ||
|
|
||
| result = str(account_balance) | ||
|
|
||
| assert "HBAR Balance:" in result | ||
| assert "5.50000000 ℏ" in result | ||
| assert " hbars" in result | ||
| # Should not include token balances section when empty | ||
| assert "Token Balances:" not in result | ||
|
|
||
|
|
||
| def test_account_balance_repr_with_hbars_only(): | ||
| """Test __repr__ method with only hbars.""" | ||
| hbars = Hbar(10) | ||
| account_balance = AccountBalance(hbars=hbars) | ||
|
|
||
| result = repr(account_balance) | ||
|
|
||
| assert "AccountBalance" in result | ||
| assert "hbars=" in result | ||
| assert "token_balances={}" in result | ||
| assert "Hbar(" in result | ||
|
|
||
|
|
||
| def test_account_balance_repr_with_token_balances(): | ||
| """Test __repr__ method with hbars and token balances.""" | ||
| hbars = Hbar(10) | ||
| token_id_1 = TokenId(0, 0, 100) | ||
| token_id_2 = TokenId(0, 0, 200) | ||
| token_balances = {token_id_1: 1000, token_id_2: 500} | ||
| account_balance = AccountBalance(hbars=hbars, token_balances=token_balances) | ||
|
|
||
| result = repr(account_balance) | ||
|
|
||
| assert "AccountBalance" in result | ||
| assert "hbars=" in result | ||
| assert "token_balances=" in result | ||
| assert "0.0.100" in result or "TokenId" in result | ||
| assert "1000" in result | ||
| assert "500" in result | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.