Search in sources :

Example 31 with RecordItem

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());
}
Also used : 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) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem)

Example 32 with RecordItem

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()));
}
Also used : RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) CsvSource(org.junit.jupiter.params.provider.CsvSource) DisplayName(org.junit.jupiter.api.DisplayName) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 33 with RecordItem

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));
}
Also used : 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 34 with RecordItem

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));
}
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 35 with RecordItem

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());
}
Also used : 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) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) CryptoTransfer(com.hedera.mirror.common.domain.transaction.CryptoTransfer) 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)

Aggregations

RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)182 Test (org.junit.jupiter.api.Test)131 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)131 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)108 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)95 Transaction (com.hederahashgraph.api.proto.java.Transaction)94 EntityId (com.hedera.mirror.common.domain.entity.EntityId)42 DomainUtils (com.hedera.mirror.common.util.DomainUtils)36 SignedTransaction (com.hederahashgraph.api.proto.java.SignedTransaction)36 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)36 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)34 EnumSource (org.junit.jupiter.params.provider.EnumSource)34 Entity (com.hedera.mirror.common.domain.entity.Entity)31 CryptoUpdateTransactionBody (com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)31 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)29 CryptoCreateTransactionBody (com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody)29 AccountID (com.hederahashgraph.api.proto.java.AccountID)28 CryptoAddLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody)28 CryptoDeleteLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody)28 FileAppendTransactionBody (com.hederahashgraph.api.proto.java.FileAppendTransactionBody)28