1- import importlib
1+ """Unit tests for the GetAccountInfo TCK endpoint."""
2+
23from unittest .mock import MagicMock , patch
34
45import pytest
56
6- from hiero_sdk_python .Duration import Duration
77from hiero_sdk_python .account .account_id import AccountId
88from hiero_sdk_python .account .account_info import AccountInfo
99from hiero_sdk_python .crypto .private_key import PrivateKey
10+ from hiero_sdk_python .Duration import Duration
1011from hiero_sdk_python .exceptions import PrecheckError
1112from hiero_sdk_python .hbar import Hbar
1213from hiero_sdk_python .response_code import ResponseCode
1819from hiero_sdk_python .tokens .token_relationship import TokenRelationship
1920from tck .errors import HIERO_ERROR , JsonRpcError
2021from tck .handlers import registry
22+ from tck .handlers .account import get_account_info
2123from tck .handlers .registry import dispatch
2224from tck .param .account import GetAccountInfoParams
2325from tck .util import client_utils
2628
2729
2830@pytest .fixture (autouse = True )
29- def clear_registry_and_clients ():
31+ def setup_registry_and_clients ():
32+ """Reset handler and client registries for isolated test execution."""
3033 registry ._HANDLERS .clear ()
3134 client_utils ._CLIENTS .clear ()
3235
33- import tck . handlers . account as account_handlers
36+ registry . rpc_method ( "getAccountInfo" )( get_account_info )
3437
35- importlib .reload (account_handlers )
3638 yield
3739
3840 registry ._HANDLERS .clear ()
@@ -41,17 +43,20 @@ def clear_registry_and_clients():
4143
4244@pytest .fixture
4345def params_dict ():
46+ """Provide a valid getAccountInfo request payload."""
4447 return {"accountId" : "0.0.123" , "sessionId" : "sess1" }
4548
4649
4750def test_parse_json_params_success (params_dict ):
51+ """parse_json_params should parse both accountId and sessionId."""
4852 params = GetAccountInfoParams .parse_json_params (params_dict )
4953
5054 assert params .accountId == "0.0.123"
5155 assert params .sessionId == "sess1"
5256
5357
5458def test_parse_json_params_missing_account_id_defaults_to_none ():
59+ """parse_json_params should allow missing accountId and keep it None."""
5560 params = GetAccountInfoParams .parse_json_params ({"sessionId" : "sess1" })
5661
5762 assert params .accountId is None
@@ -61,6 +66,7 @@ def test_parse_json_params_missing_account_id_defaults_to_none():
6166@patch ("tck.handlers.account.get_client" )
6267@patch ("hiero_sdk_python.query.account_info_query.AccountInfoQuery.execute" )
6368def test_get_account_info_success_mapping (mock_execute , mock_get_client , params_dict ):
69+ """Endpoint should map AccountInfo response fields to TCK response shape."""
6470 mock_get_client .return_value = MagicMock ()
6571
6672 key = PrivateKey .generate_ed25519 ().public_key ()
@@ -142,6 +148,7 @@ def test_get_account_info_success_mapping(mock_execute, mock_get_client, params_
142148
143149
144150def test_get_account_info_missing_account_id_maps_to_hiero_error ():
151+ """Missing accountId should map to HIERO_ERROR with INVALID_ACCOUNT_ID."""
145152 with pytest .raises (JsonRpcError ) as exception :
146153 dispatch ("getAccountInfo" , {"sessionId" : "sess1" })
147154
@@ -150,6 +157,7 @@ def test_get_account_info_missing_account_id_maps_to_hiero_error():
150157
151158
152159def test_get_account_info_invalid_account_id_maps_to_hiero_error ():
160+ """Malformed accountId should map to HIERO_ERROR with INVALID_ACCOUNT_ID."""
153161 with pytest .raises (JsonRpcError ) as exception :
154162 dispatch ("getAccountInfo" , {"sessionId" : "sess1" , "accountId" : "invalid-id" })
155163
@@ -160,6 +168,7 @@ def test_get_account_info_invalid_account_id_maps_to_hiero_error():
160168@patch ("tck.handlers.account.get_client" )
161169@patch ("hiero_sdk_python.query.account_info_query.AccountInfoQuery.execute" )
162170def test_get_account_info_precheck_error_maps_to_hiero_error (mock_execute , mock_get_client ):
171+ """SDK PrecheckError should map to HIERO_ERROR preserving response status."""
163172 mock_get_client .return_value = MagicMock ()
164173 mock_execute .side_effect = PrecheckError (status = ResponseCode .ACCOUNT_DELETED )
165174
0 commit comments