Search in sources :

Example 1 with SerializableDataInputStream

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

the class TxnReceiptTest method v0120DeserializeWorks.

@Test
void v0120DeserializeWorks() throws IOException {
    final var scheduleId = EntityId.fromGrpcScheduleId(IdUtils.asSchedule("0.0.312"));
    SerializableDataInputStream fin = mock(SerializableDataInputStream.class);
    subject = TxnReceipt.newBuilder().setStatus("SUCCESS").setScheduleId(scheduleId).setExchangeRates(mockRates).setTopicSequenceNumber(-1).setRunningHashVersion(-1).setTopicSequenceNumber(0L).setNewTotalSupply(0L).setScheduledTxnId(TxnId.fromGrpc(scheduledTxnId)).build();
    given(fin.readByteArray(MAX_STATUS_BYTES)).willReturn(subject.getStatus().getBytes());
    given(fin.readSerializable(anyBoolean(), any())).willReturn(mockRates);
    given(serdes.readNullableSerializable(fin)).willReturn(subject.getAccountId()).willReturn(subject.getFileId()).willReturn(subject.getContractId()).willReturn(subject.getTopicId()).willReturn(subject.getTokenId()).willReturn(subject.getScheduleId()).willReturn(subject.getScheduledTxnId());
    given(fin.readBoolean()).willReturn(true);
    given(fin.readLong()).willReturn(subject.getTopicSequenceNumber());
    given(fin.readLong()).willReturn(subject.getRunningHashVersion());
    given(fin.readAllBytes()).willReturn(subject.getTopicRunningHash());
    given(fin.readLong()).willReturn(subject.getNewTotalSupply());
    // and:
    TxnReceipt txnReceipt = new TxnReceipt();
    // when:
    txnReceipt.deserialize(fin, TxnReceipt.RELEASE_0120_VERSION);
    // then:
    assertEquals(subject.getNewTotalSupply(), txnReceipt.getNewTotalSupply());
    assertEquals(subject.getStatus(), txnReceipt.getStatus());
    assertEquals(subject.getExchangeRates(), txnReceipt.getExchangeRates());
    assertEquals(subject.getTokenId(), txnReceipt.getTokenId());
    assertEquals(subject.getScheduledTxnId(), txnReceipt.getScheduledTxnId());
}
Also used : SerializableDataInputStream(com.swirlds.common.io.SerializableDataInputStream) Test(org.junit.jupiter.api.Test)

Example 2 with SerializableDataInputStream

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

the class TxnReceiptTest method v0100DeserializeWorks.

@Test
void v0100DeserializeWorks() throws IOException {
    final var tokenId = EntityId.fromGrpcTokenId(TokenID.newBuilder().setTokenNum(1001L).setRealmNum(0).setShardNum(0).build());
    SerializableDataInputStream fin = mock(SerializableDataInputStream.class);
    subject = TxnReceipt.newBuilder().setStatus("SUCCESS").setScheduleId(tokenId).setExchangeRates(mockRates).setTopicSequenceNumber(-1).setRunningHashVersion(-1).setTopicSequenceNumber(0L).setNewTotalSupply(100L).setScheduledTxnId(MISSING_SCHEDULED_TXN_ID).build();
    given(fin.readByteArray(MAX_STATUS_BYTES)).willReturn(subject.getStatus().getBytes());
    given(fin.readSerializable(anyBoolean(), any())).willReturn(mockRates);
    given(serdes.readNullableSerializable(fin)).willReturn(subject.getAccountId()).willReturn(subject.getFileId()).willReturn(subject.getContractId()).willReturn(subject.getTopicId()).willReturn(subject.getTokenId());
    given(fin.readBoolean()).willReturn(true);
    given(fin.readLong()).willReturn(subject.getTopicSequenceNumber());
    given(fin.readLong()).willReturn(subject.getRunningHashVersion());
    given(fin.readAllBytes()).willReturn(subject.getTopicRunningHash());
    given(fin.readLong()).willReturn(subject.getNewTotalSupply());
    // and:
    TxnReceipt txnReceipt = new TxnReceipt();
    // when:
    txnReceipt.deserialize(fin, TxnReceipt.RELEASE_0100_VERSION);
    // then:
    assertEquals(subject.getNewTotalSupply(), txnReceipt.getNewTotalSupply());
    assertEquals(subject.getStatus(), txnReceipt.getStatus());
    assertEquals(subject.getExchangeRates(), txnReceipt.getExchangeRates());
    assertEquals(subject.getTokenId(), txnReceipt.getTokenId());
}
Also used : SerializableDataInputStream(com.swirlds.common.io.SerializableDataInputStream) Test(org.junit.jupiter.api.Test)

Example 3 with SerializableDataInputStream

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

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

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

the class MerkleUniqueTokenTest method deserializeWorksPre0180.

@Test
void deserializeWorksPre0180() 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);
    given(in.readInt()).willReturn(owner.identityCode());
    // and:
    var read = new MerkleUniqueToken();
    // when:
    read.deserialize(in, MerkleUniqueToken.PRE_RELEASE_0180_VERSION);
    // then:
    assertNotEquals(subject, read);
    // and when:
    read.setKey(new EntityNumPair(numbers));
    // then:
    assertEquals(subject, read);
}
Also used : EntityNumPair(com.hedera.services.utils.EntityNumPair) SerializableDataInputStream(com.swirlds.common.io.SerializableDataInputStream) 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