use of com.swirlds.common.io.SerializableDataOutputStream in project hedera-services by hashgraph.
the class MerkleDiskFs method setHashFromContents.
private void setHashFromContents() {
throwIfImmutable("Cannot change this file's content hash if it's immutable.");
var baos = new ByteArrayOutputStream();
try (SerializableDataOutputStream out = new SerializableDataOutputStream(baos)) {
serializeFidInfo(out, fileHashes::get);
} catch (IOException improbable) {
throw new IllegalStateException(improbable);
}
try {
baos.close();
baos.flush();
} catch (IOException improbable) {
throw new IllegalStateException(improbable);
}
super.setHash(new Hash(noThrowSha384HashOf(baos.toByteArray())));
}
use of com.swirlds.common.io.SerializableDataOutputStream in project hedera-services by hashgraph.
the class TxnReceiptTest method serializeWorks.
@Test
void serializeWorks() throws IOException {
// setup:
SerializableDataOutputStream fout = mock(SerializableDataOutputStream.class);
// and:
InOrder inOrder = Mockito.inOrder(serdes, fout);
subject = TxnReceipt.newBuilder().setStatus("SUCCESS").setExchangeRates(mockRates).setTopicSequenceNumber(-1).setRunningHashVersion(-1).setTopicSequenceNumber(0L).setNewTotalSupply(100L).setScheduledTxnId(TxnId.fromGrpc(scheduledTxnId)).setSerialNumbers(serialNumbers).build();
// when:
subject.serialize(fout);
// then:
inOrder.verify(fout).writeNormalisedString(subject.getStatus());
inOrder.verify(fout).writeSerializable(mockRates, true);
inOrder.verify(serdes, times(6)).writeNullableSerializable(null, fout);
inOrder.verify(fout).writeBoolean(false);
inOrder.verify(fout).writeLong(subject.getNewTotalSupply());
inOrder.verify(serdes).writeNullableSerializable(subject.getScheduledTxnId(), fout);
inOrder.verify(fout).writeLongArray(serialNumbers);
}
use of com.swirlds.common.io.SerializableDataOutputStream 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);
}
use of com.swirlds.common.io.SerializableDataOutputStream 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);
}
use of com.swirlds.common.io.SerializableDataOutputStream 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);
}
Aggregations