Search in sources :

Example 11 with EntityId

use of com.hedera.services.state.submerkle.EntityId in project hedera-services by hashgraph.

the class ExpiryManagerTest method expiresSchedulesAsExpected.

@Test
void expiresSchedulesAsExpected() {
    subject = new ExpiryManager(mockScheduleStore, nums, sigImpactHistorian, mockTxnHistories, () -> mockAccounts, () -> mockSchedules);
    // given:
    subject.trackExpirationEvent(Pair.of(aKey.longValue(), entityId -> mockScheduleStore.expire(entityId)), firstThen);
    subject.trackExpirationEvent(Pair.of(bKey.longValue(), entityId -> mockScheduleStore.expire(entityId)), secondThen);
    subject.purge(now);
    // then:
    verify(mockScheduleStore).expire(new EntityId(0, 0, aKey.longValue()));
    verify(sigImpactHistorian).markEntityChanged(aKey.longValue());
    assertEquals(1, subject.getShortLivedEntityExpiries().getAllExpiries().size());
}
Also used : TxnIdRecentHistory(com.hedera.services.records.TxnIdRecentHistory) OK(com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK) Mock(org.mockito.Mock) EntityId(com.hedera.services.state.submerkle.EntityId) HashMap(java.util.HashMap) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) MerkleMap(com.swirlds.merkle.map.MerkleMap) HederaNumbers(com.hedera.services.config.HederaNumbers) EntityNum(com.hedera.services.utils.EntityNum) Pair(org.apache.commons.lang3.tuple.Pair) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) MockHederaNumbers(com.hedera.services.config.MockHederaNumbers) ExpirableTxnRecord(com.hedera.services.state.submerkle.ExpirableTxnRecord) ScheduleStore(com.hedera.services.store.schedule.ScheduleStore) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AccountID(com.hederahashgraph.api.proto.java.AccountID) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) SigImpactHistorian(com.hedera.services.ledger.SigImpactHistorian) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) RichInstant(com.hedera.services.state.submerkle.RichInstant) Instant(java.time.Instant) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) IdUtils(com.hedera.test.utils.IdUtils) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) TxnReceipt(com.hedera.services.legacy.core.jproto.TxnReceipt) MerkleSchedule(com.hedera.services.state.merkle.MerkleSchedule) TxnId(com.hedera.services.state.submerkle.TxnId) EntityId(com.hedera.services.state.submerkle.EntityId) Test(org.junit.jupiter.api.Test)

Example 12 with EntityId

use of com.hedera.services.state.submerkle.EntityId 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 13 with EntityId

use of com.hedera.services.state.submerkle.EntityId in project hedera-services by hashgraph.

the class MerkleTopicTest method topicFrom.

private MerkleTopic topicFrom(int s) throws IOException {
    long v = 1_234_567L + s * 1_000_000L;
    long t = s + 1;
    AccountID payer = AccountID.newBuilder().setAccountNum(123).build();
    TopicID id = TopicID.newBuilder().setTopicNum(s).build();
    var topic = new MerkleTopic(memos[s], adminKeys[s], submitKeys[s], v, new EntityId(t, t * 2, t * 3), new RichInstant(v, s));
    for (int i = 0; i < s; i++) {
        topic.updateRunningHashAndSequenceNumber(payer, "Hello world!".getBytes(), id, Instant.ofEpochSecond(v, i));
    }
    topic.setKey(EntityNum.fromInt(s));
    return topic;
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId) AccountID(com.hederahashgraph.api.proto.java.AccountID) TopicID(com.hederahashgraph.api.proto.java.TopicID) RichInstant(com.hedera.services.state.submerkle.RichInstant)

Example 14 with EntityId

use of com.hedera.services.state.submerkle.EntityId in project hedera-services by hashgraph.

the class MerkleUniqueTokenTest method setup.

@BeforeEach
void setup() {
    owner = new EntityId(0, 0, 3);
    otherOwner = new EntityId(0, 0, 4);
    metadata = "Test NFT".getBytes();
    otherMetadata = "Test NFT2".getBytes();
    timestamp = RichInstant.fromJava(Instant.ofEpochSecond(timestampL));
    otherTimestamp = RichInstant.fromJava(Instant.ofEpochSecond(1_234_568L));
    subject = new MerkleUniqueToken(owner, metadata, timestamp);
    subject.setKey(new EntityNumPair(numbers));
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId) EntityNumPair(com.hedera.services.utils.EntityNumPair) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 15 with EntityId

use of com.hedera.services.state.submerkle.EntityId in project hedera-services by hashgraph.

the class DomainSerdesTest method readsNullForNullableSerializable.

@Test
void readsNullForNullableSerializable() throws IOException {
    // setup:
    var in = mock(SerializableDataInputStream.class);
    // and:
    EntityId data;
    given(in.readBoolean()).willReturn(false);
    // when:
    data = subject.readNullableSerializable(in);
    // then:
    verify(in).readBoolean();
    verifyNoMoreInteractions(in);
    // and:
    assertNull(data);
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId) Test(org.junit.jupiter.api.Test)

Aggregations

EntityId (com.hedera.services.state.submerkle.EntityId)35 Test (org.junit.jupiter.api.Test)18 MerkleToken (com.hedera.services.state.merkle.MerkleToken)9 RichInstant (com.hedera.services.state.submerkle.RichInstant)6 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)5 ExpirableTxnRecord (com.hedera.services.state.submerkle.ExpirableTxnRecord)5 TxnId (com.hedera.services.state.submerkle.TxnId)4 EntityNum (com.hedera.services.utils.EntityNum)4 ClassConstructorPair (com.swirlds.common.constructable.ClassConstructorPair)4 TxnReceipt (com.hedera.services.legacy.core.jproto.TxnReceipt)3 MerkleAccountState (com.hedera.services.state.merkle.MerkleAccountState)3 MerkleTopic (com.hedera.services.state.merkle.MerkleTopic)3 CurrencyAdjustments (com.hedera.services.state.submerkle.CurrencyAdjustments)3 ScheduleStore (com.hedera.services.store.schedule.ScheduleStore)3 AccountID (com.hederahashgraph.api.proto.java.AccountID)3 ByteString (com.google.protobuf.ByteString)2 JKeyList (com.hedera.services.legacy.core.jproto.JKeyList)2 MerkleEntityId (com.hedera.services.state.merkle.MerkleEntityId)2 MerkleUniqueToken (com.hedera.services.state.merkle.MerkleUniqueToken)2 DomainSerdes (com.hedera.services.state.serdes.DomainSerdes)2