Skip to content

Commit ca729cb

Browse files
committed
fix: hbar transfer
Signed-off-by: prajeeta pal <prajeetapal@gmail.com>
1 parent e846378 commit ca729cb

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
2727

2828
- fixed workflow: changelog check with improved sensitivity to deletions, additions, new releases
2929

30+
### Breaking Changes
31+
32+
- Changed error message in `TransferTransaction._add_hbar_transfer()` and `AbstractTokenTransferTransaction._add_token_transfer()` when amount is zero from "Amount must be a non-zero integer" to "Amount must be a non-zero value." for clarity and consistency.
33+
3034
## [0.1.9] - 2025-11-26
3135

3236
### Added

src/hiero_sdk_python/tokens/abstract_token_transfer_transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def _add_token_transfer(
149149
if not isinstance(account_id, AccountId):
150150
raise TypeError("account_id must be an AccountId instance.")
151151
if not isinstance(amount, int) or amount == 0:
152-
raise ValueError("Amount must be a non-zero integer.")
152+
raise ValueError("Amount must be a non-zero value.")
153153
if expected_decimals is not None and not isinstance(expected_decimals, int):
154154
raise TypeError("expected_decimals must be an integer.")
155155
if not isinstance(is_approved, bool):

tests/integration/transfer_transaction_e2e_test.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from hiero_sdk_python.crypto.private_key import PrivateKey
88
from hiero_sdk_python.exceptions import PrecheckError
99
from hiero_sdk_python.hbar import Hbar
10+
from hiero_sdk_python.hbar_unit import HbarUnit
1011
from hiero_sdk_python.query.account_balance_query import CryptoGetAccountBalanceQuery
1112
from hiero_sdk_python.response_code import ResponseCode
1213
from hiero_sdk_python.tokens.nft_id import NftId
@@ -448,3 +449,47 @@ def test_integration_transfer_transaction_approved_token_transfer():
448449

449450
finally:
450451
env.close()
452+
453+
454+
@pytest.mark.integration
455+
def test_integration_transfer_transaction_with_hbar_units():
456+
env = IntegrationTestEnv()
457+
458+
try:
459+
new_account_private_key = PrivateKey.generate()
460+
new_account_public_key = new_account_private_key.public_key()
461+
462+
initial_balance = Hbar(1)
463+
464+
account_transaction = AccountCreateTransaction(
465+
key=new_account_public_key, initial_balance=initial_balance, memo="Recipient Account"
466+
)
467+
468+
receipt = account_transaction.execute(env.client)
469+
470+
assert (
471+
receipt.status == ResponseCode.SUCCESS
472+
), f"Account creation failed with status: {ResponseCode(receipt.status).name}"
473+
474+
account_id = receipt.account_id
475+
assert account_id is not None
476+
477+
transfer_transaction = TransferTransaction()
478+
transfer_transaction.add_hbar_transfer(env.operator_id, Hbar(-1.5, HbarUnit.HBAR))
479+
transfer_transaction.add_hbar_transfer(account_id, Hbar(1.5, HbarUnit.HBAR))
480+
481+
receipt = transfer_transaction.execute(env.client)
482+
483+
assert (
484+
receipt.status == ResponseCode.SUCCESS
485+
), f"Transfer failed with status: {ResponseCode(receipt.status).name}"
486+
487+
query_transaction = CryptoGetAccountBalanceQuery(account_id)
488+
balance = query_transaction.execute(env.client)
489+
490+
expected_balance_tinybars = Hbar(1).to_tinybars() + Hbar(1.5, HbarUnit.HBAR).to_tinybars()
491+
assert (
492+
balance and balance.hbars.to_tinybars() == expected_balance_tinybars
493+
), f"Expected balance: {expected_balance_tinybars}, actual balance: {balance.hbars.to_tinybars()}"
494+
finally:
495+
env.close()

tests/unit/test_transfer_transaction.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,11 @@ def test_zero_amount_validation(mock_account_ids):
286286
transfer_tx = TransferTransaction()
287287

288288
# Test zero HBAR amount should raise ValueError
289-
with pytest.raises(ValueError, match="Amount must be a non-zero integer"):
289+
with pytest.raises(ValueError, match="Amount must be a non-zero value"):
290290
transfer_tx.add_hbar_transfer(account_id_1, 0)
291291

292292
# Test zero token amount should raise ValueError
293-
with pytest.raises(ValueError, match="Amount must be a non-zero integer"):
293+
with pytest.raises(ValueError, match="Amount must be a non-zero value"):
294294
transfer_tx.add_token_transfer(token_id_1, account_id_1, 0)
295295

296296

@@ -647,7 +647,7 @@ def test_hbar_transfer_conversion_accuracy(mock_account_ids):
647647
transfer_tx = TransferTransaction()
648648

649649
hbar_value = Hbar(1.5, HbarUnit.HBAR)
650-
expected_tinybars = 1_500_000_000
650+
expected_tinybars = 150_000_000
651651

652652
transfer_tx.add_hbar_transfer(account_id_1, hbar_value)
653653

0 commit comments

Comments
 (0)