|
7 | 7 | from hiero_sdk_python.crypto.private_key import PrivateKey |
8 | 8 | from hiero_sdk_python.exceptions import PrecheckError |
9 | 9 | from hiero_sdk_python.hbar import Hbar |
| 10 | +from hiero_sdk_python.hbar_unit import HbarUnit |
10 | 11 | from hiero_sdk_python.query.account_balance_query import CryptoGetAccountBalanceQuery |
11 | 12 | from hiero_sdk_python.response_code import ResponseCode |
12 | 13 | from hiero_sdk_python.tokens.nft_id import NftId |
@@ -448,3 +449,47 @@ def test_integration_transfer_transaction_approved_token_transfer(): |
448 | 449 |
|
449 | 450 | finally: |
450 | 451 | 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() |
0 commit comments