Skip to content

Commit

Permalink
chore: update from main
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Ivanov <[email protected]>
  • Loading branch information
0xivanov committed Dec 2, 2024
2 parents aa6f575 + 18ac2a0 commit 7bdf672
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 29 deletions.
14 changes: 7 additions & 7 deletions sdk-dependency-versions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ dependencies.constraints {
api("com.google.code.gson:gson:2.10.1") {
because("com.google.gson")
}
api("com.google.protobuf:protobuf-java:4.28.3") {
api("com.google.protobuf:protobuf-java:4.29.0") {
// shouldn't be updated for now (breaking changes after 4.x.x)
because("com.google.protobuf")
}
api("com.google.protobuf:protobuf-javalite:4.28.3") {
api("com.google.protobuf:protobuf-javalite:4.29.0") {
// shouldn't be updated for now (breaking changes after 4.x.x)
because("com.google.protobuf")
}
api("io.grpc:grpc-api:1.68.1") {
api("io.grpc:grpc-api:1.68.2") {
because("io.grpc")
}
api("io.grpc:grpc-inprocess:1.67.1") {
because("io.grpc.protobuf")
}
api("io.grpc:grpc-protobuf:1.68.1") {
api("io.grpc:grpc-protobuf:1.68.2") {
because("io.grpc.protobuf")
}
api("io.grpc:grpc-protobuf-lite:1.68.1") {
api("io.grpc:grpc-protobuf-lite:1.68.2") {
because("io.grpc.protobuf")
}
api("io.grpc:grpc-stub:1.68.1") {
api("io.grpc:grpc-stub:1.68.2") {
because("io.grpc.stub")
}
api("com.google.code.findbugs:jsr305:3.0.2") {
Expand All @@ -69,7 +69,7 @@ dependencies.constraints {
}

// Testing
api("com.fasterxml.jackson.core:jackson-core:2.18.1") {
api("com.fasterxml.jackson.core:jackson-core:2.18.2") {
because("com.fasterxml.jackson.core")
}
api("io.github.cdimascio:java-dotenv:5.3.1") {
Expand Down
12 changes: 1 addition & 11 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/BaseNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,8 @@ synchronized void close(Duration timeout) throws InterruptedException {
* @return the user agent string
*/
private String getUserAgent() {
var theModule = getClass().getModule();
var thePackage = getClass().getPackage();
String implementationVersion;
if (theModule.getName() == null) {
// running on classpath
implementationVersion =
thePackage != null ? thePackage.getImplementationVersion() : null;
} else {
// running on module path
implementationVersion =
theModule.getDescriptor().version().map(ModuleDescriptor.Version::toString).orElse(null);
}
var implementationVersion = thePackage != null ? thePackage.getImplementationVersion() : null;
return "hedera-sdk-java/" + ((implementationVersion != null) ? ("v" + implementationVersion) : "DEV");
}
}
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
5 changes: 3 additions & 2 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionId.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Objects;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.BiConsumer;
Expand Down Expand Up @@ -69,7 +70,6 @@ public final class TransactionId implements Comparable<TransactionId> {

private static final long NANOSECONDS_TO_REMOVE = 10000000000L;

private static final Random randomNanosecs = new Random();
private static final AtomicLong monotonicTime = new AtomicLong();


Expand Down Expand Up @@ -128,7 +128,8 @@ public static TransactionId generate(AccountId accountId) {
}
} while (!monotonicTime.compareAndSet(lastTime, currentTime));

return new TransactionId(accountId, Instant.ofEpochSecond(0, currentTime + randomNanosecs.nextLong(1_000)));
// NOTE: using ThreadLocalRandom because it's compatible with Android SDK version 26
return new TransactionId(accountId, Instant.ofEpochSecond(0, currentTime + ThreadLocalRandom.current().nextLong(1_000)));
}

/**
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 @@ -131,7 +131,19 @@ void shouldBytesNoSetters() throws Exception {
}

@Test
void testSetNull() {
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 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 @@ -124,6 +124,18 @@ void shouldBytesNoSetters() throws Exception {
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
void testEmptyCertificates() throws Exception {
var tx = new NodeUpdateTransaction()
Expand All @@ -136,7 +148,7 @@ void testEmptyCertificates() throws Exception {
}

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

0 comments on commit 7bdf672

Please sign in to comment.