Skip to content

Commit cd37dd6

Browse files
committed
chore: added test for topic message submit tx
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
1 parent 08789a7 commit cd37dd6

2 files changed

Lines changed: 55 additions & 5 deletions

File tree

tests/unit/topic_message_submit_transaction_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,3 +504,14 @@ def test_topic_submit_execute_returns_failed_receipt_by_default(topic_id):
504504
receipt = tx.execute(client)
505505

506506
assert receipt.status == ResponseCode.INVALID_SIGNATURE
507+
508+
def test_topic_submit_message_raises_error_on_freeze(topic_id):
509+
"""Test transaction raises error on freeze when the transaction_id and node_id not set"""
510+
tx = (
511+
TopicMessageSubmitTransaction()
512+
.set_topic_id(topic_id)
513+
.set_message("Hello Hiero")
514+
)
515+
516+
with pytest.raises(ValueError):
517+
tx.freeze()

tests/unit/transaction_test.py

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from hiero_sdk_python.account.account_create_transaction import AccountCreateTransaction
66
from hiero_sdk_python.account.account_id import AccountId
7+
from hiero_sdk_python.consensus.topic_id import TopicId
8+
from hiero_sdk_python.consensus.topic_message_submit_transaction import TopicMessageSubmitTransaction
79
from hiero_sdk_python.crypto.private_key import PrivateKey
810
from hiero_sdk_python.exceptions import ReceiptStatusError
911
from hiero_sdk_python.file.file_append_transaction import FileAppendTransaction
@@ -33,7 +35,7 @@
3335

3436
@pytest.fixture
3537
def file_id():
36-
"""Returns a file_is for test."""
38+
"""Returns a file_id for test."""
3739
return FileId.from_string("0.0.1")
3840

3941

@@ -301,8 +303,8 @@ def test_tx_without_optional_fields_should_have_smaller_tx_body(
301303
assert tx1.body_size < tx2.body_size
302304

303305

304-
def test_chunk_tx_should_return_list_of_body_sizes(file_id, account_id, transaction_id):
305-
"""Test should return array of body sizes for multi-chunk transaction."""
306+
def test_file_append_chunk_tx_should_return_list_of_body_sizes(file_id, account_id, transaction_id):
307+
"""Test file append tx should return array of body sizes for multi-chunk transaction."""
306308
chunk_size = 1024
307309
content = "a" * (chunk_size * 3)
308310

@@ -321,8 +323,8 @@ def test_chunk_tx_should_return_list_of_body_sizes(file_id, account_id, transact
321323
assert len(sizes) == 3
322324

323325

324-
def test_single_chunk_tx_return_list_of_len_one(file_id, account_id, transaction_id):
325-
"""Test should return array of one size for single-chunk transaction."""
326+
def test_file_append_single_chunk_tx_return_list_of_len_one(file_id, account_id, transaction_id):
327+
"""Test file append tx should return array of one size for single-chunk transaction."""
326328
content = "small_content"
327329
tx = (
328330
FileAppendTransaction()
@@ -338,6 +340,43 @@ def test_single_chunk_tx_return_list_of_len_one(file_id, account_id, transaction
338340
assert len(sizes) == 1
339341

340342

343+
def test_message_submit_chunk_tx_should_return_list_of_body_sizes(topic_id, account_id, transaction_id):
344+
"""Test topic message submit tx should return array of body sizes for multi-chunk transaction."""
345+
chunk_size = 1024
346+
message= "a" * (chunk_size * 3)
347+
348+
tx = (
349+
TopicMessageSubmitTransaction()
350+
.set_topic_id(topic_id)
351+
.set_chunk_size(chunk_size)
352+
.set_message(message)
353+
.set_transaction_id(transaction_id)
354+
.set_node_account_id(account_id)
355+
.freeze()
356+
)
357+
358+
sizes = tx.body_size_all_chunks
359+
assert isinstance(sizes, list)
360+
assert len(sizes) == 3
361+
362+
363+
def test_message_submit_single_chunk_tx_return_list_of_len_one(topic_id, account_id, transaction_id):
364+
"""Test topic message submit tx should return array of one size for single-chunk transaction."""
365+
message = "small_content"
366+
tx = (
367+
TopicMessageSubmitTransaction()
368+
.set_topic_id(topic_id)
369+
.set_message(message)
370+
.set_transaction_id(transaction_id)
371+
.set_node_account_id(account_id)
372+
.freeze()
373+
)
374+
375+
sizes = tx.body_size_all_chunks
376+
assert isinstance(sizes, list)
377+
assert len(sizes) == 1
378+
379+
341380
def test_tx_with_no_content_should_return_single_body_chunk(
342381
file_id, account_id, transaction_id
343382
):

0 commit comments

Comments
 (0)