use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerCryptoTest method cryptoTransferFailedTransactionErrata.
@Test
void cryptoTransferFailedTransactionErrata() {
entityProperties.getPersist().setCryptoTransferAmounts(true);
Transaction transaction = cryptoTransferTransaction();
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord record = buildTransactionRecord(r -> {
for (int i = 0; i < additionalTransfers.length; i++) {
// Add non-fee transfers to record
var accountAmount = accountAmount(additionalTransfers[i], additionalTransferAmounts[i]);
r.getTransferListBuilder().addAccountAmounts(accountAmount);
}
}, transactionBody, ResponseCodeEnum.INVALID_ACCOUNT_ID.getNumber());
var recordItem = new RecordItem(transaction, record);
parseRecordItemAndCommit(recordItem);
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEntities(), () -> assertEquals(4, cryptoTransferRepository.count(), "Node, network fee & errata"), () -> assertEquals(0, nonFeeTransferRepository.count()), () -> assertTransactionAndRecord(transactionBody, record), () -> {
for (int i = 0; i < additionalTransfers.length; i++) {
var id = new CryptoTransfer.Id(additionalTransferAmounts[i], recordItem.getConsensusTimestamp(), additionalTransfers[i]);
assertThat(cryptoTransferRepository.findById(id)).get().extracting(CryptoTransfer::getErrata).isEqualTo(ErrataType.DELETE);
}
});
}
use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerCryptoTest method cryptoDeleteAllowance.
@Test
void cryptoDeleteAllowance() {
// given
var delegatingSpender = EntityId.of(recordItemBuilder.accountId());
var ownerAccountId = EntityId.of(recordItemBuilder.accountId());
var spender1 = EntityId.of(recordItemBuilder.accountId());
var spender2 = EntityId.of(recordItemBuilder.accountId());
var tokenId1 = EntityId.of(recordItemBuilder.tokenId());
var tokenId2 = EntityId.of(recordItemBuilder.tokenId());
List<NftRemoveAllowance> nftRemoveAllowances = List.of(NftRemoveAllowance.newBuilder().setOwner(AccountID.newBuilder().setAccountNum(ownerAccountId.getEntityNum())).setTokenId(TokenID.newBuilder().setTokenNum(tokenId1.getEntityNum())).addSerialNumbers(1L).addSerialNumbers(2L).build(), NftRemoveAllowance.newBuilder().setOwner(AccountID.newBuilder().setAccountNum(ownerAccountId.getEntityNum())).setTokenId(TokenID.newBuilder().setTokenNum(tokenId2.getEntityNum())).addSerialNumbers(1L).addSerialNumbers(2L).addSerialNumbers(2L).build());
RecordItem recordItem = recordItemBuilder.cryptoDeleteAllowance().transactionBody(b -> b.clearNftAllowances().addAllNftAllowances(nftRemoveAllowances)).build();
var nft1 = Nft.builder().accountId(ownerAccountId).createdTimestamp(10L).deleted(false).id(new NftId(1L, tokenId1)).modifiedTimestamp(recordItem.getConsensusTimestamp()).build();
var nft2 = Nft.builder().accountId(ownerAccountId).createdTimestamp(11L).deleted(false).id(new NftId(2L, tokenId1)).modifiedTimestamp(recordItem.getConsensusTimestamp()).build();
var nft3 = Nft.builder().accountId(ownerAccountId).createdTimestamp(12L).deleted(false).id(new NftId(1L, tokenId2)).modifiedTimestamp(recordItem.getConsensusTimestamp()).build();
var nft4 = Nft.builder().accountId(ownerAccountId).createdTimestamp(13L).deleted(false).id(new NftId(2L, tokenId2)).modifiedTimestamp(recordItem.getConsensusTimestamp()).build();
List<Nft> nftsWithAllowance = Stream.of(nft1.toBuilder().delegatingSpender(delegatingSpender).modifiedTimestamp(15L).spender(spender1), nft2.toBuilder().modifiedTimestamp(16L).spender(spender2), nft3.toBuilder().modifiedTimestamp(17L).spender(spender1), nft4.toBuilder().modifiedTimestamp(18L).spender(spender2)).map(Nft.NftBuilder::build).collect(Collectors.toList());
nftRepository.saveAll(nftsWithAllowance);
// when
parseRecordItemAndCommit(recordItem);
// then
assertAll(() -> assertEquals(0, entityRepository.count()), () -> assertTransactionAndRecord(recordItem.getTransactionBody(), recordItem.getRecord()), () -> assertThat(nftRepository.findAll()).containsExactlyInAnyOrder(nft1, nft2, nft3, nft4));
}
use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerCryptoTest method cryptoDeleteLiveHash.
@Test
void cryptoDeleteLiveHash() {
Transaction transactionAddLiveHash = cryptoAddLiveHashTransaction();
parseRecordItemAndCommit(new RecordItem(transactionAddLiveHash, transactionRecordSuccess(getTransactionBody(transactionAddLiveHash))));
// now delete the live hash
Transaction transaction = cryptoDeleteLiveHashTransaction();
TransactionBody transactionBody = getTransactionBody(transaction);
CryptoDeleteLiveHashTransactionBody deleteLiveHashTransactionBody = transactionBody.getCryptoDeleteLiveHash();
TransactionRecord record = transactionRecordSuccess(transactionBody);
parseRecordItemAndCommit(new RecordItem(transaction, record));
assertAll(() -> assertEquals(2, transactionRepository.count()), () -> assertEntities(), () -> assertCryptoTransfers(6), () -> assertEquals(1, liveHashRepository.count()), () -> assertTransactionAndRecord(transactionBody, record));
}
use of com.hedera.mirror.common.domain.transaction.RecordItem 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));
}
use of com.hedera.mirror.common.domain.transaction.RecordItem 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()));
}
Aggregations