Search in sources :

Example 6 with ClassConstructorPair

use of com.swirlds.common.constructable.ClassConstructorPair in project hedera-services by hashgraph.

the class ExpirableTxnRecordSerdeTest method registerRecordConstructables.

public static void registerRecordConstructables() throws ConstructableRegistryException {
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(TxnId.class, TxnId::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(EntityId.class, EntityId::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(FcTokenAllowance.class, FcTokenAllowance::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(FcTokenAllowanceId.class, FcTokenAllowanceId::new));
}
Also used : ClassConstructorPair(com.swirlds.common.constructable.ClassConstructorPair)

Example 7 with ClassConstructorPair

use of com.swirlds.common.constructable.ClassConstructorPair 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 8 with ClassConstructorPair

use of com.swirlds.common.constructable.ClassConstructorPair 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 9 with ClassConstructorPair

use of com.swirlds.common.constructable.ClassConstructorPair 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);
}
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 10 with ClassConstructorPair

use of com.swirlds.common.constructable.ClassConstructorPair in project hedera-services by hashgraph.

the class DomainSerdesTest method setupAll.

@BeforeAll
public static void setupAll() throws ConstructableRegistryException {
    /* Per Cody, this will be unnecessary at some point. */
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(ExpirableTxnRecord.class, ExpirableTxnRecord::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(EntityId.class, EntityId::new));
}
Also used : ExpirableTxnRecord(com.hedera.services.state.submerkle.ExpirableTxnRecord) EntityId(com.hedera.services.state.submerkle.EntityId) ClassConstructorPair(com.swirlds.common.constructable.ClassConstructorPair) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

ClassConstructorPair (com.swirlds.common.constructable.ClassConstructorPair)19 Test (org.junit.jupiter.api.Test)13 SerializableDataInputStream (com.swirlds.common.io.SerializableDataInputStream)9 SerializableDataOutputStream (com.swirlds.common.io.SerializableDataOutputStream)9 ByteArrayInputStream (java.io.ByteArrayInputStream)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 EntityId (com.hedera.services.state.submerkle.EntityId)5 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)4 ExpirableTxnRecord (com.hedera.services.state.submerkle.ExpirableTxnRecord)3 MerkleLong (com.swirlds.common.merkle.utility.MerkleLong)3 FCQueue (com.swirlds.fcqueue.FCQueue)3 TxnReceipt (com.hedera.services.legacy.core.jproto.TxnReceipt)2 MerkleAccountState (com.hedera.services.state.merkle.MerkleAccountState)2 MerkleEntityId (com.hedera.services.state.merkle.MerkleEntityId)2 CurrencyAdjustments (com.hedera.services.state.submerkle.CurrencyAdjustments)2 EvmFnResult (com.hedera.services.state.submerkle.EvmFnResult)2 TxnId (com.hedera.services.state.submerkle.TxnId)2 MerkleMap (com.swirlds.merkle.map.MerkleMap)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 ServicesState (com.hedera.services.ServicesState)1