Skip to content

Commit 58a229d

Browse files
committed
feat: add HIP-1137 response codes to ResponseCode enum and implement unit tests
Signed-off-by: Ntege Daniel <danientege785@gmail.com>
1 parent 72dfda6 commit 58a229d

5 files changed

Lines changed: 51 additions & 4 deletions

File tree

docs/sdk_developers/hip_1137_coverage.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This document maps HIP-1137 concepts to current SDK implementation status.
1111
- Block: [src/hiero_sdk_python/address_book/block_node_service_endpoint.py](../../src/hiero_sdk_python/address_book/block_node_service_endpoint.py)
1212
- Mirror: [src/hiero_sdk_python/address_book/mirror_node_service_endpoint.py](../../src/hiero_sdk_python/address_book/mirror_node_service_endpoint.py)
1313
- RPC relay: [src/hiero_sdk_python/address_book/rpc_relay_service_endpoint.py](../../src/hiero_sdk_python/address_book/rpc_relay_service_endpoint.py)
14-
- General service (deferred/public API not exposed yet): [src/hiero_sdk_python/address_book/general_service_endpoint.py](../../src/hiero_sdk_python/address_book/general_service_endpoint.py)
14+
- General service: [src/hiero_sdk_python/address_book/general_service_endpoint.py](../../src/hiero_sdk_python/address_book/general_service_endpoint.py)
1515
- Registered node transactions:
1616
- Create: [src/hiero_sdk_python/nodes/registered_node_create_transaction.py](../../src/hiero_sdk_python/nodes/registered_node_create_transaction.py)
1717
- Update: [src/hiero_sdk_python/nodes/registered_node_update_transaction.py](../../src/hiero_sdk_python/nodes/registered_node_update_transaction.py)
@@ -21,6 +21,8 @@ This document maps HIP-1137 concepts to current SDK implementation status.
2121
- Consensus node association fields:
2222
- Create: [src/hiero_sdk_python/nodes/node_create_transaction.py](../../src/hiero_sdk_python/nodes/node_create_transaction.py)
2323
- Update (including clear semantics): [src/hiero_sdk_python/nodes/node_update_transaction.py](../../src/hiero_sdk_python/nodes/node_update_transaction.py)
24+
- HIP-1137 response codes (public SDK enum):
25+
- [src/hiero_sdk_python/response_code.py](../../src/hiero_sdk_python/response_code.py)
2426
- Registered node read models:
2527
- [src/hiero_sdk_python/address_book/registered_node.py](../../src/hiero_sdk_python/address_book/registered_node.py)
2628
- [src/hiero_sdk_python/address_book/registered_node_address_book.py](../../src/hiero_sdk_python/address_book/registered_node_address_book.py)
@@ -29,7 +31,8 @@ This document maps HIP-1137 concepts to current SDK implementation status.
2931

3032
- `RegisteredNodeAddressBookQuery` execution is intentionally deferred until mirror-node API support is defined, matching HIP guidance:
3133
[src/hiero_sdk_python/address_book/registered_node_address_book_query.py](../../src/hiero_sdk_python/address_book/registered_node_address_book_query.py)
32-
- `GeneralServiceEndpoint` protobuf subtype is not present in the currently generated schema for this repository. The SDK includes internal forward-compatible handling, but it is not a stable public top-level API until protobuf support lands.
34+
- End-to-end integration coverage for the registered-node lifecycle remains gated on environment/network support in CI:
35+
[tests/integration/registered_node_transaction_e2e_test.py](../../tests/integration/registered_node_transaction_e2e_test.py)
3336

3437
## Tests
3538

src/hiero_sdk_python/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
# Address book
1212
from .address_book.endpoint import Endpoint
13+
from .address_book.general_service_endpoint import GeneralServiceEndpoint
14+
from .address_book.mirror_node_service_endpoint import MirrorNodeServiceEndpoint
1315
from .address_book.node_address import NodeAddress
1416

1517
# Client and Network
@@ -235,6 +237,8 @@
235237
"AccountInfoQuery",
236238
# Address book
237239
"Endpoint",
240+
"GeneralServiceEndpoint",
241+
"MirrorNodeServiceEndpoint",
238242
"NodeAddress",
239243
# Logger
240244
"Logger",

src/hiero_sdk_python/address_book/block_node_service_endpoint.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ def __post_init__(self) -> None:
2626

2727
def _endpoint_type_proto(self) -> dict[str, RegisteredServiceEndpointProto.BlockNodeEndpoint]:
2828
"""Return the protobuf block-node subtype."""
29-
return {"block_node": RegisteredServiceEndpointProto.BlockNodeEndpoint(endpoint_api=int(self.endpoint_api))}
29+
return {"block_node": RegisteredServiceEndpointProto.BlockNodeEndpoint(endpoint_api=[int(self.endpoint_api)])}
3030

3131
@classmethod
3232
def _from_proto(cls, proto: RegisteredServiceEndpointProto) -> BlockNodeServiceEndpoint:
3333
"""Build a block node endpoint from protobuf."""
34+
endpoint_api = (
35+
BlockNodeApi(proto.block_node.endpoint_api[0])
36+
if len(proto.block_node.endpoint_api) > 0
37+
else BlockNodeApi.OTHER
38+
)
3439
return cls(
35-
endpoint_api=BlockNodeApi(proto.block_node.endpoint_api),
40+
endpoint_api=endpoint_api,
3641
**cls._base_kwargs_from_proto(proto),
3742
)

src/hiero_sdk_python/response_code.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,13 @@ class ResponseCode(IntEnum):
358358
MISSING_BATCH_KEY = 392
359359
BATCH_KEY_SET_ON_NON_INNER_TRANSACTION = 393
360360
INVALID_BATCH_KEY = 394
361+
INVALID_REGISTERED_NODE_ID = 529
362+
INVALID_REGISTERED_ENDPOINT = 530
363+
REGISTERED_ENDPOINTS_EXCEEDED_LIMIT = 531
364+
INVALID_REGISTERED_ENDPOINT_ADDRESS = 532
365+
INVALID_REGISTERED_ENDPOINT_TYPE = 533
366+
REGISTERED_NODE_STILL_ASSOCIATED = 534
367+
MAX_REGISTERED_NODES_EXCEEDED = 535
361368

362369
@classmethod
363370
def _missing_(cls, value: object) -> ResponseCode:

tests/unit/response_code_test.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Unit tests for ResponseCode enum mappings."""
2+
3+
from __future__ import annotations
4+
5+
import pytest
6+
7+
from hiero_sdk_python.response_code import ResponseCode
8+
9+
10+
pytestmark = pytest.mark.unit
11+
12+
13+
def test_hip_1137_response_codes_are_named_members():
14+
"""HIP-1137 response codes should be first-class enum members."""
15+
assert ResponseCode(529) is ResponseCode.INVALID_REGISTERED_NODE_ID
16+
assert ResponseCode(530) is ResponseCode.INVALID_REGISTERED_ENDPOINT
17+
assert ResponseCode(531) is ResponseCode.REGISTERED_ENDPOINTS_EXCEEDED_LIMIT
18+
assert ResponseCode(532) is ResponseCode.INVALID_REGISTERED_ENDPOINT_ADDRESS
19+
assert ResponseCode(533) is ResponseCode.INVALID_REGISTERED_ENDPOINT_TYPE
20+
assert ResponseCode(534) is ResponseCode.REGISTERED_NODE_STILL_ASSOCIATED
21+
assert ResponseCode(535) is ResponseCode.MAX_REGISTERED_NODES_EXCEEDED
22+
23+
24+
def test_unknown_response_code_still_uses_fallback_member():
25+
"""Unknown integer values should continue to map to UNKNOWN_CODE_<n>."""
26+
unknown_code = ResponseCode(9999)
27+
assert unknown_code.is_unknown
28+
assert unknown_code.name == "UNKNOWN_CODE_9999"

0 commit comments

Comments
 (0)