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