Skip to content

Commit aeeaa92

Browse files
committed
test(topic): add memo collision regression tests
Signed-off-by: iron-prog <dt915725@gmail.com>
1 parent 4c8cdc6 commit aeeaa92

2 files changed

Lines changed: 48 additions & 2 deletions

File tree

tests/unit/topic_create_transaction_test.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def test_constructor(multiple_custom_fees, key_type, use_private):
328328
fee_exempt_keys=fee_exempt_keys,
329329
)
330330

331-
assert tx.memo == "Test Topic"
331+
assert tx.topic_memo == "Test Topic"
332332
assert tx.admin_key == admin_key
333333
assert tx.submit_key == submit_key
334334
assert tx.custom_fees == multiple_custom_fees
@@ -339,7 +339,7 @@ def test_constructor(multiple_custom_fees, key_type, use_private):
339339
def test_constructor_default_values():
340340
"""Test constructor with default values."""
341341
tx_default = TopicCreateTransaction()
342-
assert tx_default.memo == ""
342+
assert tx_default.topic_memo == ""
343343
assert tx_default.admin_key is None
344344
assert tx_default.submit_key is None
345345
assert tx_default.custom_fees == []
@@ -627,3 +627,27 @@ def test_freeze_with_leaves_auto_renew_account_unset_without_operator(mock_clien
627627
body = frozen_tx.build_transaction_body()
628628

629629
assert not body.consensusCreateTopic.HasField("autoRenewAccount")
630+
631+
632+
def test_topic_memo_does_not_collide_with_transaction_memo():
633+
"""Regression test for: topic and transaction memos remain independent."""
634+
tx = TopicCreateTransaction(memo="my topic memo")
635+
assert tx.topic_memo == "my topic memo"
636+
assert tx.memo == "" # base Transaction-level memo defaults independently
637+
638+
tx.set_transaction_memo("some unrelated audit note")
639+
640+
assert tx.topic_memo == "my topic memo", "topic_memo was clobbered by set_transaction_memo()"
641+
assert tx.memo == "some unrelated audit note"
642+
643+
644+
def test_topic_memo_reflected_in_protobuf_independent_of_transaction_memo(mock_client):
645+
"""Verify protobuf preserves separate topic and transaction memos."""
646+
tx = TopicCreateTransaction(memo="my topic memo")
647+
tx.set_transaction_memo("some unrelated audit note")
648+
tx.transaction_id = TransactionId.generate(AccountId(0, 0, 1234))
649+
frozen_tx = tx.freeze_with(mock_client)
650+
body = frozen_tx.build_transaction_body()
651+
652+
assert body.consensusCreateTopic.memo == "my topic memo"
653+
assert body.memo == "some unrelated audit note"

tests/unit/topic_update_transaction_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,25 @@ def test_topic_update_transaction_with_all_fields(topic_id):
359359

360360
# Verify the receipt contains the expected values
361361
assert receipt.status == ResponseCode.SUCCESS
362+
363+
364+
def test_topic_memo_does_not_collide_with_transaction_memo():
365+
"""Regression test for: topic and transaction memos remain independent."""
366+
tx = TopicUpdateTransaction(memo="my topic memo")
367+
assert tx.topic_memo == "my topic memo"
368+
assert tx.memo == "" # base Transaction-level memo defaults independently
369+
370+
tx.set_transaction_memo("some unrelated audit note")
371+
372+
assert tx.topic_memo == "my topic memo", "topic_memo was clobbered by set_transaction_memo()"
373+
assert tx.memo == "some unrelated audit note"
374+
375+
376+
def test_set_memo_updates_topic_memo_only():
377+
"""Verify set_memo() only updates the topic memo."""
378+
tx = TopicUpdateTransaction()
379+
tx.set_transaction_memo("audit note")
380+
tx.set_memo("new topic memo")
381+
382+
assert tx.topic_memo == "new topic memo"
383+
assert tx.memo == "audit note"

0 commit comments

Comments
 (0)