Skip to content

Commit

Permalink
chore: fix empty array scenario
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Ivanov <[email protected]>
  • Loading branch information
0xivanov committed Nov 22, 2024
1 parent a5faab7 commit 7ed4ad8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -464,13 +464,13 @@ void initFromTransactionBody() {
serviceEndpoints.add(Endpoint.fromProtobuf(serviceEndpoint));
}

var protobufGossipCert = body.getGossipCaCertificate();
gossipCaCertificate = protobufGossipCert.equals(BytesValue.getDefaultInstance()) ?
null : protobufGossipCert.getValue().toByteArray();
if (body.hasGossipCaCertificate()) {
gossipCaCertificate = body.getGossipCaCertificate().getValue().toByteArray();
}

var protobufGrpcCert = body.getGrpcCertificateHash();
grpcCertificateHash = protobufGrpcCert.equals(BytesValue.getDefaultInstance()) ?
null : protobufGrpcCert.getValue().toByteArray();
if (body.hasGrpcCertificateHash()) {
grpcCertificateHash = body.getGrpcCertificateHash().getValue().toByteArray();
}

if (body.hasAdminKey()) {
adminKey = Key.fromProtobufKey(body.getAdminKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,25 @@ void shouldBytes() throws Exception {
var tx2 = NodeUpdateTransaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void testNullCertificates() throws Exception {
var tx = new NodeUpdateTransaction();
var tx2Bytes = tx.toBytes();
NodeUpdateTransaction deserializedTx = (NodeUpdateTransaction) Transaction.fromBytes(tx2Bytes);
assertThat(deserializedTx.getGossipCaCertificate()).isNull();
assertThat(deserializedTx.getGrpcCertificateHash()).isNull();
}

@Test
void testSerializeDeserialize() throws Exception {
var tx = new NodeUpdateTransaction().setDescription(TEST_DESCRIPTION);
var tx2 = new NodeUpdateTransaction().setDescription(TEST_DESCRIPTION);
var tx2Bytes = tx2.toBytes();
NodeUpdateTransaction deserializedTx2 = (NodeUpdateTransaction) Transaction.fromBytes(tx2Bytes);
assertThat(tx.getGossipCaCertificate()).isEqualTo(deserializedTx2.getGossipCaCertificate());
assertThat(tx.getGrpcCertificateHash()).isEqualTo(deserializedTx2.getGrpcCertificateHash());
void testEmptyCertificates() throws Exception {
var tx = new NodeUpdateTransaction()
.setGossipCaCertificate(new byte[]{})
.setGrpcCertificateHash(new byte[]{});
var tx2Bytes = tx.toBytes();
NodeUpdateTransaction deserializedTx = (NodeUpdateTransaction) Transaction.fromBytes(tx2Bytes);
assertThat(deserializedTx.getGossipCaCertificate()).isEqualTo(new byte[]{});
assertThat(deserializedTx.getGrpcCertificateHash()).isEqualTo(new byte[]{});
}

@Test
Expand Down

0 comments on commit 7ed4ad8

Please sign in to comment.