From 5c212986ff5bb6f3a32a79e5d6c420620660e173 Mon Sep 17 00:00:00 2001 From: Ricky Saechao Date: Mon, 26 Aug 2024 11:33:58 -0700 Subject: [PATCH] refactor: use ServiceEndpoint instead SocketAddressV4 for Node Signed-off-by: Ricky Saechao --- .../AddressBook/NodeCreateTransaction.swift | 20 ++--- .../AddressBook/NodeUpdateTransaction.swift | 20 ++--- Sources/Hedera/Endpoint.swift | 85 +++++++++++++++++++ .../Services/file_service.grpc.swift | 4 +- .../Services/network_service.grpc.swift | 6 +- .../smart_contract_service.grpc.swift | 4 +- .../NodeCreateTransactionTests.swift | 43 +++++----- .../NodeUpdateTransactionTests.swift | 45 +++++----- .../testSerialize.1.txt | 16 ++-- .../testSerialize.1.txt | 16 ++-- 10 files changed, 177 insertions(+), 82 deletions(-) create mode 100644 Sources/Hedera/Endpoint.swift diff --git a/Sources/Hedera/AddressBook/NodeCreateTransaction.swift b/Sources/Hedera/AddressBook/NodeCreateTransaction.swift index 66be932d..b01f7ba9 100644 --- a/Sources/Hedera/AddressBook/NodeCreateTransaction.swift +++ b/Sources/Hedera/AddressBook/NodeCreateTransaction.swift @@ -47,8 +47,8 @@ public final class NodeCreateTransaction: Transaction { public init( accountId: AccountId? = nil, description: String = "", - gossipEndpoints: [SocketAddressV4] = [], - serviceEndpoints: [SocketAddressV4] = [], + gossipEndpoints: [Endpoint] = [], + serviceEndpoints: [Endpoint] = [], gossipCaCertificate: Data? = nil, grpcCertificateHash: Data? = nil, adminKey: Key? = nil @@ -69,8 +69,8 @@ public final class NodeCreateTransaction: Transaction { ) throws { self.accountId = data.hasAccountID ? try .fromProtobuf(data.accountID) : nil self.description = data.description_p - self.gossipEndpoints = try data.gossipEndpoint.map(SocketAddressV4.init) - self.serviceEndpoints = try data.serviceEndpoint.map(SocketAddressV4.init) + self.gossipEndpoints = try data.gossipEndpoint.map(Endpoint.init) + self.serviceEndpoints = try data.serviceEndpoint.map(Endpoint.init) self.gossipCaCertificate = data.gossipCaCertificate self.grpcCertificateHash = data.grpcCertificateHash self.adminKey = data.hasAdminKey ? try .fromProtobuf(data.adminKey) : nil @@ -109,7 +109,7 @@ public final class NodeCreateTransaction: Transaction { } /// A list of service endpoints for gossip. - public var gossipEndpoints: [SocketAddressV4] { + public var gossipEndpoints: [Endpoint] { willSet { ensureNotFrozen() } @@ -117,7 +117,7 @@ public final class NodeCreateTransaction: Transaction { /// Assign the list of service endpoints for gossip. @discardableResult - public func gossipEndpoints(_ gossipEndpoints: [SocketAddressV4]) -> Self { + public func gossipEndpoints(_ gossipEndpoints: [Endpoint]) -> Self { self.gossipEndpoints = gossipEndpoints return self @@ -125,14 +125,14 @@ public final class NodeCreateTransaction: Transaction { /// Add an endpoint for gossip to the list of service endpoints for gossip. @discardableResult - public func addGossipEndpoint(_ gossipEndpoint: SocketAddressV4) -> Self { + public func addGossipEndpoint(_ gossipEndpoint: Endpoint) -> Self { self.gossipEndpoints.append(gossipEndpoint) return self } /// Extract the list of service endpoints for gRPC calls. - public var serviceEndpoints: [SocketAddressV4] { + public var serviceEndpoints: [Endpoint] { willSet { ensureNotFrozen() } @@ -140,7 +140,7 @@ public final class NodeCreateTransaction: Transaction { /// Assign the list of service endpoints for gRPC calls. @discardableResult - public func serviceEndpoints(_ serviceEndpoints: [SocketAddressV4]) -> Self { + public func serviceEndpoints(_ serviceEndpoints: [Endpoint]) -> Self { self.serviceEndpoints = serviceEndpoints return self @@ -148,7 +148,7 @@ public final class NodeCreateTransaction: Transaction { /// Add an endpoint for gRPC calls to the list of service endpoints for gRPC calls. @discardableResult - public func addServiceEndpoint(_ serviceEndpoint: SocketAddressV4) -> Self { + public func addServiceEndpoint(_ serviceEndpoint: Endpoint) -> Self { self.serviceEndpoints.append(serviceEndpoint) return self diff --git a/Sources/Hedera/AddressBook/NodeUpdateTransaction.swift b/Sources/Hedera/AddressBook/NodeUpdateTransaction.swift index 3faee168..0c7e2a9f 100644 --- a/Sources/Hedera/AddressBook/NodeUpdateTransaction.swift +++ b/Sources/Hedera/AddressBook/NodeUpdateTransaction.swift @@ -42,8 +42,8 @@ public final class NodeUpdateTransaction: Transaction { nodeId: UInt64 = 0, accountId: AccountId? = nil, description: String? = nil, - gossipEndpoints: [SocketAddressV4] = [], - serviceEndpoints: [SocketAddressV4] = [], + gossipEndpoints: [Endpoint] = [], + serviceEndpoints: [Endpoint] = [], gossipCaCertificate: Data? = nil, grpcCertificateHash: Data? = nil, adminKey: Key? = nil @@ -66,8 +66,8 @@ public final class NodeUpdateTransaction: Transaction { self.nodeId = data.nodeID self.accountId = data.hasAccountID ? try .fromProtobuf(data.accountID) : nil self.description = data.hasDescription_p ? data.description_p.value : nil - self.gossipEndpoints = try data.gossipEndpoint.map(SocketAddressV4.init) - self.serviceEndpoints = try data.serviceEndpoint.map(SocketAddressV4.init) + self.gossipEndpoints = try data.gossipEndpoint.map(Endpoint.init) + self.serviceEndpoints = try data.serviceEndpoint.map(Endpoint.init) self.gossipCaCertificate = data.hasGossipCaCertificate ? data.gossipCaCertificate.value : nil self.grpcCertificateHash = data.hasGrpcCertificateHash ? data.grpcCertificateHash.value : nil self.adminKey = data.hasAdminKey ? try .fromProtobuf(data.adminKey) : nil @@ -121,7 +121,7 @@ public final class NodeUpdateTransaction: Transaction { } /// A list of service endpoints for gossip. - public var gossipEndpoints: [SocketAddressV4] { + public var gossipEndpoints: [Endpoint] { willSet { ensureNotFrozen() } @@ -129,7 +129,7 @@ public final class NodeUpdateTransaction: Transaction { /// Assign the list of service endpoints for gossip. @discardableResult - public func gossipEndpoints(_ gossipEndpoints: [SocketAddressV4]) -> Self { + public func gossipEndpoints(_ gossipEndpoints: [Endpoint]) -> Self { self.gossipEndpoints = gossipEndpoints return self @@ -137,14 +137,14 @@ public final class NodeUpdateTransaction: Transaction { /// Add an endpoint for gossip to the list of service endpoints for gossip. @discardableResult - public func addGossipEndpoint(_ gossipEndpoint: SocketAddressV4) -> Self { + public func addGossipEndpoint(_ gossipEndpoint: Endpoint) -> Self { self.gossipEndpoints.append(gossipEndpoint) return self } /// Extract the list of service endpoints for gRPC calls. - public var serviceEndpoints: [SocketAddressV4] { + public var serviceEndpoints: [Endpoint] { willSet { ensureNotFrozen() } @@ -152,7 +152,7 @@ public final class NodeUpdateTransaction: Transaction { /// Assign the list of service endpoints for gRPC calls. @discardableResult - public func serviceEndpoints(_ serviceEndpoints: [SocketAddressV4]) -> Self { + public func serviceEndpoints(_ serviceEndpoints: [Endpoint]) -> Self { self.serviceEndpoints = serviceEndpoints return self @@ -160,7 +160,7 @@ public final class NodeUpdateTransaction: Transaction { /// Add an endpoint for gRPC calls to the list of service endpoints for gRPC calls. @discardableResult - public func addServiceEndpoint(_ serviceEndpoint: SocketAddressV4) -> Self { + public func addServiceEndpoint(_ serviceEndpoint: Endpoint) -> Self { self.serviceEndpoints.append(serviceEndpoint) return self diff --git a/Sources/Hedera/Endpoint.swift b/Sources/Hedera/Endpoint.swift new file mode 100644 index 00000000..bde4387b --- /dev/null +++ b/Sources/Hedera/Endpoint.swift @@ -0,0 +1,85 @@ +/* + * ‌ + * Hedera Swift SDK + * ​ + * Copyright (C) 2022 - 2024 Hedera Hashgraph, LLC + * ​ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ‍ + */ + +import Foundation +import HederaProtobufs +import Network + +public struct Endpoint { + public var ipAddress: IPv4Address? = nil + + public var port: Int32 = 0 + + public var domainName: String = "" + + public init(ipAddress: IPv4Address? = nil, port: Int32 = 0, domainName: String = "") { + self.ipAddress = ipAddress + self.port = port + self.domainName = domainName + } + + @discardableResult + public mutating func address(_ ipAddress: IPv4Address) -> Self { + self.ipAddress = ipAddress + return self + } + + @discardableResult + public mutating func port(_ port: Int32) -> Self { + self.port = port + return self + } + + @discardableResult + public mutating func domainName(_ domainName: String) -> Self { + self.domainName = domainName + return self + } + + public var description: String { + guard !domainName.isEmpty else { + return "\(ipAddress.debugDescription):\(port)" + } + return "\(domainName):\(port)" + } +} +extension Endpoint: TryProtobufCodable { + internal typealias Protobuf = Proto_ServiceEndpoint + + internal init(protobuf proto: Protobuf) throws { + let ipAddress = IPv4Address(proto.ipAddressV4) + + var port = proto.port + + if proto.port == 0 || proto.port == 50111 { + port = 50211 + } + + self.init(ipAddress: ipAddress, port: port, domainName: proto.domainName) + } + + internal func toProtobuf() -> Protobuf { + .with { proto in + proto.ipAddressV4 = ipAddress?.rawValue ?? Data() + proto.port = port + proto.domainName = domainName + } + } +} diff --git a/Sources/HederaProtobufs/Services/file_service.grpc.swift b/Sources/HederaProtobufs/Services/file_service.grpc.swift index 052e3cf8..1051194e 100644 --- a/Sources/HederaProtobufs/Services/file_service.grpc.swift +++ b/Sources/HederaProtobufs/Services/file_service.grpc.swift @@ -12,7 +12,7 @@ import SwiftProtobuf ///* -/// Transactions and queries for the file service. +/// Transactions and queries for the file service. /// /// Usage: instantiate `Proto_FileServiceClient`, then call methods of this protocol to make API calls. public protocol Proto_FileServiceClientProtocol: GRPCClient { @@ -276,7 +276,7 @@ public struct Proto_FileServiceNIOClient: Proto_FileServiceClientProtocol { } ///* -/// Transactions and queries for the file service. +/// Transactions and queries for the file service. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) public protocol Proto_FileServiceAsyncClientProtocol: GRPCClient { static var serviceDescriptor: GRPCServiceDescriptor { get } diff --git a/Sources/HederaProtobufs/Services/network_service.grpc.swift b/Sources/HederaProtobufs/Services/network_service.grpc.swift index 75fa571a..6d8e092a 100644 --- a/Sources/HederaProtobufs/Services/network_service.grpc.swift +++ b/Sources/HederaProtobufs/Services/network_service.grpc.swift @@ -65,9 +65,9 @@ extension Proto_NetworkServiceClientProtocol { } ///* - /// Retrieves the time in nanoseconds spent in handleTransaction for one or more - /// TransactionIDs (assuming they have reached consensus "recently", since only a limited - /// number of execution times are kept in-memory, depending on the value of the node-local + /// Retrieves the time in nanoseconds spent in handleTransaction for one or more + /// TransactionIDs (assuming they have reached consensus "recently", since only a limited + /// number of execution times are kept in-memory, depending on the value of the node-local /// property stats.executionTimesToTrack). /// /// - Parameters: diff --git a/Sources/HederaProtobufs/Services/smart_contract_service.grpc.swift b/Sources/HederaProtobufs/Services/smart_contract_service.grpc.swift index 6ca3f73c..9b5453e3 100644 --- a/Sources/HederaProtobufs/Services/smart_contract_service.grpc.swift +++ b/Sources/HederaProtobufs/Services/smart_contract_service.grpc.swift @@ -12,7 +12,7 @@ import SwiftProtobuf ///* -/// Transactions and queries for the file service. +/// Transactions and queries for the file service. /// /// Usage: instantiate `Proto_SmartContractServiceClient`, then call methods of this protocol to make API calls. public protocol Proto_SmartContractServiceClientProtocol: GRPCClient { @@ -373,7 +373,7 @@ public struct Proto_SmartContractServiceNIOClient: Proto_SmartContractServiceCli } ///* -/// Transactions and queries for the file service. +/// Transactions and queries for the file service. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) public protocol Proto_SmartContractServiceAsyncClientProtocol: GRPCClient { static var serviceDescriptor: GRPCServiceDescriptor { get } diff --git a/Tests/HederaTests/NodeCreateTransactionTests.swift b/Tests/HederaTests/NodeCreateTransactionTests.swift index 40ca3c77..e3a342c0 100644 --- a/Tests/HederaTests/NodeCreateTransactionTests.swift +++ b/Tests/HederaTests/NodeCreateTransactionTests.swift @@ -19,6 +19,7 @@ */ import HederaProtobufs +import Network import SnapshotTesting import XCTest @@ -29,8 +30,12 @@ internal final class NodeCreateTransactionTests: XCTestCase { internal static let testGossipCertificate = Data([0x01, 0x02, 0x03, 0x04]) internal static let testGrpcCertificateHash = Data([0x05, 0x06, 0x07, 0x08]) - private static func makeIpv4AddressList() throws -> [SocketAddressV4] { - [SocketAddressV4("127.0.0.1:50222")!, SocketAddressV4("127.0.0.1:50212")!] + private static func spawnTestEndpoint(offset: Int32) -> Endpoint { + Endpoint(ipAddress: IPv4Address("127.0.0.1:50222"), port: 42 + offset, domainName: "unit.test.com") + } + + private static func spawnTestEndpointList(offset: Int32) -> [Endpoint] { + [Self.spawnTestEndpoint(offset: offset), Self.spawnTestEndpoint(offset: offset + 1)] } private static func makeTransaction() throws -> NodeCreateTransaction { @@ -42,8 +47,8 @@ internal final class NodeCreateTransactionTests: XCTestCase { ) .accountId(AccountId.fromString("0.0.5007")) .description(testDescription) - .gossipEndpoints(try Self.makeIpv4AddressList()) - .serviceEndpoints(try Self.makeIpv4AddressList()) + .gossipEndpoints(spawnTestEndpointList(offset: 0)) + .serviceEndpoints(spawnTestEndpointList(offset: 2)) .gossipCaCertificate(Self.testGossipCertificate) .grpcCertificateHash(Self.testGrpcCertificateHash) .adminKey(Key.single(Resources.privateKey.publicKey)) @@ -65,18 +70,18 @@ internal final class NodeCreateTransactionTests: XCTestCase { } internal func testFromProtoBody() throws { - let protoData = try Com_Hedera_Hapi_Node_Addressbook_NodeCreateTransactionBody.with { proto in + let gossipEndpoints = Self.spawnTestEndpointList(offset: 0) + let serviceEndpoints = Self.spawnTestEndpointList(offset: 2) + let protoData = Com_Hedera_Hapi_Node_Addressbook_NodeCreateTransactionBody.with { proto in proto.accountID = Resources.accountId.toProtobuf() proto.description_p = Self.testDescription - proto.gossipEndpoint = try Self.makeIpv4AddressList().map { $0.toProtobuf() } - proto.serviceEndpoint = try Self.makeIpv4AddressList().map { $0.toProtobuf() } + proto.gossipEndpoint = gossipEndpoints.map { $0.toProtobuf() } + proto.serviceEndpoint = serviceEndpoints.map { $0.toProtobuf() } proto.gossipCaCertificate = Self.testGossipCertificate proto.grpcCertificateHash = Self.testGrpcCertificateHash proto.adminKey = Key.single(Resources.publicKey).toProtobuf() } - let endpoints = try Self.makeIpv4AddressList() - let protoBody = Proto_TransactionBody.with { proto in proto.nodeCreate = protoData proto.transactionID = Resources.txId.toProtobuf() @@ -93,15 +98,15 @@ internal final class NodeCreateTransactionTests: XCTestCase { XCTAssertEqual(tx.serviceEndpoints.count, 2) for (index, endpoint) in tx.gossipEndpoints.enumerated() { - XCTAssertEqual(endpoint.ip, endpoints[index].ip) - XCTAssertEqual(endpoint.port, endpoints[index].port) - XCTAssertEqual(endpoint.domainName, endpoints[index].domainName) + XCTAssertEqual(endpoint.ipAddress, gossipEndpoints[index].ipAddress) + XCTAssertEqual(endpoint.port, gossipEndpoints[index].port) + XCTAssertEqual(endpoint.domainName, gossipEndpoints[index].domainName) } for (index, endpoint) in tx.serviceEndpoints.enumerated() { - XCTAssertEqual(endpoint.ip, endpoints[index].ip) - XCTAssertEqual(endpoint.port, endpoints[index].port) - XCTAssertEqual(endpoint.domainName, endpoints[index].domainName) + XCTAssertEqual(endpoint.ipAddress, serviceEndpoints[index].ipAddress) + XCTAssertEqual(endpoint.port, serviceEndpoints[index].port) + XCTAssertEqual(endpoint.domainName, serviceEndpoints[index].domainName) } } @@ -128,11 +133,11 @@ internal final class NodeCreateTransactionTests: XCTestCase { internal func testGetSetGossipEndpoints() throws { let tx = NodeCreateTransaction() - let endpoints = try Self.makeIpv4AddressList() + let endpoints = Self.spawnTestEndpointList(offset: Int32(0)) tx.gossipEndpoints(endpoints) for (index, endpoint) in tx.gossipEndpoints.enumerated() { - XCTAssertEqual(endpoint.ip, endpoints[index].ip) + XCTAssertEqual(endpoint.ipAddress, endpoints[index].ipAddress) XCTAssertEqual(endpoint.port, endpoints[index].port) XCTAssertEqual(endpoint.domainName, endpoints[index].domainName) } @@ -140,11 +145,11 @@ internal final class NodeCreateTransactionTests: XCTestCase { internal func testGetSetServiceEndpoints() throws { let tx = NodeCreateTransaction() - let endpoints = try Self.makeIpv4AddressList() + let endpoints = Self.spawnTestEndpointList(offset: Int32(2)) tx.serviceEndpoints(endpoints) for (index, endpoint) in tx.serviceEndpoints.enumerated() { - XCTAssertEqual(endpoint.ip, endpoints[index].ip) + XCTAssertEqual(endpoint.ipAddress, endpoints[index].ipAddress) XCTAssertEqual(endpoint.port, endpoints[index].port) XCTAssertEqual(endpoint.domainName, endpoints[index].domainName) } diff --git a/Tests/HederaTests/NodeUpdateTransactionTests.swift b/Tests/HederaTests/NodeUpdateTransactionTests.swift index 477bd9f2..a7669a5b 100644 --- a/Tests/HederaTests/NodeUpdateTransactionTests.swift +++ b/Tests/HederaTests/NodeUpdateTransactionTests.swift @@ -19,6 +19,7 @@ */ import HederaProtobufs +import Network import SnapshotTesting import SwiftProtobuf import XCTest @@ -30,8 +31,12 @@ internal final class NodeUpdateTransactionTests: XCTestCase { internal static let testGossipCertificate = Data([0x01, 0x02, 0x03, 0x04]) internal static let testGrpcCertificateHash = Data([0x05, 0x06, 0x07, 0x08]) - private static func makeIpv4AddressList() throws -> [SocketAddressV4] { - [SocketAddressV4("127.0.0.1:50222")!, SocketAddressV4("127.0.0.1:50212")!] + private static func spawnTestEndpoint(offset: Int32) -> Endpoint { + Endpoint(ipAddress: IPv4Address("127.0.0.1:50211"), port: 20 + offset, domainName: "unit.test.com") + } + + private static func spawnTestEndpointList(offset: Int32) -> [Endpoint] { + [Self.spawnTestEndpoint(offset: offset), Self.spawnTestEndpoint(offset: offset + 1)] } private static func makeTransaction() throws -> NodeUpdateTransaction { @@ -44,8 +49,8 @@ internal final class NodeUpdateTransactionTests: XCTestCase { ) .accountId(AccountId.fromString("0.0.5007")) .description(testDescription) - .gossipEndpoints(try Self.makeIpv4AddressList()) - .serviceEndpoints(try Self.makeIpv4AddressList()) + .gossipEndpoints(Self.spawnTestEndpointList(offset: 1)) + .serviceEndpoints(Self.spawnTestEndpointList(offset: 3)) .gossipCaCertificate(Self.testGossipCertificate) .grpcCertificateHash(Self.testGrpcCertificateHash) .adminKey(Key.single(Resources.privateKey.publicKey)) @@ -67,18 +72,18 @@ internal final class NodeUpdateTransactionTests: XCTestCase { } internal func testFromProtoBody() throws { - let protoData = try Com_Hedera_Hapi_Node_Addressbook_NodeUpdateTransactionBody.with { proto in + let gossipEndpoints = Self.spawnTestEndpointList(offset: 1) + let serviceEndpoints = Self.spawnTestEndpointList(offset: 3) + let protoData = Com_Hedera_Hapi_Node_Addressbook_NodeUpdateTransactionBody.with { proto in proto.accountID = Resources.accountId.toProtobuf() proto.description_p = Google_Protobuf_StringValue(Self.testDescription) - proto.gossipEndpoint = try Self.makeIpv4AddressList().map { $0.toProtobuf() } - proto.serviceEndpoint = try Self.makeIpv4AddressList().map { $0.toProtobuf() } + proto.gossipEndpoint = gossipEndpoints.map { $0.toProtobuf() } + proto.serviceEndpoint = serviceEndpoints.map { $0.toProtobuf() } proto.gossipCaCertificate = Google_Protobuf_BytesValue(Self.testGossipCertificate) proto.grpcCertificateHash = Google_Protobuf_BytesValue(Self.testGrpcCertificateHash) proto.adminKey = Key.single(Resources.publicKey).toProtobuf() } - let endpoints = try Self.makeIpv4AddressList() - let protoBody = Proto_TransactionBody.with { proto in proto.nodeUpdate = protoData proto.transactionID = Resources.txId.toProtobuf() @@ -86,7 +91,7 @@ internal final class NodeUpdateTransactionTests: XCTestCase { let tx = try NodeUpdateTransaction(protobuf: protoBody, protoData) - XCTAssertEqual(tx.nodeId, 1) + XCTAssertEqual(tx.nodeId, 0) XCTAssertEqual(tx.accountId, Resources.accountId) XCTAssertEqual(tx.adminKey, Key.single(Resources.publicKey)) XCTAssertEqual(tx.description, Self.testDescription) @@ -96,15 +101,15 @@ internal final class NodeUpdateTransactionTests: XCTestCase { XCTAssertEqual(tx.serviceEndpoints.count, 2) for (index, endpoint) in tx.gossipEndpoints.enumerated() { - XCTAssertEqual(endpoint.ip, endpoints[index].ip) - XCTAssertEqual(endpoint.port, endpoints[index].port) - XCTAssertEqual(endpoint.domainName, endpoints[index].domainName) + XCTAssertEqual(endpoint.ipAddress, gossipEndpoints[index].ipAddress) + XCTAssertEqual(endpoint.port, gossipEndpoints[index].port) + XCTAssertEqual(endpoint.domainName, gossipEndpoints[index].domainName) } for (index, endpoint) in tx.serviceEndpoints.enumerated() { - XCTAssertEqual(endpoint.ip, endpoints[index].ip) - XCTAssertEqual(endpoint.port, endpoints[index].port) - XCTAssertEqual(endpoint.domainName, endpoints[index].domainName) + XCTAssertEqual(endpoint.ipAddress, serviceEndpoints[index].ipAddress) + XCTAssertEqual(endpoint.port, serviceEndpoints[index].port) + XCTAssertEqual(endpoint.domainName, serviceEndpoints[index].domainName) } } @@ -138,11 +143,11 @@ internal final class NodeUpdateTransactionTests: XCTestCase { internal func testGetSetGossipEndpoints() throws { let tx = NodeUpdateTransaction() - let endpoints = try Self.makeIpv4AddressList() + let endpoints = Self.spawnTestEndpointList(offset: Int32(4)) tx.gossipEndpoints(endpoints) for (index, endpoint) in tx.gossipEndpoints.enumerated() { - XCTAssertEqual(endpoint.ip, endpoints[index].ip) + XCTAssertEqual(endpoint.ipAddress, endpoints[index].ipAddress) XCTAssertEqual(endpoint.port, endpoints[index].port) XCTAssertEqual(endpoint.domainName, endpoints[index].domainName) } @@ -150,11 +155,11 @@ internal final class NodeUpdateTransactionTests: XCTestCase { internal func testGetSetServiceEndpoints() throws { let tx = NodeUpdateTransaction() - let endpoints = try Self.makeIpv4AddressList() + let endpoints = Self.spawnTestEndpointList(offset: Int32(4)) tx.serviceEndpoints(endpoints) for (index, endpoint) in tx.serviceEndpoints.enumerated() { - XCTAssertEqual(endpoint.ip, endpoints[index].ip) + XCTAssertEqual(endpoint.ipAddress, endpoints[index].ipAddress) XCTAssertEqual(endpoint.port, endpoints[index].port) XCTAssertEqual(endpoint.domainName, endpoints[index].domainName) } diff --git a/Tests/HederaTests/__Snapshots__/NodeCreateTransactionTests/testSerialize.1.txt b/Tests/HederaTests/__Snapshots__/NodeCreateTransactionTests/testSerialize.1.txt index 2479c4bb..5c49d95a 100644 --- a/Tests/HederaTests/__Snapshots__/NodeCreateTransactionTests/testSerialize.1.txt +++ b/Tests/HederaTests/__Snapshots__/NodeCreateTransactionTests/testSerialize.1.txt @@ -20,20 +20,20 @@ nodeCreate { } description: "test description" gossip_endpoint { - ipAddressV4: "\177\000\000\001" - port: 50222 + port: 42 + domain_name: "unit.test.com" } gossip_endpoint { - ipAddressV4: "\177\000\000\001" - port: 50212 + port: 43 + domain_name: "unit.test.com" } service_endpoint { - ipAddressV4: "\177\000\000\001" - port: 50222 + port: 44 + domain_name: "unit.test.com" } service_endpoint { - ipAddressV4: "\177\000\000\001" - port: 50212 + port: 45 + domain_name: "unit.test.com" } gossip_ca_certificate: "\001\002\003\004" grpc_certificate_hash: "\005\006\007\b" diff --git a/Tests/HederaTests/__Snapshots__/NodeUpdateTransactionTests/testSerialize.1.txt b/Tests/HederaTests/__Snapshots__/NodeUpdateTransactionTests/testSerialize.1.txt index 41747beb..1978d25a 100644 --- a/Tests/HederaTests/__Snapshots__/NodeUpdateTransactionTests/testSerialize.1.txt +++ b/Tests/HederaTests/__Snapshots__/NodeUpdateTransactionTests/testSerialize.1.txt @@ -23,20 +23,20 @@ nodeUpdate { value: "test description" } gossip_endpoint { - ipAddressV4: "\177\000\000\001" - port: 50222 + port: 21 + domain_name: "unit.test.com" } gossip_endpoint { - ipAddressV4: "\177\000\000\001" - port: 50212 + port: 22 + domain_name: "unit.test.com" } service_endpoint { - ipAddressV4: "\177\000\000\001" - port: 50222 + port: 23 + domain_name: "unit.test.com" } service_endpoint { - ipAddressV4: "\177\000\000\001" - port: 50212 + port: 24 + domain_name: "unit.test.com" } gossip_ca_certificate { value: "\001\002\003\004"