|
16 | 16 | from hiero_sdk_python.hbar import Hbar |
17 | 17 | from hiero_sdk_python.tokens.nft_id import NftId |
18 | 18 | from hiero_sdk_python.tokens.token_id import TokenId |
| 19 | +from hiero_sdk_python.transaction.transaction import Transaction |
| 20 | +from hiero_sdk_python.transaction.transaction_id import TransactionId |
19 | 21 |
|
20 | 22 |
|
21 | 23 | pytestmark = pytest.mark.unit |
@@ -404,3 +406,38 @@ def test_zero_amount_allowances(account_allowance_transaction, sample_accounts, |
404 | 406 | assert len(account_allowance_transaction.token_allowances) == 1 |
405 | 407 | assert account_allowance_transaction.hbar_allowances[0].amount == 0 |
406 | 408 | assert account_allowance_transaction.token_allowances[0].amount == 0 |
| 409 | + |
| 410 | + |
| 411 | +def test_from_bytes(mock_account_ids): |
| 412 | + """Test round-trip via _from_protobuf for AccountAllowanceApproveTransaction.""" |
| 413 | + operator_id, _, node_account_id, _, _ = mock_account_ids |
| 414 | + owner = AccountId(0, 0, 200) |
| 415 | + spender = AccountId(0, 0, 300) |
| 416 | + token_id = TokenId(0, 0, 500) |
| 417 | + nft_id = NftId(token_id, 1) |
| 418 | + |
| 419 | + tx = AccountAllowanceApproveTransaction() |
| 420 | + tx.approve_hbar_allowance(owner, spender, Hbar(10)) |
| 421 | + tx.approve_token_allowance(token_id, owner, spender, 100) |
| 422 | + tx.approve_token_nft_allowance(nft_id, owner, spender) |
| 423 | + tx.transaction_id = TransactionId.generate(operator_id) |
| 424 | + tx.node_account_id = node_account_id |
| 425 | + tx.freeze() |
| 426 | + |
| 427 | + reconstructed = Transaction.from_bytes(tx.to_bytes()) |
| 428 | + |
| 429 | + assert isinstance(reconstructed, AccountAllowanceApproveTransaction) |
| 430 | + assert len(reconstructed.hbar_allowances) == 1 |
| 431 | + assert reconstructed.hbar_allowances[0].owner_account_id == owner |
| 432 | + assert reconstructed.hbar_allowances[0].spender_account_id == spender |
| 433 | + assert reconstructed.hbar_allowances[0].amount == Hbar(10).to_tinybars() |
| 434 | + assert len(reconstructed.token_allowances) == 1 |
| 435 | + assert reconstructed.token_allowances[0].token_id == token_id |
| 436 | + assert reconstructed.token_allowances[0].owner_account_id == owner |
| 437 | + assert reconstructed.token_allowances[0].spender_account_id == spender |
| 438 | + assert reconstructed.token_allowances[0].amount == 100 |
| 439 | + assert len(reconstructed.nft_allowances) == 1 |
| 440 | + assert reconstructed.nft_allowances[0].token_id == token_id |
| 441 | + assert reconstructed.nft_allowances[0].owner_account_id == owner |
| 442 | + assert reconstructed.nft_allowances[0].spender_account_id == spender |
| 443 | + assert nft_id.serial_number in reconstructed.nft_allowances[0].serial_numbers |
0 commit comments