Skip to content

Commit a494f8a

Browse files
committed
fix(file): serialize explicit empty key list in FileUpdateTransaction
Signed-off-by: anchit-goel <anchitgoel5@gmail.com>
1 parent efab8cb commit a494f8a

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/hiero_sdk_python/file/file_update_transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def _build_proto_body(self):
164164
"""
165165
return FileUpdateTransactionBody(
166166
fileID=self.file_id._to_proto() if self.file_id is not None else None,
167-
keys=(KeyListProto(keys=[key._to_proto() for key in self.keys]) if self.keys else None),
167+
keys=(KeyListProto(keys=[key._to_proto() for key in self.keys]) if self.keys is not None else None),
168168
contents=self.contents if self.contents is not None else b"",
169169
expirationTime=(self.expiration_time._to_protobuf() if self.expiration_time else None),
170170
memo=(StringValue(value=self.file_memo) if self.file_memo is not None else None),

tests/unit/file_update_transaction_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,21 @@ def test_build_transaction_body_with_optional_fields(mock_account_ids, file_id):
202202
assert not transaction_body.fileUpdate.HasField("memo")
203203

204204

205+
def test_build_transaction_body_with_empty_keys(mock_account_ids, file_id):
206+
"""Test building transaction body with an explicit empty keys list sets empty KeyList proto."""
207+
operator_id, _, node_account_id, _, _ = mock_account_ids
208+
209+
file_tx = FileUpdateTransaction(file_id=file_id)
210+
file_tx.operator_account_id = operator_id
211+
file_tx.set_node_account_ids([node_account_id])
212+
file_tx.set_keys([])
213+
214+
transaction_body = file_tx.build_transaction_body()
215+
216+
assert transaction_body.fileUpdate.HasField("keys")
217+
assert len(transaction_body.fileUpdate.keys.keys) == 0
218+
219+
205220
def test_build_scheduled_body(mock_account_ids, file_id):
206221
"""Test building a schedulable file update transaction body."""
207222
operator_id, _, node_account_id, _, _ = mock_account_ids

0 commit comments

Comments
 (0)