Search in sources :

Example 76 with Entity

use of com.hedera.mirror.common.domain.entity.Entity in project hedera-mirror-node by hashgraph.

the class AbstractEntityRecordItemListenerTest method createEntity.

protected Entity createEntity(EntityId entityId, Key adminKey, Long autoRenewAccountId, Long autoRenewPeriod, Boolean deleted, Long expiryTimeNs, String memo, Key submitKey, Long createdTimestamp, Long modifiedTimestamp) {
    byte[] adminKeyBytes = rawBytesFromKey(adminKey);
    byte[] submitKeyBytes = rawBytesFromKey(submitKey);
    Entity entity = entityId.toEntity();
    entity.setAutoRenewAccountId(autoRenewAccountId);
    entity.setAutoRenewPeriod(autoRenewPeriod);
    entity.setCreatedTimestamp(createdTimestamp);
    entity.setDeleted(deleted);
    entity.setEthereumNonce(0L);
    entity.setExpirationTimestamp(expiryTimeNs);
    entity.setMemo(memo);
    entity.setTimestampLower(modifiedTimestamp);
    entity.setKey(adminKeyBytes);
    entity.setSubmitKey(submitKeyBytes);
    entity.setStakedAccountId(-1L);
    entity.setStakedNodeId(-1L);
    entity.setStakePeriodStart(-1L);
    return entity;
}
Also used : AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) Entity(com.hedera.mirror.common.domain.entity.Entity)

Example 77 with Entity

use of com.hedera.mirror.common.domain.entity.Entity in project hedera-mirror-node by hashgraph.

the class SqlEntityListenerTest method onEntityWithNonHistoryUpdates.

@Test
void onEntityWithNonHistoryUpdates() {
    // given
    // Update to non-history field with existing entity should just update nonce
    Entity existingEntity = domainBuilder.entity().persist();
    Entity existingEntityNonce1 = existingEntity.toEntityId().toEntity();
    existingEntityNonce1.setEthereumNonce(100L);
    existingEntityNonce1.setTimestampRange(null);
    Entity existingEntityNonce2 = existingEntity.toEntityId().toEntity();
    existingEntityNonce2.setEthereumNonce(101L);
    existingEntityNonce2.setTimestampRange(null);
    Entity existingEntityStakePeriodStart1 = existingEntity.toEntityId().toEntity();
    existingEntityStakePeriodStart1.setStakePeriodStart(2L);
    existingEntityStakePeriodStart1.setTimestampRange(null);
    Entity existingEntityStakePeriodStart2 = existingEntity.toEntityId().toEntity();
    existingEntityStakePeriodStart2.setStakePeriodStart(5L);
    existingEntityStakePeriodStart2.setTimestampRange(null);
    // Update to non-history field with partial data should be discarded
    Entity nonExistingEntity = domainBuilder.entity().get();
    Entity nonExistingEntityNonce1 = nonExistingEntity.toEntityId().toEntity();
    nonExistingEntityNonce1.setEthereumNonce(200L);
    nonExistingEntityNonce1.setTimestampRange(null);
    Entity nonExistingEntityNonce2 = nonExistingEntity.toEntityId().toEntity();
    nonExistingEntityNonce2.setEthereumNonce(201L);
    nonExistingEntityNonce2.setTimestampRange(null);
    Entity nonExistingEntityStakePeriodStart1 = nonExistingEntity.toEntityId().toEntity();
    nonExistingEntityStakePeriodStart1.setStakePeriodStart(6L);
    nonExistingEntityStakePeriodStart1.setTimestampRange(null);
    Entity nonExistingEntityStakePeriodStart2 = nonExistingEntity.toEntityId().toEntity();
    nonExistingEntityStakePeriodStart2.setStakePeriodStart(8L);
    nonExistingEntityStakePeriodStart2.setTimestampRange(null);
    // when
    sqlEntityListener.onEntity(existingEntityNonce1);
    sqlEntityListener.onEntity(existingEntityNonce2);
    sqlEntityListener.onEntity(existingEntityStakePeriodStart1);
    sqlEntityListener.onEntity(existingEntityStakePeriodStart2);
    sqlEntityListener.onEntity(nonExistingEntityNonce1);
    sqlEntityListener.onEntity(nonExistingEntityNonce2);
    sqlEntityListener.onEntity(nonExistingEntityStakePeriodStart1);
    sqlEntityListener.onEntity(nonExistingEntityStakePeriodStart2);
    completeFileAndCommit();
    existingEntity.setEthereumNonce(existingEntityNonce2.getEthereumNonce());
    existingEntity.setStakePeriodStart(existingEntityStakePeriodStart2.getStakePeriodStart());
    assertThat(entityRepository.findAll()).containsExactly(existingEntity);
    Entity existingEntityNonce3 = existingEntity.toEntityId().toEntity();
    existingEntityNonce3.setEthereumNonce(102L);
    existingEntityNonce3.setTimestampRange(null);
    Entity existingEntityStakePeriodStart3 = existingEntity.toEntityId().toEntity();
    existingEntityStakePeriodStart3.setStakePeriodStart(10L);
    existingEntityStakePeriodStart3.setTimestampRange(null);
    Entity nonExistingEntityNonce3 = domainBuilder.entityId(EntityType.ACCOUNT).toEntity();
    nonExistingEntityNonce3.setEthereumNonce(202L);
    nonExistingEntityNonce3.setTimestampRange(null);
    Entity nonExistingEntityStakePeriodStart3 = domainBuilder.entityId(EntityType.ACCOUNT).toEntity();
    nonExistingEntityStakePeriodStart3.setStakePeriodStart(12L);
    nonExistingEntityStakePeriodStart3.setTimestampRange(null);
    sqlEntityListener.onEntity(existingEntityNonce3);
    sqlEntityListener.onEntity(existingEntityStakePeriodStart3);
    sqlEntityListener.onEntity(nonExistingEntityNonce3);
    sqlEntityListener.onEntity(nonExistingEntityStakePeriodStart3);
    completeFileAndCommit();
    // then
    existingEntity.setEthereumNonce(existingEntityNonce3.getEthereumNonce());
    existingEntity.setStakePeriodStart(existingEntityStakePeriodStart3.getStakePeriodStart());
    assertThat(entityRepository.findAll()).containsExactly(existingEntity);
    assertThat(findHistory(Entity.class)).isEmpty();
}
Also used : Entity(com.hedera.mirror.common.domain.entity.Entity) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 78 with Entity

use of com.hedera.mirror.common.domain.entity.Entity in project hedera-mirror-node by hashgraph.

the class SqlEntityListenerTest method onEntity.

@Test
void onEntity() {
    // given
    Entity entity1 = domainBuilder.entity().get();
    Entity entity2 = domainBuilder.entity().get();
    // when
    sqlEntityListener.onEntity(entity1);
    sqlEntityListener.onEntity(entity2);
    completeFileAndCommit();
    // then
    assertThat(contractRepository.count()).isZero();
    assertThat(entityRepository.findAll()).containsExactlyInAnyOrder(entity1, entity2);
    assertThat(findHistory(Entity.class)).isEmpty();
}
Also used : Entity(com.hedera.mirror.common.domain.entity.Entity) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Entity (com.hedera.mirror.common.domain.entity.Entity)78 Test (org.junit.jupiter.api.Test)52 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)40 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)23 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)22 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)21 Transaction (com.hederahashgraph.api.proto.java.Transaction)19 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)16 AbstractEntity (com.hedera.mirror.common.domain.entity.AbstractEntity)15 EntityId (com.hedera.mirror.common.domain.entity.EntityId)15 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)14 AccountID (com.hederahashgraph.api.proto.java.AccountID)11 CryptoUpdateTransactionBody (com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)10 ByteString (com.google.protobuf.ByteString)9 Contract (com.hedera.mirror.common.domain.contract.Contract)9 FileAppendTransactionBody (com.hederahashgraph.api.proto.java.FileAppendTransactionBody)9 FileCreateTransactionBody (com.hederahashgraph.api.proto.java.FileCreateTransactionBody)9 FileUpdateTransactionBody (com.hederahashgraph.api.proto.java.FileUpdateTransactionBody)9 Resource (javax.annotation.Resource)9 Assertions (org.junit.jupiter.api.Assertions)9