Skip to content

Commit 7ef0514

Browse files
authored
feat: Update TopicUpdate Transaction (#2479)
Signed-off-by: aceppaluni <aceppaluni@gmail.com>
1 parent d18f803 commit 7ef0514

2 files changed

Lines changed: 24 additions & 12 deletions

File tree

src/hiero_sdk_python/consensus/topic_update_transaction.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from hiero_sdk_python.crypto.key import Key
1414
from hiero_sdk_python.Duration import Duration
1515
from hiero_sdk_python.executable import _Method
16-
from hiero_sdk_python.hapi.services import consensus_update_topic_pb2, duration_pb2, timestamp_pb2, transaction_pb2
16+
from hiero_sdk_python.hapi.services import consensus_update_topic_pb2, duration_pb2, transaction_pb2
1717
from hiero_sdk_python.hapi.services.custom_fees_pb2 import FeeExemptKeyList, FixedCustomFeeList
1818
from hiero_sdk_python.hapi.services.schedulable_transaction_body_pb2 import (
1919
SchedulableTransactionBody,
@@ -33,7 +33,7 @@ def __init__(
3333
memo: str | None = None,
3434
admin_key: Key | None = None,
3535
submit_key: Key | None = None,
36-
auto_renew_period: Duration | None = Duration(7890000),
36+
auto_renew_period: Duration | None = None,
3737
auto_renew_account: AccountId | None = None,
3838
expiration_time: Timestamp | None = None,
3939
custom_fees: list[CustomFixedFee] | None = None,
@@ -157,7 +157,7 @@ def set_auto_renew_account(self, account_id: AccountId) -> TopicUpdateTransactio
157157
self.auto_renew_account = account_id
158158
return self
159159

160-
def set_expiration_time(self, expiration_time: timestamp_pb2.Timestamp) -> TopicUpdateTransaction:
160+
def set_expiration_time(self, expiration_time: Timestamp) -> TopicUpdateTransaction:
161161
"""
162162
Sets the expiration time for the topic.
163163
@@ -243,12 +243,7 @@ def _build_proto_body(self) -> consensus_update_topic_pb2.ConsensusUpdateTopicTr
243243
244244
Returns:
245245
ConsensusUpdateTopicTransactionBody: The protobuf body for this transaction.
246-
247-
Raises:
248-
ValueError: If required fields are missing.
249246
"""
250-
if self.topic_id is None:
251-
raise ValueError("Missing required fields: topic_id")
252247

253248
custom_fees = (
254249
FixedCustomFeeList(fees=[custom_fee._to_topic_fee_proto() for custom_fee in self.custom_fees])
@@ -263,7 +258,7 @@ def _build_proto_body(self) -> consensus_update_topic_pb2.ConsensusUpdateTopicTr
263258
)
264259

265260
return consensus_update_topic_pb2.ConsensusUpdateTopicTransactionBody(
266-
topicID=self.topic_id._to_proto(),
261+
topicID=self.topic_id._to_proto() if self.topic_id else None,
267262
adminKey=key_to_proto(self.admin_key) if self.admin_key else None,
268263
submitKey=key_to_proto(self.submit_key) if self.submit_key else None,
269264
autoRenewPeriod=(

tests/unit/topic_update_transaction_test.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,16 @@ def test_build_scheduled_body(topic_id):
260260

261261
# This test uses fixture mock_account_ids as parameter
262262
def test_missing_topic_id_in_update(mock_account_ids):
263-
"""Test that building fails if no topic ID is provided."""
263+
"""Test that a missing topic ID is deferred to network validation."""
264264
_, _, node_account_id, _, _ = mock_account_ids
265265

266266
tx = TopicUpdateTransaction(topic_id=None, memo="No ID")
267267
tx.operator_account_id = AccountId(0, 0, 2)
268268
tx.node_account_id = node_account_id
269269

270-
with pytest.raises(ValueError, match="Missing required fields"):
271-
tx.build_transaction_body()
270+
transaction_body = tx.build_transaction_body()
271+
272+
assert not transaction_body.consensusUpdateTopic.HasField("topicID")
272273

273274

274275
# This test uses fixtures (mock_account_ids, topic_id, private_key) as parameters
@@ -424,3 +425,19 @@ def test_topic_memo_serialization_distinguishes_unset_and_empty(
424425
body = tx.build_transaction_body().consensusUpdateTopic
425426
assert body.HasField("memo")
426427
assert body.memo.value == "hello"
428+
429+
430+
def test_auto_renew_period_omitted_when_unset(
431+
mock_account_ids,
432+
topic_id,
433+
):
434+
"""Unset auto-renew period should not be serialized."""
435+
_, _, node_account_id, _, _ = mock_account_ids
436+
437+
tx = TopicUpdateTransaction(topic_id=topic_id)
438+
tx.operator_account_id = AccountId(0, 0, 2)
439+
tx.node_account_id = node_account_id
440+
441+
body = tx.build_transaction_body().consensusUpdateTopic
442+
443+
assert not body.HasField("autoRenewPeriod")

0 commit comments

Comments
 (0)