Skip to content

Commit 765b8ba

Browse files
committed
chore: add test for validating changes
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
1 parent 1c0d56b commit 765b8ba

3 files changed

Lines changed: 81 additions & 3 deletions

File tree

tests/unit/file_append_transaction_test.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
import pytest
66

7+
from hiero_sdk_python.account.account_id import AccountId
78
from hiero_sdk_python.exceptions import PrecheckError, ReceiptStatusError
89
from hiero_sdk_python.file.file_append_transaction import FileAppendTransaction
910
from hiero_sdk_python.file.file_id import FileId
1011
from hiero_sdk_python.hapi.services import (
1112
response_header_pb2,
1213
response_pb2,
14+
timestamp_pb2,
1315
transaction_get_receipt_pb2,
1416
transaction_receipt_pb2,
1517
transaction_response_pb2,
@@ -372,3 +374,30 @@ def test_file_append_execute_all_returns_receipt_without_validation(file_id):
372374
receipts = tx.execute_all(client)
373375

374376
assert receipts[0].status == ResponseCode.INVALID_FILE_ID
377+
378+
379+
def test_chunk_transaction_id_nanosecond_overflow(file_id):
380+
"""Test that multi-chunk transaction IDs handle nanosecond overflow correctly."""
381+
base_seconds = 1770911831
382+
base_nanos = 999_999_999
383+
384+
start_timestamp = timestamp_pb2.Timestamp(seconds=base_seconds, nanos=base_nanos)
385+
tx_id = TransactionId(account_id=AccountId(0, 0, 2), valid_start=start_timestamp)
386+
387+
tx = (
388+
FileAppendTransaction()
389+
.set_file_id(file_id)
390+
.set_contents("a" * 20)
391+
.set_chunk_size(10)
392+
.set_transaction_id(tx_id)
393+
.set_node_account_id(AccountId(0, 0, 3))
394+
.freeze()
395+
)
396+
397+
# First chunk is exactly equal initial ID
398+
assert tx._transaction_ids[0].valid_start.seconds == base_seconds
399+
assert tx._transaction_ids[0].valid_start.nanos == base_nanos
400+
401+
# Second chunk seconds=base_seconds + 1, nanos=0
402+
assert tx._transaction_ids[1].valid_start.seconds == base_seconds + 1
403+
assert tx._transaction_ids[1].valid_start.nanos == 0

tests/unit/topic_message_submit_transaction_test.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
import pytest
88

9+
from hiero_sdk_python.account.account_id import AccountId
910
from hiero_sdk_python.consensus.topic_message_submit_transaction import TopicMessageSubmitTransaction
1011
from hiero_sdk_python.exceptions import PrecheckError, ReceiptStatusError
1112
from hiero_sdk_python.hapi.services import (
1213
response_header_pb2,
1314
response_pb2,
15+
timestamp_pb2,
1416
transaction_get_receipt_pb2,
1517
transaction_receipt_pb2,
1618
transaction_response_pb2,
@@ -20,6 +22,7 @@
2022
)
2123
from hiero_sdk_python.response_code import ResponseCode
2224
from hiero_sdk_python.transaction.custom_fee_limit import CustomFeeLimit
25+
from hiero_sdk_python.transaction.transaction_id import TransactionId
2326
from hiero_sdk_python.transaction.transaction_receipt import TransactionReceipt
2427
from hiero_sdk_python.transaction.transaction_response import TransactionResponse
2528
from tests.unit.mock_server import mock_hedera_servers
@@ -511,3 +514,30 @@ def test_topic_submit_message_raises_error_on_freeze(topic_id):
511514

512515
with pytest.raises(ValueError):
513516
tx.freeze()
517+
518+
519+
def test_chunk_transaction_id_nanosecond_overflow(topic_id):
520+
"""Test that multi-chunk transaction IDs handle nanosecond overflow correctly."""
521+
base_seconds = 1770911831
522+
base_nanos = 999_999_999
523+
524+
start_timestamp = timestamp_pb2.Timestamp(seconds=base_seconds, nanos=base_nanos)
525+
tx_id = TransactionId(account_id=AccountId(0, 0, 2), valid_start=start_timestamp)
526+
527+
tx = (
528+
TopicMessageSubmitTransaction()
529+
.set_topic_id(topic_id)
530+
.set_message("a" * 20)
531+
.set_chunk_size(10)
532+
.set_transaction_id(tx_id)
533+
.set_node_account_id(AccountId(0, 0, 3))
534+
.freeze()
535+
)
536+
537+
# First chunk is exactly equal initial ID
538+
assert tx._transaction_ids[0].valid_start.seconds == base_seconds
539+
assert tx._transaction_ids[0].valid_start.nanos == base_nanos
540+
541+
# Second chunk seconds=base_seconds + 1, nanos=0
542+
assert tx._transaction_ids[1].valid_start.seconds == base_seconds + 1
543+
assert tx._transaction_ids[1].valid_start.nanos == 0

tests/unit/transaction_test.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ def test_message_submit_chunk_tx_should_return_list_of_body_sizes(topic_id, acco
355355
sizes = tx.body_size_all_chunks
356356
assert isinstance(sizes, list)
357357
assert len(sizes) == 3
358+
assert tx._current_index == 0
358359

359360

360361
def test_message_submit_single_chunk_tx_return_list_of_len_one(topic_id, account_id, transaction_id):
@@ -420,9 +421,27 @@ def test_chunked_tx_return_proper_sizes(file_id, account_id, transaction_id):
420421

421422
# Size should be greater than single chunk size
422423
assert large_size > 1024
423-
424424
# The larger chunked transaction should be bigger than the single-chunk transaction
425425
assert large_size > small_size
426-
427-
# Check for chuck index reset reset
428426
assert large_tx._current_chunk_index == 0
427+
428+
429+
def test_chunked_tx_differ_size_if_chunk_are_not_equal(topic_id, account_id, transaction_id):
430+
"""Test that the last chunk's size is different from the full chunks if the chunk size is not even."""
431+
chunk_size = 1024
432+
message = "a" * (chunk_size + 512)
433+
434+
tx = (
435+
TopicMessageSubmitTransaction()
436+
.set_topic_id(topic_id)
437+
.set_chunk_size(chunk_size)
438+
.set_message(message)
439+
.set_transaction_id(transaction_id)
440+
.set_node_account_id(account_id)
441+
.freeze()
442+
)
443+
444+
sizes = tx.body_size_all_chunks
445+
assert len(sizes) == 2
446+
# The first chunk should be larger than the second because it carries more message data
447+
assert sizes[0] > sizes[1]

0 commit comments

Comments
 (0)