use of com.swirlds.common.io.SerializableDataInputStream 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);
}
use of com.swirlds.common.io.SerializableDataInputStream in project hedera-services by hashgraph.
the class NftAdjustmentsTest method deserialize.
@Test
void deserialize() throws IOException {
SerializableDataInputStream stream = mock(SerializableDataInputStream.class);
given(stream.readSerializableList(eq(NftAdjustments.MAX_NUM_ADJUSTMENTS), anyBoolean(), any())).willReturn(Collections.emptyList());
given(stream.readLongArray(NftAdjustments.MAX_NUM_ADJUSTMENTS)).willReturn(new long[] { 1, 2, 3 });
subject.deserialize(stream, 1);
verify(stream).readLongArray(NftAdjustments.MAX_NUM_ADJUSTMENTS);
verify(stream, times(2)).readSerializableList(eq(1024), eq(true), any());
}
use of com.swirlds.common.io.SerializableDataInputStream in project hedera-services by hashgraph.
the class TxnReceiptTest method v0160DeserializeWorks.
@Test
void v0160DeserializeWorks() 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)).setSerialNumbers(new long[] { 1, 2, 3, 4, 5 }).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());
given(fin.readLongArray(anyInt())).willReturn(subject.getSerialNumbers());
// and:
TxnReceipt txnReceipt = new TxnReceipt();
// when:
txnReceipt.deserialize(fin, TxnReceipt.RELEASE_0160_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());
assertArrayEquals(subject.getSerialNumbers(), txnReceipt.getSerialNumbers());
}
use of com.swirlds.common.io.SerializableDataInputStream in project hedera-services by hashgraph.
the class MerkleSpecialFilesTest method liveFireSerdeWorksWithEmpty.
@Test
void liveFireSerdeWorksWithEmpty() throws IOException, ConstructableRegistryException {
final var baos = new ByteArrayOutputStream();
final var dos = new SerializableDataOutputStream(baos);
ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleSpecialFiles.class, MerkleSpecialFiles::new));
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 MerkleSpecialFiles();
newSubject.deserialize(din, MerkleSpecialFiles.CURRENT_VERSION);
assertTrue(newSubject.getFileContents().isEmpty(), "Deserialized instance should be empty");
}
use of com.swirlds.common.io.SerializableDataInputStream in project hedera-services by hashgraph.
the class MerkleSpecialFilesTest method liveFireSerdeWorksWithNonEmpty.
@Test
void liveFireSerdeWorksWithNonEmpty() throws IOException, ConstructableRegistryException {
final var baos = new ByteArrayOutputStream();
final var dos = new SerializableDataOutputStream(baos);
ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleSpecialFiles.class, MerkleSpecialFiles::new));
ConstructableRegistry.registerConstructable(new ClassConstructorPair(FCQueue.class, FCQueue::new));
ConstructableRegistry.registerConstructable(new ClassConstructorPair(FilePart.class, FilePart::new));
subject.update(fid, Arrays.copyOfRange(stuff, 0, stuff.length / 2));
subject.update(secondFid, Arrays.copyOfRange(stuff, stuff.length / 2, stuff.length));
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 MerkleSpecialFiles();
newSubject.deserialize(din, MerkleSpecialFiles.CURRENT_VERSION);
assertArrayEquals(subject.get(fid), newSubject.get(fid), "Deserialized contents should match for first file");
assertArrayEquals(subject.get(secondFid), newSubject.get(secondFid), "Deserialized contents should match for second file");
}
Aggregations