Skip to content

Commit 1fb81ce

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

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

CHANGELOG.md

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

4747
- fixed workflow: changelog check with improved sensitivity to deletions, additions, new releases
4848

49+
### Breaking Changes
50+
51+
- 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.
52+
4953
## [0.1.9] - 2025-11-26
5054

5155
### 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,11 @@ def test_zero_amount_validation(mock_account_ids):
284284
transfer_tx = TransferTransaction()
285285

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

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

294294

0 commit comments

Comments
 (0)