Search in sources :

Example 1 with Entity

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

the class SqlEntityListenerTest method getEntity.

private Entity getEntity(long id, Long createdTimestamp, long modifiedTimestamp, String memo, Key adminKey, EntityId autoRenewAccountId, Long autoRenewPeriod, Boolean deleted, Long expiryTimeNs, Integer maxAutomaticTokenAssociations, Boolean receiverSigRequired, Key submitKey) {
    Entity entity = new Entity();
    entity.setId(id);
    entity.setAutoRenewAccountId(autoRenewAccountId);
    entity.setAutoRenewPeriod(autoRenewPeriod);
    entity.setCreatedTimestamp(createdTimestamp);
    entity.setDeleted(deleted);
    entity.setExpirationTimestamp(expiryTimeNs);
    entity.setKey(adminKey != null ? adminKey.toByteArray() : null);
    entity.setMaxAutomaticTokenAssociations(maxAutomaticTokenAssociations);
    entity.setTimestampLower(modifiedTimestamp);
    entity.setNum(id);
    entity.setRealm(0L);
    entity.setReceiverSigRequired(receiverSigRequired);
    entity.setShard(0L);
    entity.setSubmitKey(submitKey != null ? submitKey.toByteArray() : null);
    entity.setType(ACCOUNT);
    if (memo != null) {
        entity.setMemo(memo);
    }
    return entity;
}
Also used : Entity(com.hedera.mirror.common.domain.entity.Entity)

Example 2 with Entity

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

the class SqlEntityListenerTest method onEntityMerge.

@Test
void onEntityMerge() {
    // given
    Entity entity = getEntity(1, 1L, 1L, 0, "memo", keyFromString(KEY));
    sqlEntityListener.onEntity(entity);
    Entity entityAutoUpdated = getEntity(1, 5L);
    EntityId autoRenewAccountId = EntityId.of("0.0.10", ACCOUNT);
    entityAutoUpdated.setAutoRenewAccountId(autoRenewAccountId);
    entityAutoUpdated.setAutoRenewPeriod(360L);
    sqlEntityListener.onEntity(entityAutoUpdated);
    Entity entityExpirationUpdated = getEntity(1, 10L);
    entityExpirationUpdated.setExpirationTimestamp(720L);
    sqlEntityListener.onEntity(entityExpirationUpdated);
    Entity entitySubmitKeyUpdated = getEntity(1, 15L);
    entitySubmitKeyUpdated.setSubmitKey(keyFromString(KEY2).toByteArray());
    sqlEntityListener.onEntity(entitySubmitKeyUpdated);
    Entity entityMemoUpdated = getEntity(1, 20L);
    entityMemoUpdated.setMemo("memo-updated");
    sqlEntityListener.onEntity(entityMemoUpdated);
    Entity entityMaxAutomaticTokenAssociationsUpdated = getEntity(1, 25L);
    entityMaxAutomaticTokenAssociationsUpdated.setMaxAutomaticTokenAssociations(10);
    sqlEntityListener.onEntity(entityMaxAutomaticTokenAssociationsUpdated);
    Entity entityReceiverSigRequired = getEntity(1, 30L);
    entityReceiverSigRequired.setReceiverSigRequired(true);
    sqlEntityListener.onEntity(entityReceiverSigRequired);
    // when
    completeFileAndCommit();
    // then
    Entity expected = getEntity(1, 1L, 30L, "memo-updated", keyFromString(KEY), autoRenewAccountId, 360L, null, 720L, 10, true, keyFromString(KEY2));
    assertThat(entityRepository.findAll()).containsExactlyInAnyOrder(expected);
    assertThat(contractRepository.count()).isZero();
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) 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 3 with Entity

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

the class EntityRepositoryTest method storeAlias.

@Test
void storeAlias() {
    Entity entity = domainBuilder.entity().get();
    byte[] alias = entity.getAlias();
    entityRepository.storeAlias(alias, entity.getId());
    assertThat(entityRepository.findByAlias(alias)).get().isEqualTo(entity.getId());
}
Also used : Entity(com.hedera.mirror.common.domain.entity.Entity) Test(org.junit.jupiter.api.Test)

Example 4 with Entity

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

the class EntityRecordItemListenerCryptoTest method cryptoUpdateFailedTransaction.

@Test
void cryptoUpdateFailedTransaction() {
    Transaction createTransaction = cryptoCreateTransaction();
    TransactionRecord createRecord = transactionRecordSuccess(getTransactionBody(createTransaction));
    parseRecordItemAndCommit(new RecordItem(createTransaction, createRecord));
    // now update
    Transaction transaction = cryptoUpdateTransaction(accountId1);
    TransactionBody transactionBody = getTransactionBody(transaction);
    TransactionRecord record = transactionRecord(transactionBody, ResponseCodeEnum.INSUFFICIENT_ACCOUNT_BALANCE);
    parseRecordItemAndCommit(new RecordItem(transaction, record));
    Entity dbAccountEntityBefore = getTransactionEntity(createRecord.getConsensusTimestamp());
    Entity dbAccountEntity = getTransactionEntity(record.getConsensusTimestamp());
    assertAll(() -> assertEquals(2, transactionRepository.count()), () -> assertEntities(EntityId.of(accountId1)), // 3 + 3 fee transfers with one transfer per account
    () -> assertCryptoTransfers(6), () -> assertTransactionAndRecord(transactionBody, record), () -> assertAccount(record.getReceipt().getAccountID(), dbAccountEntity), // no changes to entity
    () -> assertEquals(dbAccountEntityBefore, dbAccountEntity));
}
Also used : Entity(com.hedera.mirror.common.domain.entity.Entity) CryptoDeleteLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) CryptoAddLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) UtilityTest(com.hedera.mirror.importer.util.UtilityTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with Entity

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

the class EntityRecordItemListenerCryptoTest method cryptoUpdateSuccessfulTransaction.

@Test
void cryptoUpdateSuccessfulTransaction() {
    createAccount();
    // now update
    Transaction transaction = cryptoUpdateTransaction(accountId1);
    TransactionBody transactionBody = getTransactionBody(transaction);
    CryptoUpdateTransactionBody cryptoUpdateTransactionBody = transactionBody.getCryptoUpdateAccount();
    TransactionRecord record = transactionRecordSuccess(transactionBody);
    parseRecordItemAndCommit(new RecordItem(transaction, record));
    Entity dbAccountEntity = getTransactionEntity(record.getConsensusTimestamp());
    assertAll(() -> assertEquals(2, transactionRepository.count()), () -> assertEntities(EntityId.of(accountId1)), () -> assertEquals(6, cryptoTransferRepository.count()), () -> assertCryptoTransaction(transactionBody, record), // transaction body inputs
    () -> assertEquals(cryptoUpdateTransactionBody.getAutoRenewPeriod().getSeconds(), dbAccountEntity.getAutoRenewPeriod()), () -> assertEquals(DomainUtils.getPublicKey(cryptoUpdateTransactionBody.getKey().toByteArray()), dbAccountEntity.getPublicKey()), () -> assertEquals(EntityId.of(cryptoUpdateTransactionBody.getProxyAccountID()), dbAccountEntity.getProxyAccountId()), () -> assertArrayEquals(cryptoUpdateTransactionBody.getKey().toByteArray(), dbAccountEntity.getKey()), () -> assertEquals(cryptoUpdateTransactionBody.getMaxAutomaticTokenAssociations().getValue(), dbAccountEntity.getMaxAutomaticTokenAssociations()), () -> assertEquals(cryptoUpdateTransactionBody.getMemo().getValue(), dbAccountEntity.getMemo()), () -> assertEquals(DomainUtils.timeStampInNanos(cryptoUpdateTransactionBody.getExpirationTime()), dbAccountEntity.getExpirationTimestamp()), () -> assertEquals(DomainUtils.timestampInNanosMax(record.getConsensusTimestamp()), dbAccountEntity.getTimestampLower()), () -> assertFalse(dbAccountEntity.getReceiverSigRequired()), () -> assertFalse(dbAccountEntity.isDeclineReward()), () -> assertEquals(cryptoUpdateTransactionBody.getStakedNodeId(), dbAccountEntity.getStakedNodeId()), () -> assertEquals(-1L, dbAccountEntity.getStakedAccountId()), () -> assertEquals(Utility.getEpochDay(DomainUtils.timestampInNanosMax(record.getConsensusTimestamp())), dbAccountEntity.getStakePeriodStart()));
}
Also used : Entity(com.hedera.mirror.common.domain.entity.Entity) CryptoDeleteLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) CryptoAddLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) UtilityTest(com.hedera.mirror.importer.util.UtilityTest) Test(org.junit.jupiter.api.Test) 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