use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerCryptoTest method testRawBytes.
private void testRawBytes(Transaction transaction, byte[] expectedBytes) {
// given
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord record = transactionRecordSuccess(transactionBody);
// when
parseRecordItemAndCommit(new RecordItem(transaction, record));
// then
var dbTransaction = getDbTransaction(record.getConsensusTimestamp());
assertArrayEquals(expectedBytes, dbTransaction.getTransactionBytes());
}
use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerCryptoTest method cryptoUpdateExpirationOverflow.
@DisplayName("update account such that expiration timestamp overflows nanos_timestamp")
@ParameterizedTest(name = "with seconds {0} and expectedNanosTimestamp {1}")
@CsvSource({ "9223372036854775807, 9223372036854775807", "31556889864403199, 9223372036854775807", "-9223372036854775808, -9223372036854775808", "-1000000000000000000, -9223372036854775808" })
void cryptoUpdateExpirationOverflow(long seconds, long expectedNanosTimestamp) {
createAccount();
// now update
var updateTransaction = buildTransaction(builder -> {
builder.getCryptoUpdateAccountBuilder().setAccountIDToUpdate(accountId1).setExpirationTime(Timestamp.newBuilder().setSeconds(seconds)).setDeclineReward(BoolValue.of(true)).setStakedAccountId(AccountID.newBuilder().setAccountNum(1L).build());
});
var transactionBody = getTransactionBody(updateTransaction);
var record = transactionRecordSuccess(transactionBody);
parseRecordItemAndCommit(new RecordItem(updateTransaction, record));
var dbAccountEntity = getTransactionEntity(record.getConsensusTimestamp());
var entityId = EntityId.of(transactionBody.getCryptoUpdateAccount().getStakedAccountId());
long stakedAccountId = AccountIdConverter.INSTANCE.convertToDatabaseColumn(entityId);
assertAll(() -> assertEquals(2, transactionRepository.count()), () -> assertEquals(expectedNanosTimestamp, dbAccountEntity.getExpirationTimestamp()), () -> assertTrue(dbAccountEntity.isDeclineReward()), () -> assertEquals(stakedAccountId, dbAccountEntity.getStakedAccountId()), () -> assertEquals(-1L, dbAccountEntity.getStakedNodeId()));
}
use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerCryptoTest method samePayerAndUpdateAccount.
/**
* Github issue #483
*/
@Test
void samePayerAndUpdateAccount() {
Transaction transaction = cryptoUpdateTransaction(accountId1);
TransactionBody transactionBody = getTransactionBody(transaction);
transactionBody = TransactionBody.newBuilder().mergeFrom(transactionBody).setTransactionID(Utility.getTransactionId(accountId1)).build();
transaction = Transaction.newBuilder().setSignedTransactionBytes(SignedTransaction.newBuilder().setBodyBytes(transactionBody.toByteString()).build().toByteString()).build();
TransactionRecord record = transactionRecordSuccess(transactionBody);
parseRecordItemAndCommit(new RecordItem(transaction, record));
assertThat(transactionRepository.findById(DomainUtils.timestampInNanosMax(record.getConsensusTimestamp()))).get().extracting(com.hedera.mirror.common.domain.transaction.Transaction::getPayerAccountId, com.hedera.mirror.common.domain.transaction.Transaction::getEntityId).containsOnly(EntityId.of(accountId1));
}
use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerCryptoTest method cryptoDeleteSuccessfulTransaction.
@Test
void cryptoDeleteSuccessfulTransaction() {
// first create the account
createAccount();
Entity dbAccountEntityBefore = getEntity(EntityId.of(accountId1));
// now delete
Transaction transaction = cryptoDeleteTransaction();
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord record = transactionRecordSuccess(transactionBody);
parseRecordItemAndCommit(new RecordItem(transaction, record));
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), () -> assertCryptoTransaction(transactionBody, record), () -> assertThat(dbAccountEntity).isNotNull().returns(true, Entity::getDeleted).returns(DomainUtils.timestampInNanosMax(record.getConsensusTimestamp()), Entity::getTimestampLower).usingRecursiveComparison().ignoringFields("deleted", "timestampRange").isEqualTo(dbAccountEntityBefore));
}
use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerCryptoTest method cryptoCreateWithZeroInitialBalance.
@Test
void cryptoCreateWithZeroInitialBalance() {
final long initialBalance = 0;
CryptoCreateTransactionBody.Builder cryptoCreateBuilder = cryptoCreateAccountBuilderWithDefaults().setInitialBalance(initialBalance);
Transaction transaction = cryptoCreateTransaction(cryptoCreateBuilder);
TransactionBody transactionBody = getTransactionBody(transaction);
CryptoCreateTransactionBody cryptoCreateTransactionBody = transactionBody.getCryptoCreateAccount();
TransactionRecord record = transactionRecordSuccess(transactionBody);
parseRecordItemAndCommit(new RecordItem(transaction, record));
var accountEntityId = EntityId.of(accountId1);
var consensusTimestamp = DomainUtils.timeStampInNanos(record.getConsensusTimestamp());
var dbTransaction = getDbTransaction(record.getConsensusTimestamp());
Optional<CryptoTransfer> initialBalanceTransfer = cryptoTransferRepository.findById(new CryptoTransfer.Id(initialBalance, consensusTimestamp, accountEntityId.getId()));
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEntities(accountEntityId), () -> assertCryptoTransfers(3), () -> assertCryptoTransaction(transactionBody, record), () -> assertCryptoEntity(cryptoCreateTransactionBody, record.getConsensusTimestamp()), () -> assertEquals(cryptoCreateTransactionBody.getInitialBalance(), dbTransaction.getInitialBalance()), () -> assertThat(initialBalanceTransfer).isEmpty());
}
Aggregations