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());
}
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());
}
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);
}
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);
}
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);
}
Aggregations