Skip to content

Commit b69e4b0

Browse files
authored
feat(topic): add add_fee_exempt_key to TopicUpdateTransaction (hiero-ledger#2612)
Signed-off-by: achintya2k5 <achintyasin@gmail.com>
1 parent e8ed509 commit b69e4b0

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

src/hiero_sdk_python/consensus/topic_update_transaction.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,27 @@ def add_custom_fee(self, custom_fee: CustomFixedFee) -> TopicUpdateTransaction:
234234
self.custom_fees.append(custom_fee)
235235
return self
236236

237+
def add_fee_exempt_key(self, key: Key) -> TopicUpdateTransaction:
238+
"""
239+
Adds a single fee exempt key to the transaction's fee exempt key list.
240+
241+
Args:
242+
key (Key): The fee exempt key to add.
243+
244+
Returns:
245+
TopicUpdateTransaction: The current instance for method chaining.
246+
"""
247+
self._require_not_frozen()
248+
249+
if not isinstance(key, Key):
250+
raise TypeError("key must be a Key")
251+
252+
if self.fee_exempt_keys is None:
253+
self.fee_exempt_keys = []
254+
255+
self.fee_exempt_keys.append(key)
256+
return self
257+
237258
def clear_custom_fees(self) -> TopicUpdateTransaction:
238259
"""
239260
Clears the custom fees for the topic update transaction and

tests/unit/topic_update_transaction_test.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,3 +486,49 @@ def test_add_custom_fee_type_error():
486486
with pytest.raises(TypeError, match="custom_fee must be a CustomFixedFee"):
487487
tx.add_custom_fee(None) # type: ignore
488488
assert tx.custom_fees is None, "Invalid input must not change custom_fees"
489+
490+
491+
def test_add_fee_exempt_key():
492+
"""Test adding a fee exempt key to the transaction."""
493+
tx = TopicUpdateTransaction()
494+
495+
key1 = PrivateKey.generate().public_key()
496+
key2 = PrivateKey.generate().public_key()
497+
498+
result = tx.add_fee_exempt_key(key1)
499+
500+
assert len(tx.fee_exempt_keys) == 1
501+
assert tx.fee_exempt_keys[0] == key1
502+
assert result is tx
503+
504+
tx.add_fee_exempt_key(key2)
505+
506+
assert len(tx.fee_exempt_keys) == 2
507+
assert tx.fee_exempt_keys[0] == key1
508+
assert tx.fee_exempt_keys[1] == key2
509+
510+
511+
def test_add_fee_exempt_key_frozen(mock_client, topic_id):
512+
"""Test calling add_fee_exempt_key() after freezing raises an exception."""
513+
tx = TopicUpdateTransaction()
514+
515+
tx.set_topic_id(topic_id)
516+
tx.freeze_with(mock_client)
517+
518+
key = PrivateKey.generate().public_key()
519+
520+
with pytest.raises(Exception, match="Transaction is immutable; it has been frozen"):
521+
tx.add_fee_exempt_key(key)
522+
523+
524+
def test_add_fee_exempt_key_type_error():
525+
"""Test passing None or a non-Key argument raises TypeError."""
526+
tx = TopicUpdateTransaction()
527+
528+
with pytest.raises(TypeError, match="key must be a Key"):
529+
tx.add_fee_exempt_key("this_is_a_string") # type: ignore
530+
assert tx.fee_exempt_keys is None, "Invalid input must not change fee_exempt_keys"
531+
532+
with pytest.raises(TypeError, match="key must be a Key"):
533+
tx.add_fee_exempt_key(None) # type: ignore
534+
assert tx.fee_exempt_keys is None, "Invalid input must not change fee_exempt_keys"

0 commit comments

Comments
 (0)