Search in sources :

Example 6 with SerializableDataInputStream

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

the class MerkleUniqueTokenTest method deserializeWorksPost0180.

@Test
void deserializeWorksPost0180() throws IOException {
    // setup:
    SerializableDataInputStream in = mock(SerializableDataInputStream.class);
    // and:
    final var packedTime = packedTime(timestamp.getSeconds(), timestamp.getNanos());
    given(in.readByteArray(anyInt())).willReturn(metadata);
    given(in.readLong()).willReturn(packedTime).willReturn(numbers);
    given(in.readInt()).willReturn(owner.identityCode());
    // and:
    var read = new MerkleUniqueToken();
    // when:
    read.deserialize(in, MerkleUniqueToken.RELEASE_0180_VERSION);
    // then:
    assertEquals(subject, read);
}
Also used : SerializableDataInputStream(com.swirlds.common.io.SerializableDataInputStream) Test(org.junit.jupiter.api.Test)

Example 7 with SerializableDataInputStream

use of com.swirlds.common.io.SerializableDataInputStream 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)

Example 8 with SerializableDataInputStream

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

the class FcCustomFeeTest method liveFireSerdesWorkForFixedWithNullDenom.

@Test
void liveFireSerdesWorkForFixedWithNullDenom() throws IOException {
    final var fixedSubject = FcCustomFee.fixedFee(fixedUnitsToCollect, null, 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 9 with SerializableDataInputStream

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

the class HFileMetaSerdeTest method undoStaticMocking.

private void undoStaticMocking() {
    HFileMetaSerde.serdes = new DomainSerdes();
    HFileMetaSerde.setSerInFactory(SerializableDataInputStream::new);
    HFileMetaSerde.setSerOutFactory(SerializableDataOutputStream::new);
    HFileMetaSerde.setStreamContentDiscovery(JKeySerializer::byteStream);
}
Also used : SerializableDataInputStream(com.swirlds.common.io.SerializableDataInputStream) SerializableDataOutputStream(com.swirlds.common.io.SerializableDataOutputStream) DomainSerdes(com.hedera.services.state.serdes.DomainSerdes) JKeySerializer(com.hedera.services.legacy.core.jproto.JKeySerializer)

Example 10 with SerializableDataInputStream

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

the class FcAssessedCustomFeeTest method liveFireSerdeWorksForHbarFee0170Version.

@Test
void liveFireSerdeWorksForHbarFee0170Version() throws IOException, ConstructableRegistryException {
    // setup:
    final var account = new EntityId(1, 2, 3);
    final var amount = 345L;
    final var subject = new FcAssessedCustomFee(account, amount, FcAssessedCustomFee.UNKNOWN_EFFECTIVE_PAYER_ACCOUNT_NUMS);
    // 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.RELEASE_0170_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

SerializableDataInputStream (com.swirlds.common.io.SerializableDataInputStream)21 Test (org.junit.jupiter.api.Test)20 SerializableDataOutputStream (com.swirlds.common.io.SerializableDataOutputStream)15 ByteArrayInputStream (java.io.ByteArrayInputStream)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)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 EntityNumPair (com.hedera.services.utils.EntityNumPair)1 FCQueue (com.swirlds.fcqueue.FCQueue)1