Search in sources :

Example 21 with Entity

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

the class EntityRecordItemListenerTokenTest method tokenCreate.

void tokenCreate(List<CustomFee> customFees, boolean freezeDefault, boolean freezeKey, boolean kycKey, boolean pauseKey, List<TokenAccount> expectedTokenAccounts, List<EntityId> autoAssociatedAccounts) {
    // given
    Entity expected = createEntity(DOMAIN_TOKEN_ID, TOKEN_REF_KEY, PAYER.getAccountNum(), AUTO_RENEW_PERIOD, false, EXPIRY_NS, TOKEN_CREATE_MEMO, null, CREATE_TIMESTAMP, CREATE_TIMESTAMP);
    // when
    createTokenEntity(TOKEN_ID, FUNGIBLE_COMMON, SYMBOL, CREATE_TIMESTAMP, freezeDefault, freezeKey, kycKey, pauseKey, customFees, autoAssociatedAccounts);
    // then
    assertEquals(1L, entityRepository.count());
    assertEntity(expected);
    // verify token
    TokenPauseStatusEnum pauseStatus = pauseKey ? TokenPauseStatusEnum.UNPAUSED : TokenPauseStatusEnum.NOT_APPLICABLE;
    assertTokenInRepository(TOKEN_ID, true, CREATE_TIMESTAMP, CREATE_TIMESTAMP, SYMBOL, INITIAL_SUPPLY, pauseStatus);
    assertThat(tokenAccountRepository.findAll()).containsExactlyInAnyOrderElementsOf(expectedTokenAccounts);
    assertTokenTransferInRepository(TOKEN_ID, PAYER, CREATE_TIMESTAMP, INITIAL_SUPPLY);
    assertCustomFeesInDb(customFees);
    assertThat(tokenTransferRepository.count()).isEqualTo(1L);
}
Also used : Entity(com.hedera.mirror.common.domain.entity.Entity) TokenPauseStatusEnum(com.hedera.mirror.common.domain.token.TokenPauseStatusEnum)

Example 22 with Entity

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

the class EntityRecordItemListenerTopicTest method createTopicEntity.

private Entity createTopicEntity(TopicID topicId, Long expirationTimeSeconds, Integer expirationTimeNanos, Key adminKey, Key submitKey, String memo, Long autoRenewAccountNum, Long autoRenewPeriod) {
    Entity topic = EntityId.of(topicId).toEntity();
    if (autoRenewAccountNum != null) {
        topic.setAutoRenewAccountId(autoRenewAccountNum);
    }
    if (autoRenewPeriod != null) {
        topic.setAutoRenewPeriod(autoRenewPeriod);
    }
    if (expirationTimeSeconds != null && expirationTimeNanos != null) {
        topic.setExpirationTimestamp(DomainUtils.convertToNanosMax(expirationTimeSeconds, expirationTimeNanos));
    }
    if (null != adminKey) {
        topic.setKey(adminKey.toByteArray());
    }
    if (null != submitKey) {
        topic.setSubmitKey(submitKey.toByteArray());
    }
    topic.setEthereumNonce(0L);
    topic.setMemo(memo);
    topic.setType(EntityType.TOPIC);
    topic.setStakedAccountId(-1L);
    topic.setStakedNodeId(-1L);
    topic.setStakePeriodStart(-1L);
    return topic;
}
Also used : AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) Entity(com.hedera.mirror.common.domain.entity.Entity)

Example 23 with Entity

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

the class CryptoCreateTransactionHandlerTest method updateTransactionStakedAccountId.

@Test
void updateTransactionStakedAccountId() {
    // given
    final AccountID accountId = AccountID.newBuilder().setAccountNum(1L).build();
    var recordItem = recordItemBuilder.cryptoCreate().transactionBody(b -> b.setDeclineReward(false).setStakedAccountId(accountId)).build();
    // when
    transactionHandler.updateTransaction(transaction(recordItem), recordItem);
    // then
    verify(entityListener).onEntity(entities.capture());
    assertThat(entities.getValue()).isNotNull().returns(false, Entity::isDeclineReward).returns(accountId.getAccountNum(), Entity::getStakedAccountId).returns(Utility.getEpochDay(recordItem.getConsensusTimestamp()), Entity::getStakePeriodStart);
}
Also used : CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) DomainUtils(com.hedera.mirror.common.util.DomainUtils) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) Captor(org.mockito.Captor) EntityType(com.hedera.mirror.common.domain.entity.EntityType) Mockito.verify(org.mockito.Mockito.verify) TransactionReceipt(com.hederahashgraph.api.proto.java.TransactionReceipt) Entity(com.hedera.mirror.common.domain.entity.Entity) Test(org.junit.jupiter.api.Test) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) List(java.util.List) UtilityTest(com.hedera.mirror.importer.util.UtilityTest) ArgumentCaptor(org.mockito.ArgumentCaptor) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Message(com.google.protobuf.Message) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) AccountID(com.hederahashgraph.api.proto.java.AccountID) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) Utility(com.hedera.mirror.importer.util.Utility) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) Entity(com.hedera.mirror.common.domain.entity.Entity) AccountID(com.hederahashgraph.api.proto.java.AccountID) Test(org.junit.jupiter.api.Test) UtilityTest(com.hedera.mirror.importer.util.UtilityTest)

Example 24 with Entity

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

the class AbstractTransactionHandlerTest method getUpdateEntityTestSpecsForUpdateTransaction.

private List<UpdateEntityTestSpec> getUpdateEntityTestSpecsForUpdateTransaction(FieldDescriptor memoField, FieldDescriptor memoWrapperField, FieldDescriptor maxAutomaticTokenAssociationsField, FieldDescriptor receiverSigRequiredWrapperField) {
    TransactionBody body = getTransactionBodyForUpdateEntityWithoutMemo();
    Message innerBody = getInnerBody(body);
    List<UpdateEntityTestSpec> testSpecs = new LinkedList<>();
    if (receiverSigRequiredWrapperField != null) {
        innerBody = innerBody.toBuilder().setField(receiverSigRequiredWrapperField, UPDATED_RECEIVER_SIG_REQUIRED).build();
    }
    AbstractEntity expected = getExpectedUpdatedEntity();
    Message unchangedMemoInnerBody = innerBody;
    if (receiverSigRequiredWrapperField != null && expected instanceof Entity) {
        ((Entity) expected).setReceiverSigRequired(UPDATED_RECEIVER_SIG_REQUIRED.getValue());
    }
    testSpecs.add(UpdateEntityTestSpec.builder().description("update entity without memo").expected(expected).recordItem(getRecordItem(body, unchangedMemoInnerBody)).build());
    Message updatedMemoInnerBody = innerBody;
    if (memoWrapperField != null) {
        // memo is of string type
        // non-empty string, expect memo set to non-empty string
        expected = getExpectedUpdatedEntity();
        expected.setMemo(UPDATED_MEMO);
        updatedMemoInnerBody = innerBody.toBuilder().setField(memoField, UPDATED_MEMO).build();
    }
    if (receiverSigRequiredWrapperField != null && expected instanceof Entity) {
        ((Entity) expected).setReceiverSigRequired(UPDATED_RECEIVER_SIG_REQUIRED.getValue());
    }
    testSpecs.add(UpdateEntityTestSpec.builder().description("update entity with non-empty String").expected(expected).recordItem(getRecordItem(body, updatedMemoInnerBody)).build());
    // memo is set through the StringValue field
    // there is always a StringValue field, either "memo" or "memoWrapper"
    FieldDescriptor field = memoWrapperField;
    if (field == null) {
        field = memoField;
    }
    expected = getExpectedUpdatedEntity();
    expected.setMemo("");
    Message clearedMemoInnerBody = innerBody.toBuilder().setField(field, StringValue.of("")).build();
    if (receiverSigRequiredWrapperField != null && expected instanceof Entity) {
        ((Entity) expected).setReceiverSigRequired(UPDATED_RECEIVER_SIG_REQUIRED.getValue());
    }
    testSpecs.add(UpdateEntityTestSpec.builder().description("update entity with empty StringValue memo, expect memo cleared").expected(expected).recordItem(getRecordItem(body, clearedMemoInnerBody)).build());
    // non-empty StringValue, expect memo in entity updated
    expected = getExpectedUpdatedEntity();
    expected.setMemo(UPDATED_MEMO);
    Message memoStringValueUpdatedInnerBody = innerBody.toBuilder().setField(field, StringValue.of(UPDATED_MEMO)).build();
    if (receiverSigRequiredWrapperField != null && expected instanceof Entity) {
        ((Entity) expected).setReceiverSigRequired(UPDATED_RECEIVER_SIG_REQUIRED.getValue());
    }
    testSpecs.add(UpdateEntityTestSpec.builder().description("update entity with non-empty StringValue memo, expect memo updated").expected(expected).recordItem(getRecordItem(body, memoStringValueUpdatedInnerBody)).build());
    if (maxAutomaticTokenAssociationsField != null) {
        expected = getExpectedUpdatedEntity();
        expected.setMaxAutomaticTokenAssociations(500);
        if (expected instanceof Entity) {
            ((Entity) expected).setReceiverSigRequired(true);
        }
        Message updatedInnerBody = innerBody.toBuilder().setField(maxAutomaticTokenAssociationsField, Int32Value.of(500)).build();
        testSpecs.add(UpdateEntityTestSpec.builder().description("update entity with max_automatic_token_associations").expected(expected).recordItem(getRecordItem(body, updatedInnerBody)).build());
    }
    return testSpecs;
}
Also used : AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) Entity(com.hedera.mirror.common.domain.entity.Entity) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Message(com.google.protobuf.Message) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) LinkedList(java.util.LinkedList) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 25 with Entity

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

the class CryptoUpdateTransactionHandlerTest method updateTransactionStakedNodeId.

@Test
void updateTransactionStakedNodeId() {
    RecordItem withStakedNodeIdSet = recordItemBuilder.cryptoUpdate().transactionBody(body -> body.setStakedNodeId(1L)).build();
    setupForCrytoUpdateTransactionTest(withStakedNodeIdSet, t -> assertThat(t).returns(1L, Entity::getStakedNodeId).returns(-1L, Entity::getStakedAccountId).returns(true, Entity::isDeclineReward).extracting(Entity::getStakePeriodStart).isNotNull());
}
Also used : CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) BoolValue(com.google.protobuf.BoolValue) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Range(com.google.common.collect.Range) Mockito.times(org.mockito.Mockito.times) EntityType(com.hedera.mirror.common.domain.entity.EntityType) Mockito.verify(org.mockito.Mockito.verify) Entity(com.hedera.mirror.common.domain.entity.Entity) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Assertions(org.junit.jupiter.api.Assertions) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) AccountID(com.hederahashgraph.api.proto.java.AccountID) Utility(com.hedera.mirror.importer.util.Utility) Entity(com.hedera.mirror.common.domain.entity.Entity) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test)

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