Search in sources :

Example 1 with DomainSerdes

use of com.hedera.services.state.serdes.DomainSerdes in project hedera-services by hashgraph.

the class TxnIdTest method v0130DeserializeWorks.

@Test
void v0130DeserializeWorks() throws IOException {
    // setup:
    subject = scheduledSubjectUserNonce();
    // and:
    din = mock(SerializableDataInputStream.class);
    serdes = mock(DomainSerdes.class);
    TxnId.serdes = serdes;
    given(din.readSerializable(booleanThat(Boolean.TRUE::equals), any(Supplier.class))).willReturn(fcPayer);
    given(serdes.deserializeTimestamp(din)).willReturn(fcValidStart);
    given(din.readBoolean()).willReturn(true);
    // and:
    var deserializedId = new TxnId();
    // when:
    deserializedId.deserialize(din, TxnId.RELEASE_0130_VERSION);
    // then:
    assertEquals(subject, deserializedId);
    // and:
    verify(din, times(1)).readBoolean();
    // cleanup:
    TxnId.serdes = new DomainSerdes();
}
Also used : SerializableDataInputStream(com.swirlds.common.io.SerializableDataInputStream) DomainSerdes(com.hedera.services.state.serdes.DomainSerdes) Supplier(java.util.function.Supplier) Test(org.junit.jupiter.api.Test)

Example 2 with DomainSerdes

use of com.hedera.services.state.serdes.DomainSerdes in project hedera-services by hashgraph.

the class TxnIdTest method v0210DeserializeWorksWithUserNonce.

@Test
void v0210DeserializeWorksWithUserNonce() throws IOException {
    // setup:
    subject = scheduledSubjectUserNonce();
    // and:
    din = mock(SerializableDataInputStream.class);
    serdes = mock(DomainSerdes.class);
    TxnId.serdes = serdes;
    given(din.readSerializable(booleanThat(Boolean.TRUE::equals), any(Supplier.class))).willReturn(fcPayer);
    given(serdes.deserializeTimestamp(din)).willReturn(fcValidStart);
    given(din.readBoolean()).willReturn(true).willReturn(false);
    // and:
    var deserializedId = new TxnId();
    // when:
    deserializedId.deserialize(din, TxnId.RELEASE_0210_VERSION);
    // then:
    assertEquals(subject, deserializedId);
    // and:
    verify(din, times(2)).readBoolean();
    verify(din, never()).readInt();
    // cleanup:
    TxnId.serdes = new DomainSerdes();
}
Also used : SerializableDataInputStream(com.swirlds.common.io.SerializableDataInputStream) DomainSerdes(com.hedera.services.state.serdes.DomainSerdes) Supplier(java.util.function.Supplier) Test(org.junit.jupiter.api.Test)

Example 3 with DomainSerdes

use of com.hedera.services.state.serdes.DomainSerdes in project hedera-services by hashgraph.

the class TxnIdTest method serializeWorksForScheduled.

@Test
void serializeWorksForScheduled() throws IOException {
    // setup:
    subject = scheduledSubject();
    // and:
    dout = mock(SerializableDataOutputStream.class);
    serdes = mock(DomainSerdes.class);
    TxnId.serdes = serdes;
    // given:
    InOrder inOrder = Mockito.inOrder(serdes, dout);
    // when:
    subject.serialize(dout);
    // then:
    inOrder.verify(dout).writeSerializable(fcPayer, Boolean.TRUE);
    inOrder.verify(serdes).serializeTimestamp(fcValidStart, dout);
    inOrder.verify(dout, times(2)).writeBoolean(true);
    inOrder.verify(dout).writeInt(nonce);
    // cleanup:
    TxnId.serdes = new DomainSerdes();
}
Also used : InOrder(org.mockito.InOrder) SerializableDataOutputStream(com.swirlds.common.io.SerializableDataOutputStream) DomainSerdes(com.hedera.services.state.serdes.DomainSerdes) Test(org.junit.jupiter.api.Test)

Example 4 with DomainSerdes

use of com.hedera.services.state.serdes.DomainSerdes in project hedera-services by hashgraph.

the class TxnIdTest method v0210DeserializeWorksWithNonUserNonce.

@Test
void v0210DeserializeWorksWithNonUserNonce() throws IOException {
    // setup:
    subject = scheduledSubject();
    // and:
    din = mock(SerializableDataInputStream.class);
    serdes = mock(DomainSerdes.class);
    TxnId.serdes = serdes;
    given(din.readSerializable(booleanThat(Boolean.TRUE::equals), any(Supplier.class))).willReturn(fcPayer);
    given(serdes.deserializeTimestamp(din)).willReturn(fcValidStart);
    given(din.readBoolean()).willReturn(true);
    given(din.readInt()).willReturn(nonce);
    // and:
    var deserializedId = new TxnId();
    // when:
    deserializedId.deserialize(din, TxnId.RELEASE_0210_VERSION);
    // then:
    assertEquals(subject, deserializedId);
    // and:
    verify(din, times(2)).readBoolean();
    verify(din).readInt();
    // cleanup:
    TxnId.serdes = new DomainSerdes();
}
Also used : SerializableDataInputStream(com.swirlds.common.io.SerializableDataInputStream) DomainSerdes(com.hedera.services.state.serdes.DomainSerdes) Supplier(java.util.function.Supplier) Test(org.junit.jupiter.api.Test)

Example 5 with DomainSerdes

use of com.hedera.services.state.serdes.DomainSerdes 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)

Aggregations

DomainSerdes (com.hedera.services.state.serdes.DomainSerdes)7 Test (org.junit.jupiter.api.Test)6 SerializableDataInputStream (com.swirlds.common.io.SerializableDataInputStream)5 SerializableDataOutputStream (com.swirlds.common.io.SerializableDataOutputStream)4 Supplier (java.util.function.Supplier)3 InOrder (org.mockito.InOrder)2 JKeySerializer (com.hedera.services.legacy.core.jproto.JKeySerializer)1 EntityId (com.hedera.services.state.submerkle.EntityId)1 FcCustomFee (com.hedera.services.state.submerkle.FcCustomFee)1 ClassConstructorPair (com.swirlds.common.constructable.ClassConstructorPair)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1