Search in sources :

Example 11 with SerializableDataOutputStream

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

the class FcCustomFeeTest method liveFireSerdesWorkForFixed.

@Test
void liveFireSerdesWorkForFixed() throws IOException {
    final var fixedSubject = FcCustomFee.fixedFee(fixedUnitsToCollect, denom, feeCollector);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final var dos = new SerializableDataOutputStream(baos);
    fixedSubject.serialize(dos);
    dos.flush();
    final var bytes = baos.toByteArray();
    final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    final var din = new SerializableDataInputStream(bais);
    final var newSubject = new FcCustomFee();
    newSubject.deserialize(din, FcCustomFee.CURRENT_VERSION);
    assertEquals(fixedSubject.getFixedFeeSpec(), newSubject.getFixedFeeSpec());
    assertEquals(fixedSubject.getFeeCollector(), newSubject.getFeeCollector());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SerializableDataOutputStream(com.swirlds.common.io.SerializableDataOutputStream) SerializableDataInputStream(com.swirlds.common.io.SerializableDataInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 12 with SerializableDataOutputStream

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

the class FcCustomFeeTest method liveFireSerdesWorkForFractional.

@Test
void liveFireSerdesWorkForFractional() throws IOException {
    final var subject = FcCustomFee.fractionalFee(validNumerator, validDenominator, minimumUnitsToCollect, maximumUnitsToCollect, netOfTransfers, feeCollector);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final var dos = new SerializableDataOutputStream(baos);
    subject.serialize(dos);
    dos.flush();
    final var bytes = baos.toByteArray();
    final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    final var din = new SerializableDataInputStream(bais);
    final var newSubject = new FcCustomFee();
    newSubject.deserialize(din, FcCustomFee.CURRENT_VERSION);
    assertEquals(subject.getFractionalFeeSpec(), newSubject.getFractionalFeeSpec());
    assertEquals(subject.getFeeCollector(), newSubject.getFeeCollector());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SerializableDataOutputStream(com.swirlds.common.io.SerializableDataOutputStream) SerializableDataInputStream(com.swirlds.common.io.SerializableDataInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 13 with SerializableDataOutputStream

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

the class FcCustomFeeTest method liveFireSerdesWorkForRoyaltyNoFallback.

@Test
void liveFireSerdesWorkForRoyaltyNoFallback() throws IOException {
    final var subject = FcCustomFee.royaltyFee(validNumerator, validDenominator, null, feeCollector);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final var dos = new SerializableDataOutputStream(baos);
    subject.serialize(dos);
    dos.flush();
    final var bytes = baos.toByteArray();
    final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    final var din = new SerializableDataInputStream(bais);
    final var newSubject = new FcCustomFee();
    newSubject.deserialize(din, FcCustomFee.CURRENT_VERSION);
    assertEquals(subject.getRoyaltyFeeSpec(), newSubject.getRoyaltyFeeSpec());
    assertEquals(subject.getFeeCollector(), newSubject.getFeeCollector());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SerializableDataOutputStream(com.swirlds.common.io.SerializableDataOutputStream) SerializableDataInputStream(com.swirlds.common.io.SerializableDataInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 14 with SerializableDataOutputStream

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

the class FcTokenAssociationTest method serializationWorks.

@Test
void serializationWorks() throws IOException, ConstructableRegistryException {
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(EntityId.class, EntityId::new));
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final var dos = new SerializableDataOutputStream(baos);
    subject.serialize(dos);
    dos.flush();
    final var bytes = baos.toByteArray();
    final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    final var din = new SerializableDataInputStream(bais);
    final var newSubject = new FcTokenAssociation();
    newSubject.deserialize(din, FcTokenAssociation.RELEASE_0180_VERSION);
    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 15 with SerializableDataOutputStream

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

the class NftAdjustmentsTest method serialize.

@Test
void serialize() throws IOException {
    givenCanonicalSubject();
    SerializableDataOutputStream stream = mock(SerializableDataOutputStream.class);
    subject.serialize(stream);
    verify(stream).writeLongArray(new long[] { 1 });
    verify(stream, times(1)).writeSerializableList(List.of(EntityId.fromGrpcAccountId(sender)), true, true);
    verify(stream, times(1)).writeSerializableList(List.of(EntityId.fromGrpcAccountId(recipient)), true, true);
}
Also used : SerializableDataOutputStream(com.swirlds.common.io.SerializableDataOutputStream) 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