Skip to content

Commit e77b4b9

Browse files
committed
chore:added review changes
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
1 parent cecccf1 commit e77b4b9

2 files changed

Lines changed: 87 additions & 12 deletions

File tree

src/hiero_sdk_python/transaction/transaction_response.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,17 @@ def get_receipt_query(self, validate_status: bool = False, client: Client | None
4545
4646
Returns:
4747
TransactionGetReceiptQuery: A configured receipt query.
48+
49+
Raises:
50+
TypeError: If `validate_status` is not a bool or `client` is not a Client.
4851
"""
4952
from hiero_sdk_python.query.transaction_get_receipt_query import TransactionGetReceiptQuery
5053

51-
if client is None or not client.allow_receipt_node_failover:
52-
return (
53-
TransactionGetReceiptQuery()
54-
.set_transaction_id(self.transaction_id)
55-
.set_node_account_ids([self.node_id])
56-
.set_validate_status(validate_status)
57-
)
54+
if not isinstance(validate_status, bool):
55+
raise TypeError("validate_status must be a boolean")
56+
57+
if client is not None and not isinstance(client, Client):
58+
raise TypeError("client must be an instance of Client")
5859

5960
node_account_ids = self._resolve_node_account_ids(client)
6061
return (
@@ -90,11 +91,14 @@ def get_record_query(self, client: Client | None = None):
9091
9192
Returns:
9293
TransactionRecordQuery: A configured record query.
94+
95+
Raises:
96+
TypeError: If `client` is not a Client.
9397
"""
9498
from hiero_sdk_python.query.transaction_record_query import TransactionRecordQuery
9599

96-
if client is None or not client.allow_receipt_node_failover:
97-
return TransactionRecordQuery().set_transaction_id(self.transaction_id).set_node_account_ids([self.node_id])
100+
if client is not None and not isinstance(client, Client):
101+
raise TypeError("client must be an instance of Client")
98102

99103
node_account_ids = self._resolve_node_account_ids(client)
100104
return TransactionRecordQuery().set_transaction_id(self.transaction_id).set_node_account_ids(node_account_ids)
@@ -114,8 +118,11 @@ def get_record(self, client: Client, timeout: int | float | None = None) -> Tran
114118

115119
def _resolve_node_account_ids(self, client: Client) -> list[AccountId]:
116120
"""Resolve node account IDs for receipt or record query failover."""
117-
available_node_ids = self._transaction_node_ids if self._transaction_node_ids else client.get_node_account_ids()
118-
119121
node_account_ids = [self.node_id]
122+
123+
if client is None or not client.allow_receipt_node_failover:
124+
return node_account_ids
125+
126+
available_node_ids = self._transaction_node_ids if self._transaction_node_ids else client.get_node_account_ids()
120127
node_account_ids.extend(node_id for node_id in available_node_ids if node_id != self.node_id)
121128
return node_account_ids

tests/unit/transaction_response_test.py

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import pytest
1313

1414
from hiero_sdk_python.account.account_id import AccountId
15+
from hiero_sdk_python.client.client import Client
1516
from hiero_sdk_python.exceptions import ReceiptStatusError
1617
from hiero_sdk_python.hapi.services import (
1718
basic_types_pb2,
@@ -253,6 +254,73 @@ def test_transaction_response_get_receipt_is_pinned_to_submitting_node(
253254
assert receipt.status == ResponseCode.SUCCESS
254255

255256

257+
@pytest.mark.parametrize("status", [1, 1.2, None, Client(), "True", [], {}])
258+
def test_get_receipt_query_invalid_status_type(status):
259+
"""Test that get_receipt_query raises TypeError for an invalid status type."""
260+
response = TransactionResponse()
261+
with pytest.raises(TypeError, match="validate_status must be a boolean"):
262+
response.get_receipt_query(validate_status=status)
263+
264+
265+
@pytest.mark.parametrize(
266+
"client",
267+
[1, 1.2, True, "True", [], {}], # None is allow for client
268+
)
269+
def test_get_receipt_query_invalid_client_type(client):
270+
"""Test that get_receipt_query raises TypeError for an invalid client type."""
271+
response = TransactionResponse()
272+
with pytest.raises(TypeError, match="client must be an instance of Client"):
273+
response.get_receipt_query(client=client)
274+
275+
276+
@pytest.mark.parametrize(
277+
"client",
278+
[1, 1.2, True, "True", [], {}], # None is allow for client
279+
)
280+
def test_get_record_query_invalid_client_type(client):
281+
"""Test that get_record_query raises TypeError for an invalid client type."""
282+
response = TransactionResponse()
283+
with pytest.raises(TypeError, match="client must be an instance of Client"):
284+
response.get_record_query(client=client)
285+
286+
287+
def test_resolve_node_account_ids_with_failover_diabled(mock_client):
288+
"""Test that only the transaction node is returned when no client or failover is disabled."""
289+
response = TransactionResponse()
290+
response.node_id = AccountId.from_string("0.0.3")
291+
292+
# When client is None
293+
node_ids = response._resolve_node_account_ids(None)
294+
assert node_ids == [AccountId.from_string("0.0.3")]
295+
296+
# With failover disabled
297+
node_ids = response._resolve_node_account_ids(mock_client)
298+
assert node_ids == [AccountId.from_string("0.0.3")]
299+
300+
301+
def test_resolve_node_account_ids_with_transaction_nodes(mock_client):
302+
"""Test that transaction nodes are used when receipt failover is enabled."""
303+
response = TransactionResponse()
304+
response.node_id = AccountId.from_string("0.0.3")
305+
response._transaction_node_ids = [AccountId.from_string("0.0.3"), AccountId.from_string("0.0.4")]
306+
307+
mock_client.set_allow_receipt_node_failover(True)
308+
node_ids = response._resolve_node_account_ids(mock_client)
309+
assert node_ids == [AccountId.from_string("0.0.3"), AccountId.from_string("0.0.4")]
310+
311+
312+
def test_resolve_node_account_ids_uses_client_nodes_when_transaction_nodes_unavailable(mock_client):
313+
"""Test that client nodes are used when transaction nodes are unavailable."""
314+
response = TransactionResponse()
315+
response.node_id = AccountId.from_string("0.0.3")
316+
response._transaction_node_ids = []
317+
318+
mock_client.set_allow_receipt_node_failover(True)
319+
node_ids = response._resolve_node_account_ids(mock_client)
320+
321+
assert node_ids == mock_client.get_node_account_ids()
322+
323+
256324
def test_default_receipt_query_is_pinned_to_submitting_node(mock_client):
257325
"""Test that receipt queries use only the submitting node by default."""
258326
node_id = AccountId.from_string("0.0.4")
@@ -271,7 +339,7 @@ def test_default_receipt_query_is_pinned_to_submitting_node(mock_client):
271339
assert query.node_account_ids == [node_id]
272340

273341
# With failover disabled
274-
query = response.get_receipt_query(mock_client)
342+
query = response.get_receipt_query(client=mock_client)
275343
assert isinstance(query, TransactionGetReceiptQuery)
276344
assert query.node_account_ids == [node_id]
277345

0 commit comments

Comments
 (0)