Skip to content

Commit 9607c9c

Browse files
chore(tests): format node unit tests with black (#1615)
Signed-off-by: SubhraSameerDash <[email protected]> Signed-off-by: Subhra Sameer Dash <[email protected]>
1 parent 0eb1188 commit 9607c9c

File tree

5 files changed

+176
-114
lines changed

5 files changed

+176
-114
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
1717
- Style: formatted `tests/unit/prng_transaction_test.py` with black (#1546)
1818
- Formatted contract unit tests with black for consistent style. (#1523)
1919
- Format account test files with Black (#1519)
20+
- Format `tests/unit/node*.py` with Black for consistent code style (#1545)
2021
- Improve unit test coverage for Hbar, including edge cases, validation, comparisons, and hashing. (#1483)
2122
- Standardize formatting of evm_address_test.py using Black for improved consistency and readability (#1529)
2223
- Formatted unit test files using Black.
@@ -217,7 +218,6 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
217218
- Enhance TopicInfo `__str__` method and tests with additional coverage, and update the format_key function in `key_format.py` to handle objects with a \_to_proto method.
218219
- Update changelog workflow to trigger automatically on pull requests instead of manual dispatch (#1567)
219220
- Formatted key-related unit test files (`key_utils_test.py`, `test_key_format.py`, `test_key_list.py`) using the black formatter
220-
- chore: update maintainer guidelines link in MAINTAINERS.md (#1605)
221221

222222
### Fixed
223223

tests/unit/node_address_test.py

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,34 @@
33
from hiero_sdk_python.account.account_id import AccountId
44
from hiero_sdk_python.address_book.endpoint import Endpoint
55
from hiero_sdk_python.address_book.node_address import NodeAddress
6-
from hiero_sdk_python.hapi.services.basic_types_pb2 import NodeAddress as NodeAddressProto
6+
from hiero_sdk_python.hapi.services.basic_types_pb2 import (
7+
NodeAddress as NodeAddressProto,
8+
)
9+
710
pytestmark = pytest.mark.unit
811

12+
913
def test_init():
1014
"""Test initialization of _NodeAddress."""
1115
# Create test data
1216
account_id = AccountId(0, 0, 123)
13-
addresses = [Endpoint(address=bytes("192.168.1.1", 'utf-8'), port=8080, domain_name="example.com")]
14-
cert_hash = b'sample-cert-hash'
15-
17+
addresses = [
18+
Endpoint(
19+
address=bytes("192.168.1.1", "utf-8"), port=8080, domain_name="example.com"
20+
)
21+
]
22+
cert_hash = b"sample-cert-hash"
23+
1624
# Initialize _NodeAddress
1725
node_address = NodeAddress(
1826
public_key="sample-public-key",
1927
account_id=account_id,
2028
node_id=1234,
2129
cert_hash=cert_hash,
2230
addresses=addresses,
23-
description="Sample Node"
31+
description="Sample Node",
2432
)
25-
33+
2634
# Assert properties are set correctly
2735
assert node_address._public_key == "sample-public-key"
2836
assert node_address._account_id == account_id
@@ -31,30 +39,35 @@ def test_init():
3139
assert node_address._addresses == addresses
3240
assert node_address._description == "Sample Node"
3341

42+
3443
def test_string_representation():
3544
"""Test string representation of _NodeAddress."""
3645
# Create AccountId
3746
account_id = AccountId(0, 0, 123)
38-
39-
# Create
40-
endpoint = Endpoint(address=bytes("192.168.1.1", 'utf-8'), port=8080, domain_name="example.com")
41-
47+
48+
# Create
49+
endpoint = Endpoint(
50+
address=bytes("192.168.1.1", "utf-8"), port=8080, domain_name="example.com"
51+
)
52+
4253
# Create NodeAddress
4354
node_address = NodeAddress(
4455
public_key="sample-public-key",
4556
account_id=account_id,
4657
node_id=1234,
47-
cert_hash=b'sample-cert-hash',
58+
cert_hash=b"sample-cert-hash",
4859
addresses=[endpoint],
49-
description="Sample Node"
60+
description="Sample Node",
5061
)
51-
62+
5263
# Get string representation
5364
result = str(node_address)
54-
65+
5566
# Check if expected fields are in the result
5667
assert "NodeAccountId: 0.0.123" in result
57-
assert "CertHash: 73616d706c652d636572742d68617368" in result # hex representation of sample-cert-hash
68+
assert (
69+
"CertHash: 73616d706c652d636572742d68617368" in result
70+
) # hex representation of sample-cert-hash
5871
assert "NodeId: 1234" in result
5972
assert "PubKey: sample-public-key" in result
6073

@@ -63,17 +76,23 @@ def test_to_proto():
6376
"""Test conversion of NodeAddress to protobuf with endpoints."""
6477
account_id = AccountId(0, 0, 123)
6578
endpoints = [
66-
Endpoint(address=bytes("192.168.1.1", "utf-8"), port=8080, domain_name="example1.com"),
67-
Endpoint(address=bytes("192.168.1.2", "utf-8"), port=8081, domain_name="example2.com"),
68-
Endpoint(address=bytes("192.168.1.3", "utf-8"), port=8082, domain_name="example3.com"),
79+
Endpoint(
80+
address=bytes("192.168.1.1", "utf-8"), port=8080, domain_name="example1.com"
81+
),
82+
Endpoint(
83+
address=bytes("192.168.1.2", "utf-8"), port=8081, domain_name="example2.com"
84+
),
85+
Endpoint(
86+
address=bytes("192.168.1.3", "utf-8"), port=8082, domain_name="example3.com"
87+
),
6988
]
7089
node_address = NodeAddress(
7190
public_key="sample-public-key",
7291
account_id=account_id,
7392
node_id=1234,
7493
cert_hash=b"sample-cert-hash",
7594
addresses=endpoints,
76-
description="Sample Node"
95+
description="Sample Node",
7796
)
7897

7998
node_address_proto = node_address._to_proto()
@@ -146,9 +165,7 @@ def test_from_proto():
146165
"""Test creation of NodeAddress from protobuf with endpoint."""
147166
account_id_proto = AccountId(0, 0, 123)._to_proto()
148167
endpoint_proto = Endpoint(
149-
address=bytes("192.168.1.1", "utf-8"),
150-
port=8080,
151-
domain_name="example.com"
168+
address=bytes("192.168.1.1", "utf-8"), port=8080, domain_name="example.com"
152169
)._to_proto()
153170

154171
# Create NodeAddressProto
@@ -178,9 +195,7 @@ def test_round_trip():
178195
"""Ensure NodeAddress → Proto → NodeAddress round trip works."""
179196
account_id = AccountId(0, 0, 123)
180197
endpoint = Endpoint(
181-
address=bytes("192.168.1.1", "utf-8"),
182-
port=8080,
183-
domain_name="example.com"
198+
address=bytes("192.168.1.1", "utf-8"), port=8080, domain_name="example.com"
184199
)
185200

186201
# Create NodeAddress
@@ -190,7 +205,7 @@ def test_round_trip():
190205
node_id=1234,
191206
cert_hash=b"sample-cert-hash",
192207
addresses=[endpoint],
193-
description="Sample Node"
208+
description="Sample Node",
194209
)
195210

196211
# Convert to proto
@@ -220,12 +235,13 @@ def test_empty_addresses():
220235
node_id=1234,
221236
cert_hash=b"sample-cert-hash",
222237
addresses=[],
223-
description="No endpoints"
238+
description="No endpoints",
224239
)
225240

226241
proto = node_address._to_proto()
227242
assert len(proto.serviceEndpoint) == 0
228243

244+
229245
def test_to_proto_none_account_id():
230246
"""Test _to_proto handles None account_id gracefully."""
231247
node_address = NodeAddress(
@@ -234,10 +250,10 @@ def test_to_proto_none_account_id():
234250
node_id=1234,
235251
cert_hash=b"sample-cert-hash",
236252
addresses=[],
237-
description="No account"
253+
description="No account",
238254
)
239255

240256
proto = node_address._to_proto()
241257

242258
# Should not have nodeAccountId set
243-
assert not proto.HasField('nodeAccountId')
259+
assert not proto.HasField("nodeAccountId")

tests/unit/node_create_transaction_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ def test_build_transaction_body_with_valid_parameters(mock_account_ids, node_par
104104
)
105105
assert len(node_create.service_endpoint) == 1
106106
assert (
107-
node_create.service_endpoint[0] == node_params["service_endpoints"][0]._to_proto()
107+
node_create.service_endpoint[0]
108+
== node_params["service_endpoints"][0]._to_proto()
108109
)
109110
assert node_create.gossip_ca_certificate == node_params["gossip_ca_certificate"]
110111
assert node_create.grpc_certificate_hash == node_params["grpc_certificate_hash"]
@@ -139,7 +140,8 @@ def test_build_scheduled_body(node_params):
139140
)
140141
assert len(node_create.service_endpoint) == 1
141142
assert (
142-
node_create.service_endpoint[0] == node_params["service_endpoints"][0]._to_proto()
143+
node_create.service_endpoint[0]
144+
== node_params["service_endpoints"][0]._to_proto()
143145
)
144146
assert node_create.gossip_ca_certificate == node_params["gossip_ca_certificate"]
145147
assert node_create.grpc_certificate_hash == node_params["grpc_certificate_hash"]

0 commit comments

Comments
 (0)