Skip to content

Commit 1489840

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

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
@@ -639,3 +639,14 @@ def test_topic_submit_execute_returns_failed_receipt_by_default(topic_id):
639639
receipt = tx.execute(client)
640640

641641
assert receipt.status == ResponseCode.INVALID_SIGNATURE
642+
643+
def test_topic_submit_message_raises_error_on_freeze(topic_id):
644+
"""Test transaction raises error on freeze when the transaction_id and node_id not set"""
645+
tx = (
646+
TopicMessageSubmitTransaction()
647+
.set_topic_id(topic_id)
648+
.set_message("Hello Hiero")
649+
)
650+
651+
with pytest.raises(ValueError):
652+
tx.freeze()

tests/unit/transaction_test.py

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

33
from hiero_sdk_python.account.account_create_transaction import AccountCreateTransaction
44
from hiero_sdk_python.account.account_id import AccountId
5+
from hiero_sdk_python.consensus.topic_id import TopicId
6+
from hiero_sdk_python.consensus.topic_message_submit_transaction import TopicMessageSubmitTransaction
57
from hiero_sdk_python.crypto.private_key import PrivateKey
68
from hiero_sdk_python.exceptions import ReceiptStatusError
79
from hiero_sdk_python.file.file_append_transaction import FileAppendTransaction
@@ -27,7 +29,7 @@
2729

2830
@pytest.fixture
2931
def file_id():
30-
"""Returns a file_is for test."""
32+
"""Returns a file_id for test."""
3133
return FileId.from_string("0.0.1")
3234

3335

@@ -277,8 +279,8 @@ def test_tx_without_optional_fields_should_have_smaller_tx_body(
277279
assert tx1.body_size < tx2.body_size
278280

279281

280-
def test_chunk_tx_should_return_list_of_body_sizes(file_id, account_id, transaction_id):
281-
"""Test should return array of body sizes for multi-chunk transaction."""
282+
def test_file_append_chunk_tx_should_return_list_of_body_sizes(file_id, account_id, transaction_id):
283+
"""Test file append tx should return array of body sizes for multi-chunk transaction."""
282284
chunk_size = 1024
283285
content = "a" * (chunk_size * 3)
284286

@@ -297,8 +299,8 @@ def test_chunk_tx_should_return_list_of_body_sizes(file_id, account_id, transact
297299
assert len(sizes) == 3
298300

299301

300-
def test_single_chunk_tx_return_list_of_len_one(file_id, account_id, transaction_id):
301-
"""Test should return array of one size for single-chunk transaction."""
302+
def test_file_append_single_chunk_tx_return_list_of_len_one(file_id, account_id, transaction_id):
303+
"""Test file append tx should return array of one size for single-chunk transaction."""
302304
content = "small_content"
303305
tx = (
304306
FileAppendTransaction()
@@ -314,6 +316,43 @@ def test_single_chunk_tx_return_list_of_len_one(file_id, account_id, transaction
314316
assert len(sizes) == 1
315317

316318

319+
def test_message_submit_chunk_tx_should_return_list_of_body_sizes(topic_id, account_id, transaction_id):
320+
"""Test topic message submit tx should return array of body sizes for multi-chunk transaction."""
321+
chunk_size = 1024
322+
message= "a" * (chunk_size * 3)
323+
324+
tx = (
325+
TopicMessageSubmitTransaction()
326+
.set_topic_id(topic_id)
327+
.set_chunk_size(chunk_size)
328+
.set_message(message)
329+
.set_transaction_id(transaction_id)
330+
.set_node_account_id(account_id)
331+
.freeze()
332+
)
333+
334+
sizes = tx.body_size_all_chunks
335+
assert isinstance(sizes, list)
336+
assert len(sizes) == 3
337+
338+
339+
def test_message_submit_single_chunk_tx_return_list_of_len_one(topic_id, account_id, transaction_id):
340+
"""Test topic message submit tx should return array of one size for single-chunk transaction."""
341+
message = "small_content"
342+
tx = (
343+
TopicMessageSubmitTransaction()
344+
.set_topic_id(topic_id)
345+
.set_message(message)
346+
.set_transaction_id(transaction_id)
347+
.set_node_account_id(account_id)
348+
.freeze()
349+
)
350+
351+
sizes = tx.body_size_all_chunks
352+
assert isinstance(sizes, list)
353+
assert len(sizes) == 1
354+
355+
317356
def test_tx_with_no_content_should_return_single_body_chunk(
318357
file_id, account_id, transaction_id
319358
):

0 commit comments

Comments
 (0)