use of com.swirlds.common.constructable.ClassConstructorPair in project hedera-services by hashgraph.
the class FcAssessedCustomFeeTest method liveFireSerdeWorksForHbarFee0170Version.
@Test
void liveFireSerdeWorksForHbarFee0170Version() throws IOException, ConstructableRegistryException {
// setup:
final var account = new EntityId(1, 2, 3);
final var amount = 345L;
final var subject = new FcAssessedCustomFee(account, amount, FcAssessedCustomFee.UNKNOWN_EFFECTIVE_PAYER_ACCOUNT_NUMS);
// 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.RELEASE_0170_VERSION);
// then:
assertEquals(subject, newSubject);
}
use of com.swirlds.common.constructable.ClassConstructorPair in project hedera-services by hashgraph.
the class FcAssessedCustomFeeTest method liveFireSerdeWorksForHtsFee0170Version.
@Test
void liveFireSerdeWorksForHtsFee0170Version() 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, FcAssessedCustomFee.UNKNOWN_EFFECTIVE_PAYER_ACCOUNT_NUMS);
// 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.RELEASE_0170_VERSION);
// then:
assertEquals(subject, newSubject);
}
use of com.swirlds.common.constructable.ClassConstructorPair 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.constructable.ClassConstructorPair in project hedera-services by hashgraph.
the class BackingAccountsTest method twoPutsChangesG4M.
@Test
void twoPutsChangesG4M() throws ConstructableRegistryException {
// setup:
ConstructableRegistry.registerConstructable(new ClassConstructorPair(KeyedMerkleLong.class, KeyedMerkleLong::new));
final var oneGrandKey = new FcLong(1000L);
final var twoGrandKey = new FcLong(2000L);
final var evilKey = new FcLong(666L);
final var nonEvilKey = new FcLong(667L);
/* Case 1: g4m a leaf; then put ONE new leaf; then change the mutable leaf and re-get to verify new value */
final MerkleMap<FcLong, KeyedMerkleLong<FcLong>> firstMm = new MerkleMap<>();
final var oneGrandEntry = new KeyedMerkleLong<>(oneGrandKey, 1000L);
firstMm.put(oneGrandKey, oneGrandEntry);
final var mutableOne = firstMm.getForModify(oneGrandKey);
/* Putting just one new leaf */
final var evilEntry = new KeyedMerkleLong<>(evilKey, 666L);
firstMm.put(evilKey, evilEntry);
/* Then the mutable value is retained */
assertSame(mutableOne, firstMm.get(oneGrandKey));
/* Case 2: g4m a leaf; then put TWO new leaves; then change the mutable leaf and re-get to verify new value */
final var secondFcm = new MerkleMap<FcLong, KeyedMerkleLong<FcLong>>();
final var twoGrandEntry = new KeyedMerkleLong<>(twoGrandKey, 2000L);
final var evilEntry2 = new KeyedMerkleLong<>(evilKey, 666L);
final var nonEvilEntry2 = new KeyedMerkleLong<>(nonEvilKey, 667L);
secondFcm.put(twoGrandKey, twoGrandEntry);
final var mutableTwo = secondFcm.getForModify(twoGrandEntry.getKey());
/* Putting two new leaves now */
secondFcm.put(evilEntry2.getKey(), evilEntry2);
secondFcm.put(nonEvilEntry2.getKey(), nonEvilEntry2);
/* And now changing the once-mutable value throws MutabilityException */
assertThrows(MutabilityException.class, mutableTwo::increment);
}
use of com.swirlds.common.constructable.ClassConstructorPair in project hedera-services by hashgraph.
the class BackingAccountsTest method auxiliarySetIsRebuiltFromScratch.
@Test
void auxiliarySetIsRebuiltFromScratch() throws ConstructableRegistryException {
ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleAccount.class, MerkleAccount::new));
final var idSet = subject.getExistingAccounts();
subject.rebuildFromSources();
assertTrue(idSet.contains(aKey.toGrpcAccountId()));
assertTrue(idSet.contains(bKey.toGrpcAccountId()));
delegate.remove(aKey);
subject.rebuildFromSources();
assertFalse(idSet.contains(aKey.toGrpcAccountId()));
assertTrue(idSet.contains(bKey.toGrpcAccountId()));
}
Aggregations