Skip to content

Commit 1b471c9

Browse files
committed
feat: added unit and integration test for chuck message
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
1 parent 9f63b04 commit 1b471c9

File tree

5 files changed

+199
-8
lines changed

5 files changed

+199
-8
lines changed

src/hiero_sdk_python/consensus/topic_message.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,13 @@ def of_many(cls, responses: List[mirror_proto.ConsensusTopicResponse]) -> "Topic
103103
chunks: List[TopicMessageChunk] = []
104104
total_size: int = 0
105105
transaction_id: Optional[str] = None
106-
106+
107107
for r in sorted_responses:
108108
c = TopicMessageChunk(r)
109109
chunks.append(c)
110+
110111
total_size += len(r.message)
112+
111113

112114
if (
113115
transaction_id is None
@@ -116,11 +118,13 @@ def of_many(cls, responses: List[mirror_proto.ConsensusTopicResponse]) -> "Topic
116118
):
117119
tx_id = r.chunkInfo.initialTransactionID
118120
transaction_id = (
119-
f"{tx_id.shardNum}.{tx_id.realmNum}.{tx_id.accountNum}-"
121+
f"{tx_id.accountID.shardNum, '0'}.{tx_id.accountID.realmNum, '0'}.{tx_id.accountID.accountNum}-"
120122
f"{tx_id.transactionValidStart.seconds}.{tx_id.transactionValidStart.nanos}"
121123
)
124+
print(transaction_id)
122125

123126
contents = bytearray(total_size)
127+
124128
offset: int = 0
125129
for r in sorted_responses:
126130
end = offset + len(r.message)

src/hiero_sdk_python/consensus/topic_message_submit_transaction.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ def execute(self, client: "Client"):
289289
print(self.get_required_chunks())
290290

291291
for chunk_index in range(self.get_required_chunks()):
292-
print(chunk_index)
293292
self._current_index = chunk_index
294293

295294
if self._transaction_ids and chunk_index < len(self._transaction_ids):

src/hiero_sdk_python/query/topic_message_query.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,21 @@ def run_stream():
144144
continue
145145

146146
initial_tx_id = response.chunkInfo.initialTransactionID
147-
tx_id_str = (f"{initial_tx_id.shardNum}."
148-
f"{initial_tx_id.realmNum}."
149-
f"{initial_tx_id.accountNum}-"
147+
tx_id_str = (f"{initial_tx_id.accountID.shardNum or '0'}."
148+
f"{initial_tx_id.accountID.realmNum or '0'}."
149+
f"{initial_tx_id.accountID.accountNum}-"
150150
f"{initial_tx_id.transactionValidStart.seconds}."
151151
f"{initial_tx_id.transactionValidStart.nanos}")
152+
152153
if tx_id_str not in pending_chunks:
153154
pending_chunks[tx_id_str] = []
155+
154156
pending_chunks[tx_id_str].append(response)
155157

156-
if len(pending_chunks[tx_id_str]) == response.chunkInfo.total:
157-
chunk_list = pending_chunks.pop(tx_id_str)
158+
if len(pending_chunks) == response.chunkInfo.total:
159+
chunk_list = [resp for chunk_list in pending_chunks.values() for resp in chunk_list]
160+
pending_chunks.clear()
161+
158162
msg_obj = TopicMessage.of_many(chunk_list)
159163
on_message(msg_obj)
160164

@@ -164,6 +168,7 @@ def run_stream():
164168

165169
except Exception as e:
166170
if subscription_handle.is_cancelled():
171+
167172
return
168173

169174
attempt += 1

0 commit comments

Comments
 (0)