Skip to content

Commit

Permalink
fix: do not override service port
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Ivanov <[email protected]>
  • Loading branch information
0xivanov committed Nov 28, 2024
1 parent dff3bef commit 8ab2853
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 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 @@ -123,13 +123,23 @@ 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 tx2Bytes = tx.toBytes();
NodeCreateTransaction deserializedTx = (NodeCreateTransaction) Transaction.fromBytes(tx2Bytes);
assertThat(tx.getServiceEndpoints()).isEqualTo(deserializedTx.getServiceEndpoints());
}

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

@Test
Expand Down
Original file line number Diff line number Diff line change
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 Down

0 comments on commit 8ab2853

Please sign in to comment.