Skip to content

Commit ddef21e

Browse files
committed
chore: fix docstrings and tests
Signed-off-by: oGranny <ogranny.github.io@gmail.com>
1 parent 75ce116 commit ddef21e

2 files changed

Lines changed: 37 additions & 6 deletions

File tree

src/hiero_sdk_python/consensus/topic_update_transaction.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ def __init__(
5151
auto_renew_period (Duration): The auto-renew period for the topic.
5252
auto_renew_account (AccountId): The account ID for auto-renewal.
5353
expiration_time (Timestamp): The expiration time of the topic.
54+
custom_fees (list[CustomFixedFee]): A list of custom fees to set for the topic.
55+
fee_schedule_key (Key): The fee schedule key for the topic.
56+
fee_exempt_keys (list[Key]): A list of fee exempt keys for the topic
5457
"""
5558
super().__init__()
5659
self.topic_id: TopicId | None = topic_id
@@ -95,10 +98,10 @@ def set_memo(self, memo: str) -> TopicUpdateTransaction:
9598

9699
def set_admin_key(self, key: Key) -> TopicUpdateTransaction:
97100
"""
98-
Sets the public admin key for the topic.
101+
Sets the admin key for the topic.
99102
100103
Args:
101-
Key: The admin key to set.
104+
key: The admin key to set.
102105
103106
Returns:
104107
TopicUpdateTransaction: Returns the instance for method chaining.
@@ -109,10 +112,10 @@ def set_admin_key(self, key: Key) -> TopicUpdateTransaction:
109112

110113
def set_submit_key(self, key: Key) -> TopicUpdateTransaction:
111114
"""
112-
Sets the public submit key for the topic.
115+
Sets the submit key for the topic.
113116
114117
Args:
115-
Key: The submit key to set.
118+
key: The submit key to set.
116119
117120
Returns:
118121
TopicUpdateTransaction: Returns the instance for method chaining.

tests/unit/topic_update_transaction_test.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ def create_key(key_type: str, use_private: bool) -> PrivateKey | PublicKey:
3939
Returns:
4040
The created key (PrivateKey or PublicKey)
4141
"""
42-
private_key = PrivateKey.generate_ed25519() if key_type == "ed25519" else PrivateKey.generate("ecdsa")
42+
if key_type == "ed25519":
43+
private_key = PrivateKey.generate_ed25519()
44+
elif key_type == "ecdsa":
45+
private_key = PrivateKey.generate("ecdsa")
46+
else:
47+
raise ValueError(f"Unsupported key_type: {key_type!r}")
4348
return private_key if use_private else private_key.public_key()
4449

4550

@@ -60,9 +65,32 @@ def verify_key_in_proto(proto_key, expected_public_key: PublicKey, key_type: str
6065
"""Verify the proto key matches expected public key."""
6166
if key_type == "ed25519":
6267
assert proto_key.ed25519 == expected_public_key.to_bytes_raw()
63-
else: # ecdsa
68+
elif key_type == "ecdsa": # ecdsa
6469
assert proto_key.HasField("ECDSA_secp256k1")
6570
assert proto_key.ECDSA_secp256k1 == expected_public_key.to_bytes_raw()
71+
else:
72+
raise ValueError(f"Unsupported key_type: {key_type!r}")
73+
74+
75+
@pytest.mark.parametrize(
76+
"key_type,use_private",
77+
[
78+
("ed25519", True),
79+
("ed25519", False),
80+
("ecdsa", True),
81+
("ecdsa", False),
82+
],
83+
)
84+
def test_topic_update_setters_return_self(key_type, use_private, topic_id):
85+
"""Fluent setters must return self for the Key-typed API."""
86+
key = create_key(key_type, use_private)
87+
tx = TopicUpdateTransaction()
88+
89+
assert tx.set_topic_id(topic_id) is tx
90+
assert tx.set_admin_key(key) is tx
91+
assert tx.set_submit_key(key) is tx
92+
assert tx.set_fee_schedule_key(key) is tx
93+
assert tx.set_fee_exempt_keys([key]) is tx
6694

6795

6896
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)