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()));
}
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));
}
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()));
}
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));
}
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()));
}
Aggregations