Skip to content

Commit

Permalink
fix: Do not override service port (#2106)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Ivanov <[email protected]>
  • Loading branch information
0xivanov authored Nov 29, 2024
1 parent d88f7b4 commit 914af7f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
4 changes: 0 additions & 4 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/Endpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ public Endpoint() {
static Endpoint fromProtobuf(ServiceEndpoint serviceEndpoint) {
var port = (int) (serviceEndpoint.getPort() & 0x00000000ffffffffL);

if (port == 0 || port == 50111) {
port = 50211;
}

return new Endpoint()
.setAddress(serviceEndpoint.getIpAddressV4().toByteArray())
.setPort(port)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class NodeCreateTransactionTest {
private static final byte[] TEST_GRPC_CERTIFICATE_HASH = new byte[]{5, 6, 7, 8, 9};

private static final PublicKey TEST_ADMIN_KEY = PrivateKey.fromString(
"302e020100300506032b65700422042062c4b69e9f45a554e5424fb5a6fe5e6ac1f19ead31dc7718c2d980fd1f998d4b")
"302e020100300506032b65700422042062c4b69e9f45a554e5424fb5a6fe5e6ac1f19ead31dc7718c2d980fd1f998d4b")
.getPublicKey();

final Instant TEST_VALID_START = Instant.ofEpochSecond(1554158542);
Expand All @@ -83,7 +83,7 @@ void shouldSerialize() {

private static Endpoint spawnTestEndpoint(byte offset) {
return new Endpoint()
.setAddress(new byte[] {0x00, 0x01, 0x02, 0x03})
.setAddress(new byte[]{0x00, 0x01, 0x02, 0x03})
.setDomainName(offset + "unit.test.com")
.setPort(42 + offset);
}
Expand Down Expand Up @@ -123,17 +123,26 @@ void fromScheduledTransaction() {
}

@Test
void testSerializeDeserialize() throws Exception {
var tx = new NodeCreateTransaction().setDescription(TEST_DESCRIPTION);
var tx2 = new NodeCreateTransaction().setDescription(TEST_DESCRIPTION);
var tx2Bytes = tx2.toBytes();
NodeCreateTransaction deserializedTx2 = (NodeCreateTransaction) Transaction.fromBytes(tx2Bytes);
assertThat(tx.getGossipCaCertificate()).isEqualTo(deserializedTx2.getGossipCaCertificate());
assertThat(tx.getGrpcCertificateHash()).isEqualTo(deserializedTx2.getGrpcCertificateHash());
void testUnrecognizedServicePort() throws Exception {
var tx = new NodeCreateTransaction()
.setServiceEndpoints(
List.of(new Endpoint()
.setAddress(new byte[]{0x00, 0x01, 0x02, 0x03})
.setDomainName("unit.test.com")
.setPort(50111)));
var tx2 = NodeCreateTransaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void testNullOptionalValues() throws Exception {
var tx = new NodeCreateTransaction();
var tx2 = NodeCreateTransaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void testSetNull() {
void testSetNull() {
new NodeCreateTransaction()
.setDescription(null)
.setAccountId(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void shouldSerialize() {

private static Endpoint spawnTestEndpoint(byte offset) {
return new Endpoint()
.setAddress(new byte[] {0x00, 0x01, 0x02, 0x03})
.setAddress(new byte[]{0x00, 0x01, 0x02, 0x03})
.setDomainName(offset + "unit.test.com")
.setPort(42 + offset);
}
Expand Down Expand Up @@ -120,11 +120,20 @@ void shouldBytes() throws Exception {
@Test
void testNullOptionalValues() throws Exception {
var tx = new NodeUpdateTransaction();
var tx2Bytes = tx.toBytes();
NodeUpdateTransaction deserializedTx = (NodeUpdateTransaction) Transaction.fromBytes(tx2Bytes);
assertThat(deserializedTx.getGossipCaCertificate()).isNull();
assertThat(deserializedTx.getGrpcCertificateHash()).isNull();
assertThat(deserializedTx.getDescription()).isNull();
var tx2 = NodeUpdateTransaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void testUnrecognizedServicePort() throws Exception {
var tx = new NodeUpdateTransaction()
.setServiceEndpoints(
List.of(new Endpoint()
.setAddress(new byte[]{0x00, 0x01, 0x02, 0x03})
.setDomainName("unit.test.com")
.setPort(50111)));
var tx2 = NodeUpdateTransaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
Expand All @@ -139,7 +148,7 @@ void testEmptyCertificates() throws Exception {
}

@Test
void testSetNull() {
void testSetNull() {
new NodeUpdateTransaction()
.setDescription(null)
.setAccountId(null)
Expand Down

0 comments on commit 914af7f

Please sign in to comment.