Search in sources :

Example 66 with Entity

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

the class EntityRecordItemListenerCryptoTest method cryptoTransferWithAlias.

@Test
void cryptoTransferWithAlias() {
    entityProperties.getPersist().setCryptoTransferAmounts(true);
    entityProperties.getPersist().setNonFeeTransfers(true);
    Entity entity = domainBuilder.entity().persist();
    var newAccount = AccountID.newBuilder().setAccountNum(domainBuilder.id()).build();
    assertThat(entityRepository.findByAlias(entity.getAlias())).get().isEqualTo(entity.getId());
    assertThat(entityRepository.findByAlias(ALIAS_KEY.toByteArray())).isNotPresent();
    // Crypto create alias account
    Transaction accountCreateTransaction = cryptoCreateTransaction();
    TransactionBody accountCreateTransactionBody = getTransactionBody(accountCreateTransaction);
    TransactionRecord recordCreate = buildTransactionRecord(recordBuilder -> recordBuilder.setAlias(ALIAS_KEY).getReceiptBuilder().setAccountID(newAccount), accountCreateTransactionBody, ResponseCodeEnum.SUCCESS.getNumber());
    var transfer1 = accountAliasAmount(ALIAS_KEY, 1003).build();
    var transfer2 = accountAliasAmount(ByteString.copyFrom(entity.getAlias()), 1004).build();
    // Crypto transfer to both existing alias and newly created alias accounts
    Transaction transaction = buildTransaction(builder -> builder.getCryptoTransferBuilder().getTransfersBuilder().addAccountAmounts(transfer1).addAccountAmounts(transfer2));
    TransactionBody transactionBody = getTransactionBody(transaction);
    TransactionRecord recordTransfer = transactionRecordSuccess(transactionBody, builder -> groupCryptoTransfersByAccountId(builder, List.of()));
    parseRecordItemsAndCommit(List.of(new RecordItem(accountCreateTransaction, recordCreate), new RecordItem(transaction, recordTransfer)));
    assertAll(() -> assertEquals(2, transactionRepository.count()), () -> assertEntities(EntityId.of(newAccount), entity.toEntityId()), () -> assertCryptoTransfers(6).areAtMost(1, isAccountAmountReceiverAccountAmount(transfer1)).areAtMost(1, isAccountAmountReceiverAccountAmount(transfer2)), () -> assertEquals(additionalTransfers.length * 2 + 2, nonFeeTransferRepository.count()), () -> assertTransactionAndRecord(transactionBody, recordTransfer), () -> assertThat(findNonFeeTransfers()).extracting(NonFeeTransfer::getEntityId).extracting(EntityId::getEntityNum).contains(newAccount.getAccountNum(), entity.getNum()));
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) 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 67 with Entity

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

the class EntityRecordItemListenerCryptoTest method cryptoDeleteFailedTransaction.

@Test
void cryptoDeleteFailedTransaction() {
    createAccount();
    // now delete
    Transaction transaction = cryptoDeleteTransaction();
    TransactionBody transactionBody = getTransactionBody(transaction);
    TransactionRecord record = transactionRecord(transactionBody, ResponseCodeEnum.INSUFFICIENT_ACCOUNT_BALANCE.getNumber(), recordBuilder -> groupCryptoTransfersByAccountId(recordBuilder, List.of()));
    parseRecordItemAndCommit(new RecordItem(transaction, record));
    Entity dbAccountEntity = getTransactionEntity(record.getConsensusTimestamp());
    assertAll(() -> assertEquals(2, transactionRepository.count()), () -> assertEntities(EntityId.of(accountId1)), // 3 + 3 fee transfers with only one transfer per account
    () -> assertCryptoTransfers(6), () -> assertCryptoTransaction(transactionBody, record), () -> assertThat(dbAccountEntity).isNotNull().returns(false, Entity::getDeleted));
}
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 68 with Entity

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

the class EntityRecordItemListenerCryptoTest method assertCryptoEntity.

private void assertCryptoEntity(CryptoCreateTransactionBody expected, Timestamp consensusTimestamp) {
    Entity actualAccount = getTransactionEntity(consensusTimestamp);
    long timestamp = DomainUtils.timestampInNanosMax(consensusTimestamp);
    assertAll(() -> assertEquals(expected.getAutoRenewPeriod().getSeconds(), actualAccount.getAutoRenewPeriod()), () -> assertEquals(timestamp, actualAccount.getCreatedTimestamp()), () -> assertEquals(false, actualAccount.getDeleted()), () -> assertNull(actualAccount.getExpirationTimestamp()), () -> assertArrayEquals(expected.getKey().toByteArray(), actualAccount.getKey()), () -> assertEquals(0, actualAccount.getMaxAutomaticTokenAssociations()), () -> assertEquals(expected.getMemo(), actualAccount.getMemo()), () -> assertEquals(timestamp, actualAccount.getTimestampLower()), () -> assertEquals(DomainUtils.getPublicKey(expected.getKey().toByteArray()), actualAccount.getPublicKey()), () -> assertEquals(EntityId.of(expected.getProxyAccountID()), actualAccount.getProxyAccountId()), () -> assertEquals(expected.getReceiverSigRequired(), actualAccount.getReceiverSigRequired()));
}
Also used : Entity(com.hedera.mirror.common.domain.entity.Entity)

Example 69 with Entity

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

the class EntityRecordItemListenerEthereumTest method ethereumTransactionEip1559.

@ValueSource(booleans = { true, false })
@ParameterizedTest
void ethereumTransactionEip1559(boolean create) {
    RecordItem recordItem = recordItemBuilder.ethereumTransaction(create).build();
    var record = recordItem.getRecord();
    var functionResult = create ? record.getContractCreateResult() : record.getContractCallResult();
    var senderId = EntityId.of(functionResult.getSenderId());
    Entity sender = domainBuilder.entity().customize(e -> e.id(senderId.getId()).num(senderId.getEntityNum())).persist();
    parseRecordItemAndCommit(recordItem);
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(1, contractRepository.count()), () -> assertEquals(1, entityRepository.count()), () -> assertEquals(1, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertEquals(1, ethereumTransactionRepository.count()), () -> assertThat(contractResultRepository.findAll()).hasSize(1), () -> assertEthereumTransaction(recordItem, sender));
}
Also used : ValueSource(org.junit.jupiter.params.provider.ValueSource) BeforeEach(org.junit.jupiter.api.BeforeEach) DomainUtils(com.hedera.mirror.common.util.DomainUtils) FileID(com.hederahashgraph.api.proto.java.FileID) Hash(org.web3j.crypto.Hash) SneakyThrows(lombok.SneakyThrows) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Integers(com.esaulpaugh.headlong.util.Integers) RequiredArgsConstructor(lombok.RequiredArgsConstructor) RLPEncoder(com.esaulpaugh.headlong.rlp.RLPEncoder) Autowired(org.springframework.beans.factory.annotation.Autowired) Hex(org.apache.commons.codec.binary.Hex) LegacyEthereumTransactionParserTest(com.hedera.mirror.importer.parser.record.ethereum.LegacyEthereumTransactionParserTest) Entity(com.hedera.mirror.common.domain.entity.Entity) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) EthereumTransactionRepository(com.hedera.mirror.importer.repository.EthereumTransactionRepository) Assertions(org.junit.jupiter.api.Assertions) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) EthereumTransaction(com.hedera.mirror.common.domain.transaction.EthereumTransaction) InvalidDatasetException(com.hedera.mirror.importer.exception.InvalidDatasetException) Entity(com.hedera.mirror.common.domain.entity.Entity) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 70 with Entity

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

the class EntityRecordItemListenerFileTest method fileUpdateExpiryToExisting.

@Test
void fileUpdateExpiryToExisting() {
    // first create the file
    Transaction fileCreateTransaction = fileCreateTransaction();
    TransactionBody createTransactionBody = getTransactionBody(fileCreateTransaction);
    TransactionRecord recordCreate = transactionRecord(createTransactionBody);
    parseRecordItemAndCommit(new RecordItem(fileCreateTransaction, recordCreate));
    // now update
    Transaction transaction = fileUpdateExpiryTransaction();
    TransactionBody transactionBody = getTransactionBody(transaction);
    TransactionRecord record = transactionRecord(transactionBody);
    parseRecordItemAndCommit(new RecordItem(transaction, record));
    Entity actualFile = getTransactionEntity(record.getConsensusTimestamp());
    assertAll(// TODO: Review row count of fileDataRepository with issue #294, probably should be 1
    () -> assertRowCountOnTwoFileTransactions(), () -> assertTransactionAndRecord(transactionBody, record), // Additional entity checks
    () -> assertFalse(actualFile.getDeleted()), () -> assertEquals(DomainUtils.timeStampInNanos(transactionBody.getFileUpdate().getExpirationTime()), actualFile.getExpirationTimestamp()), () -> assertNotNull(actualFile.getKey()), () -> assertNull(actualFile.getAutoRenewPeriod()), () -> assertNull(actualFile.getProxyAccountId()));
}
Also used : Entity(com.hedera.mirror.common.domain.entity.Entity) FileAppendTransactionBody(com.hederahashgraph.api.proto.java.FileAppendTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) FileUpdateTransactionBody(com.hederahashgraph.api.proto.java.FileUpdateTransactionBody) FileCreateTransactionBody(com.hederahashgraph.api.proto.java.FileCreateTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) 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)

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