Search in sources :

Example 6 with AbstractEntity

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

the class AbstractTransactionHandlerTest method getUpdateEntityTestSpecsForCreateTransaction.

protected List<UpdateEntityTestSpec> getUpdateEntityTestSpecsForCreateTransaction(FieldDescriptor memoField) {
    TransactionBody body = getTransactionBodyForUpdateEntityWithoutMemo();
    Message innerBody = getInnerBody(body);
    List<UpdateEntityTestSpec> testSpecs = new LinkedList<>();
    AbstractEntity expected = getExpectedUpdatedEntity();
    // Proto defaults to empty string
    expected.setMemo("");
    // no memo set, expect empty memo
    testSpecs.add(UpdateEntityTestSpec.builder().description("create entity without memo, expect empty memo").expected(expected).recordItem(getRecordItem(body, innerBody)).build());
    expected = getExpectedUpdatedEntity();
    expected.setMemo("");
    // memo set to empty string, expect empty memo
    Message updatedInnerBody = innerBody.toBuilder().setField(memoField, "").build();
    testSpecs.add(UpdateEntityTestSpec.builder().description("create entity with empty memo, expect empty memo").expected(expected).recordItem(getRecordItem(body, updatedInnerBody)).build());
    // memo set to non-empty string, expect memo set
    expected = getExpectedUpdatedEntity();
    expected.setMemo(DEFAULT_MEMO);
    updatedInnerBody = innerBody.toBuilder().setField(memoField, DEFAULT_MEMO).build();
    testSpecs.add(UpdateEntityTestSpec.builder().description("create entity with non-empty memo, expect memo set").expected(expected).recordItem(getRecordItem(body, updatedInnerBody)).build());
    return testSpecs;
}
Also used : TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Message(com.google.protobuf.Message) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) LinkedList(java.util.LinkedList)

Example 7 with AbstractEntity

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

the class TokenUpdateTransactionHandlerTest method updateTreasury.

@Test
void updateTreasury() {
    AbstractEntity entity = getExpectedUpdatedEntity();
    AccountID previousAccountId = AccountID.newBuilder().setAccountNum(1L).build();
    AccountID newAccountId = AccountID.newBuilder().setAccountNum(2L).build();
    TokenID tokenID = TokenID.newBuilder().setTokenNum(3L).build();
    long consensusTimestamp = DomainUtils.timestampInNanosMax(MODIFIED_TIMESTAMP);
    TokenTransferList tokenTransferList = TokenTransferList.newBuilder().setToken(tokenID).addNftTransfers(NftTransfer.newBuilder().setReceiverAccountID(newAccountId).setSenderAccountID(previousAccountId).setSerialNumber(NftTransferId.WILDCARD_SERIAL_NUMBER).build()).build();
    TransactionRecord record = getDefaultTransactionRecord().addTokenTransferLists(tokenTransferList).build();
    RecordItem recordItem = getRecordItem(getDefaultTransactionBody().build(), record);
    when(entityIdService.lookup(AccountID.newBuilder().setAccountNum(DEFAULT_AUTO_RENEW_ACCOUNT_NUM).build())).thenReturn(EntityIdEndec.decode(DEFAULT_AUTO_RENEW_ACCOUNT_NUM, EntityType.ACCOUNT));
    Transaction transaction = new Transaction();
    transaction.setEntityId(entity.toEntityId());
    transactionHandler.updateTransaction(transaction, recordItem);
    TransactionBody body = recordItem.getTransactionBody();
    var payerAccount = EntityId.of(body.getTransactionID().getAccountID()).toEntity().getId();
    verify(nftRepository).updateTreasury(tokenID.getTokenNum(), previousAccountId.getAccountNum(), newAccountId.getAccountNum(), consensusTimestamp, payerAccount, false);
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody) AccountID(com.hederahashgraph.api.proto.java.AccountID) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) TokenID(com.hederahashgraph.api.proto.java.TokenID) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with AbstractEntity

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

the class HistoricalAccountInfoMigration method process.

boolean process(AccountInfo accountInfo) {
    EntityType entityType = EntityType.ACCOUNT;
    long id = EntityId.of(accountInfo.getAccountID()).getId();
    if (contractIds.contains(id)) {
        entityType = EntityType.CONTRACT;
    }
    EntityId entityId = EntityIdEndec.decode(id, entityType);
    CrudRepository<AbstractEntity, Long> repository = getRepository(entityType);
    Optional<AbstractEntity> currentEntity = repository.findById(entityId.getId());
    boolean exists = currentEntity.isPresent();
    AbstractEntity entity = currentEntity.orElseGet(entityId::toEntity);
    boolean updated = !exists;
    // All contract accounts don't have to have a key, but luckily in our file they do.
    if (exists && ArrayUtils.isNotEmpty(entity.getKey())) {
        log.trace("Skipping entity {} that was created after the reset", entityId::entityIdToString);
        return false;
    }
    if (entity.getAutoRenewPeriod() == null && accountInfo.hasAutoRenewPeriod()) {
        entity.setAutoRenewPeriod(accountInfo.getAutoRenewPeriod().getSeconds());
        updated = true;
    }
    // Accounts can't be undeleted
    if (entity.getDeleted() == null || (entity.getDeleted() != accountInfo.getDeleted() && accountInfo.getDeleted())) {
        entity.setDeleted(accountInfo.getDeleted());
        updated = true;
    }
    if (entity.getExpirationTimestamp() == null && accountInfo.hasExpirationTime()) {
        entity.setExpirationTimestamp(DomainUtils.timestampInNanosMax(accountInfo.getExpirationTime()));
        updated = true;
    }
    if (entity.getKey() == null && accountInfo.hasKey()) {
        entity.setKey(accountInfo.getKey().toByteArray());
        updated = true;
    }
    if (StringUtils.isEmpty(entity.getMemo())) {
        entity.setMemo(accountInfo.getMemo());
        updated = true;
    }
    if (entity.getProxyAccountId() == null && accountInfo.hasProxyAccountID()) {
        EntityId proxyAccountEntityId = EntityId.of(accountInfo.getProxyAccountID());
        // Proxy account should get created separately
        entity.setProxyAccountId(proxyAccountEntityId);
        updated |= proxyAccountEntityId != null;
    }
    if (updated) {
        log.info("Saving {} entity: {}", exists ? "existing" : "new", entity);
        repository.save(entity);
    }
    return updated;
}
Also used : EntityType(com.hedera.mirror.common.domain.entity.EntityType) EntityId(com.hedera.mirror.common.domain.entity.EntityId) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity)

Example 9 with AbstractEntity

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

the class EntityRecordItemListenerTopicTest method createTopicTestExistingAutoRenewAccount.

// https://github.com/hashgraph/hedera-mirror-node/issues/501
@Test
void createTopicTestExistingAutoRenewAccount() {
    Long autoRenewAccountId = 100L;
    var consensusTimestamp = 2_000_000L;
    var responseCode = SUCCESS;
    var transaction = createCreateTopicTransaction(null, null, "", autoRenewAccountId, null);
    var transactionRecord = createTransactionRecord(TOPIC_ID, null, null, 1, consensusTimestamp, responseCode);
    parseRecordItemAndCommit(new RecordItem(transaction, transactionRecord));
    var entity = getTopicEntity(TOPIC_ID);
    assertTransactionInRepository(responseCode, consensusTimestamp, entity.getId());
    assertEquals(1L, entityRepository.count());
    assertThat(entity).returns("".getBytes(), from(Entity::getKey)).returns("".getBytes(), from(Entity::getSubmitKey)).returns("", from(Entity::getMemo)).returns(false, from(Entity::getDeleted)).returns(EntityType.TOPIC, from(Entity::getType)).returns(autoRenewAccountId, AbstractEntity::getAutoRenewAccountId);
}
Also used : AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) Entity(com.hedera.mirror.common.domain.entity.Entity) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with AbstractEntity

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

the class AbstractDeleteOrUndeleteTransactionHandlerTest method getUpdateEntityTestSpecs.

@Override
protected List<UpdateEntityTestSpec> getUpdateEntityTestSpecs() {
    String description = deleteOrUndelete ? "delete entity transaction, expect entity deleted" : "undelete entity transaction, expect entity undeleted";
    AbstractEntity expected = getExpectedEntityWithTimestamp();
    expected.setDeleted(deleteOrUndelete);
    return List.of(UpdateEntityTestSpec.builder().description(description).expected(expected).recordItem(getRecordItem(getDefaultTransactionBody().build(), getDefaultTransactionRecord().build())).build());
}
Also used : AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity)

Aggregations

AbstractEntity (com.hedera.mirror.common.domain.entity.AbstractEntity)14 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)6 Message (com.google.protobuf.Message)5 Entity (com.hedera.mirror.common.domain.entity.Entity)3 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)3 Test (org.junit.jupiter.api.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)2 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)2 TokenTransferList (com.hederahashgraph.api.proto.java.TokenTransferList)2 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)2 LinkedList (java.util.LinkedList)2 ByteString (com.google.protobuf.ByteString)1 Contract (com.hedera.mirror.common.domain.contract.Contract)1 EntityId (com.hedera.mirror.common.domain.entity.EntityId)1 EntityOperation (com.hedera.mirror.common.domain.entity.EntityOperation)1 EntityType (com.hedera.mirror.common.domain.entity.EntityType)1 AccountID (com.hederahashgraph.api.proto.java.AccountID)1 ContractCreateTransactionBody (com.hederahashgraph.api.proto.java.ContractCreateTransactionBody)1 CryptoCreateTransactionBody (com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody)1