Search in sources :

Example 1 with SerializableDataOutputStream

use of com.swirlds.common.io.SerializableDataOutputStream in project hedera-services by hashgraph.

the class MerkleDiskFs method setHashFromContents.

private void setHashFromContents() {
    throwIfImmutable("Cannot change this file's content hash if it's immutable.");
    var baos = new ByteArrayOutputStream();
    try (SerializableDataOutputStream out = new SerializableDataOutputStream(baos)) {
        serializeFidInfo(out, fileHashes::get);
    } catch (IOException improbable) {
        throw new IllegalStateException(improbable);
    }
    try {
        baos.close();
        baos.flush();
    } catch (IOException improbable) {
        throw new IllegalStateException(improbable);
    }
    super.setHash(new Hash(noThrowSha384HashOf(baos.toByteArray())));
}
Also used : SerializableDataOutputStream(com.swirlds.common.io.SerializableDataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Hash(com.swirlds.common.crypto.Hash)

Example 2 with SerializableDataOutputStream

use of com.swirlds.common.io.SerializableDataOutputStream in project hedera-services by hashgraph.

the class TxnReceiptTest method serializeWorks.

@Test
void serializeWorks() throws IOException {
    // setup:
    SerializableDataOutputStream fout = mock(SerializableDataOutputStream.class);
    // and:
    InOrder inOrder = Mockito.inOrder(serdes, fout);
    subject = TxnReceipt.newBuilder().setStatus("SUCCESS").setExchangeRates(mockRates).setTopicSequenceNumber(-1).setRunningHashVersion(-1).setTopicSequenceNumber(0L).setNewTotalSupply(100L).setScheduledTxnId(TxnId.fromGrpc(scheduledTxnId)).setSerialNumbers(serialNumbers).build();
    // when:
    subject.serialize(fout);
    // then:
    inOrder.verify(fout).writeNormalisedString(subject.getStatus());
    inOrder.verify(fout).writeSerializable(mockRates, true);
    inOrder.verify(serdes, times(6)).writeNullableSerializable(null, fout);
    inOrder.verify(fout).writeBoolean(false);
    inOrder.verify(fout).writeLong(subject.getNewTotalSupply());
    inOrder.verify(serdes).writeNullableSerializable(subject.getScheduledTxnId(), fout);
    inOrder.verify(fout).writeLongArray(serialNumbers);
}
Also used : InOrder(org.mockito.InOrder) SerializableDataOutputStream(com.swirlds.common.io.SerializableDataOutputStream) Test(org.junit.jupiter.api.Test)

Example 3 with SerializableDataOutputStream

use of com.swirlds.common.io.SerializableDataOutputStream in project hedera-services by hashgraph.

the class FcAssessedCustomFeeTest method liveFireSerdeWorksForHbarFeeCurrentVersion.

@Test
void liveFireSerdeWorksForHbarFeeCurrentVersion() throws IOException, ConstructableRegistryException {
    // setup:
    final var account = new EntityId(1, 2, 3);
    final var amount = 345L;
    final var subject = new FcAssessedCustomFee(account, amount, effectivePayers);
    // and:
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(EntityId.class, EntityId::new));
    // and:
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final var dos = new SerializableDataOutputStream(baos);
    // given:
    subject.serialize(dos);
    dos.flush();
    // and:
    final var bytes = baos.toByteArray();
    final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    final var din = new SerializableDataInputStream(bais);
    // when:
    final var newSubject = new FcAssessedCustomFee();
    newSubject.deserialize(din, FcAssessedCustomFee.CURRENT_VERSION);
    // then:
    assertEquals(subject, newSubject);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SerializableDataOutputStream(com.swirlds.common.io.SerializableDataOutputStream) SerializableDataInputStream(com.swirlds.common.io.SerializableDataInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ClassConstructorPair(com.swirlds.common.constructable.ClassConstructorPair) Test(org.junit.jupiter.api.Test)

Example 4 with SerializableDataOutputStream

use of com.swirlds.common.io.SerializableDataOutputStream in project hedera-services by hashgraph.

the class MerkleTokenTest method liveFireSerdeWorks.

@Test
void liveFireSerdeWorks() throws IOException, ConstructableRegistryException {
    final var baos = new ByteArrayOutputStream();
    final var dos = new SerializableDataOutputStream(baos);
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(FcCustomFee.class, FcCustomFee::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(EntityId.class, EntityId::new));
    MerkleToken.serdes = new DomainSerdes();
    subject.serialize(dos);
    dos.flush();
    final var bytes = baos.toByteArray();
    final var bais = new ByteArrayInputStream(bytes);
    final var din = new SerializableDataInputStream(bais);
    final var newSubject = new MerkleToken();
    newSubject.deserialize(din, MerkleToken.CURRENT_VERSION);
    assertEquals(subject, newSubject);
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId) ByteArrayInputStream(java.io.ByteArrayInputStream) FcCustomFee(com.hedera.services.state.submerkle.FcCustomFee) SerializableDataOutputStream(com.swirlds.common.io.SerializableDataOutputStream) SerializableDataInputStream(com.swirlds.common.io.SerializableDataInputStream) DomainSerdes(com.hedera.services.state.serdes.DomainSerdes) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ClassConstructorPair(com.swirlds.common.constructable.ClassConstructorPair) Test(org.junit.jupiter.api.Test)

Example 5 with SerializableDataOutputStream

use of com.swirlds.common.io.SerializableDataOutputStream in project hedera-services by hashgraph.

the class FcAssessedCustomFeeTest method liveFireSerdeWorksForHtsFeeCurrentVersion.

@Test
void liveFireSerdeWorksForHtsFeeCurrentVersion() throws IOException, ConstructableRegistryException {
    // setup:
    final var account = new EntityId(1, 2, 3);
    final var token = new EntityId(2, 3, 4);
    final var amount = 345L;
    final var subject = new FcAssessedCustomFee(account, token, amount, effectivePayers);
    // and:
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(EntityId.class, EntityId::new));
    // and:
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final var dos = new SerializableDataOutputStream(baos);
    // given:
    subject.serialize(dos);
    dos.flush();
    // and:
    final var bytes = baos.toByteArray();
    final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    final var din = new SerializableDataInputStream(bais);
    // when:
    final var newSubject = new FcAssessedCustomFee();
    newSubject.deserialize(din, FcAssessedCustomFee.CURRENT_VERSION);
    // then:
    assertEquals(subject, newSubject);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SerializableDataOutputStream(com.swirlds.common.io.SerializableDataOutputStream) SerializableDataInputStream(com.swirlds.common.io.SerializableDataInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ClassConstructorPair(com.swirlds.common.constructable.ClassConstructorPair) Test(org.junit.jupiter.api.Test)

Aggregations

SerializableDataOutputStream (com.swirlds.common.io.SerializableDataOutputStream)18 Test (org.junit.jupiter.api.Test)16 SerializableDataInputStream (com.swirlds.common.io.SerializableDataInputStream)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 ByteArrayInputStream (java.io.ByteArrayInputStream)14 ClassConstructorPair (com.swirlds.common.constructable.ClassConstructorPair)9 DomainSerdes (com.hedera.services.state.serdes.DomainSerdes)2 EntityId (com.hedera.services.state.submerkle.EntityId)2 JKeySerializer (com.hedera.services.legacy.core.jproto.JKeySerializer)1 FilePart (com.hedera.services.state.merkle.internals.FilePart)1 FcCustomFee (com.hedera.services.state.submerkle.FcCustomFee)1 Hash (com.swirlds.common.crypto.Hash)1 FCQueue (com.swirlds.fcqueue.FCQueue)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 InOrder (org.mockito.InOrder)1