Search in sources :

Example 11 with TransactionID

use of com.hederahashgraph.api.proto.java.TransactionID in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerTopicTest method submitMessageDisabled.

@Test
void submitMessageDisabled() {
    // given
    entityProperties.getPersist().setTopics(false);
    var responseCode = SUCCESS;
    var topicId = TOPIC_ID;
    var consensusTimestamp = 10_000_000L;
    var message = "message";
    var sequenceNumber = 10_000L;
    var runningHash = "running-hash";
    var runningHashVersion = 1;
    var chunkNum = 3;
    var chunkTotal = 5;
    var validStartNs = 7L;
    var scheduled = false;
    var nonce = 0;
    TransactionID initialTransactionId = createTransactionID(PAYER_ACCOUNT_ID.getEntityNum(), TestUtils.toTimestamp(validStartNs), scheduled, nonce);
    var transaction = createSubmitMessageTransaction(topicId, message, chunkNum, chunkTotal, initialTransactionId);
    var transactionRecord = createTransactionRecord(topicId, sequenceNumber, runningHash.getBytes(), runningHashVersion, consensusTimestamp, responseCode);
    // when
    parseRecordItemAndCommit(new RecordItem(transaction, transactionRecord));
    // then
    assertEquals(0L, entityRepository.count());
    assertEquals(0L, topicMessageRepository.count());
    assertTransactionInRepository(responseCode, consensusTimestamp, TOPIC_ID.getTopicNum());
    entityProperties.getPersist().setTopics(true);
}
Also used : RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with TransactionID

use of com.hederahashgraph.api.proto.java.TransactionID in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerTopicTest method submitMessageTestTopicNotFound.

@Test
void submitMessageTestTopicNotFound() {
    var responseCode = SUCCESS;
    var consensusTimestamp = 10_000_000L;
    var message = "message";
    var sequenceNumber = 10_000L;
    var runningHash = "running-hash";
    var runningHashVersion = 2;
    var chunkNum = 3;
    var chunkTotal = 5;
    var validStartNs = 7L;
    var scheduled = false;
    var nonce = 0;
    TransactionID initialTransactionId = createTransactionID(PAYER_ACCOUNT_ID.getEntityNum(), TestUtils.toTimestamp(validStartNs), scheduled, nonce);
    var topicMessage = createTopicMessage(TOPIC_ID, message, sequenceNumber, runningHash, consensusTimestamp, runningHashVersion, chunkNum, chunkTotal, PAYER_ACCOUNT_ID, initialTransactionId);
    var transaction = createSubmitMessageTransaction(TOPIC_ID, message, chunkNum, chunkTotal, initialTransactionId);
    var transactionRecord = createTransactionRecord(TOPIC_ID, sequenceNumber, runningHash.getBytes(), runningHashVersion, consensusTimestamp, responseCode);
    parseRecordItemAndCommit(new RecordItem(transaction, transactionRecord));
    assertTransactionInRepository(responseCode, consensusTimestamp, TOPIC_ID.getTopicNum());
    assertEquals(0L, entityRepository.count());
    assertEquals(1L, topicMessageRepository.count());
    assertThat(topicMessageRepository.findById(consensusTimestamp)).get().isEqualTo(topicMessage);
}
Also used : RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with TransactionID

use of com.hederahashgraph.api.proto.java.TransactionID in project hedera-mirror-node by hashgraph.

the class UtilityTest method getTransactionID.

@Test
@DisplayName("get TransactionId")
void getTransactionID() {
    AccountID payerAccountId = AccountID.newBuilder().setShardNum(0).setRealmNum(0).setAccountNum(2).build();
    TransactionID transactionId = Utility.getTransactionId(payerAccountId);
    assertThat(transactionId).isNotEqualTo(TransactionID.getDefaultInstance());
    AccountID testAccountId = transactionId.getAccountID();
    assertAll(// row counts
    () -> assertEquals(payerAccountId.getShardNum(), testAccountId.getShardNum()), () -> assertEquals(payerAccountId.getRealmNum(), testAccountId.getRealmNum()), () -> assertEquals(payerAccountId.getAccountNum(), testAccountId.getAccountNum()));
}
Also used : AccountID(com.hederahashgraph.api.proto.java.AccountID) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 14 with TransactionID

use of com.hederahashgraph.api.proto.java.TransactionID in project hedera-mirror-node by hashgraph.

the class TopicMessageTest method toJson.

// Test serialization to JSON to verify contract with PostgreSQL listen/notify
@Test
void toJson() throws Exception {
    TopicMessage topicMessage = new TopicMessage();
    topicMessage.setChunkNum(1);
    topicMessage.setChunkTotal(2);
    topicMessage.setConsensusTimestamp(1594401417000000000L);
    topicMessage.setMessage(new byte[] { 1, 2, 3 });
    topicMessage.setPayerAccountId(EntityId.of("0.1.1000", EntityType.ACCOUNT));
    topicMessage.setRunningHash(new byte[] { 4, 5, 6 });
    topicMessage.setRunningHashVersion(2);
    topicMessage.setSequenceNumber(1L);
    topicMessage.setTopicId(EntityId.of("0.0.1001", EntityType.TOPIC));
    topicMessage.setValidStartTimestamp(1594401416000000000L);
    TransactionID transactionID = TransactionID.newBuilder().setAccountID(AccountID.newBuilder().setShardNum(0).setRealmNum(0).setAccountNum(10)).setTransactionValidStart(Timestamp.newBuilder().setSeconds(20).setNanos(20)).setNonce(1).setScheduled(true).build();
    topicMessage.setInitialTransactionId(transactionID.toByteArray());
    ObjectMapper objectMapper = new ObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
    String json = objectMapper.writeValueAsString(topicMessage);
    assertThat(json).isEqualTo("{" + "\"@type\":\"TopicMessage\"," + "\"chunk_num\":1," + "\"chunk_total\":2," + "\"consensus_timestamp\":1594401417000000000," + "\"initial_transaction_id\":\"CgQIFBAUEgIYChgBIAE=\"," + "\"message\":\"AQID\"," + "\"payer_account_id\":4294968296," + "\"running_hash\":\"BAUG\"," + "\"running_hash_version\":2," + "\"sequence_number\":1," + "\"topic_id\":1001," + "\"valid_start_timestamp\":1594401416000000000}");
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) Test(org.junit.jupiter.api.Test)

Example 15 with TransactionID

use of com.hederahashgraph.api.proto.java.TransactionID in project hedera-mirror-node by hashgraph.

the class TopicMessage method toResponse.

private ConsensusTopicResponse toResponse() {
    var consensusTopicResponseBuilder = ConsensusTopicResponse.newBuilder().setConsensusTimestamp(ProtoUtil.toTimestamp(getConsensusTimestampInstant())).setMessage(ProtoUtil.toByteString(message)).setRunningHash(ProtoUtil.toByteString(runningHash)).setRunningHashVersion(runningHashVersion).setSequenceNumber(sequenceNumber);
    if (getChunkNum() != null) {
        ConsensusMessageChunkInfo.Builder chunkBuilder = ConsensusMessageChunkInfo.newBuilder().setNumber(getChunkNum()).setTotal(getChunkTotal());
        TransactionID transactionID = parseTransactionID(initialTransactionId);
        EntityId payerAccountEntity = EntityId.of(payerAccountId, EntityType.ACCOUNT);
        Instant validStartInstant = LongToInstantConverter.INSTANCE.convert(validStartTimestamp);
        if (transactionID != null) {
            chunkBuilder.setInitialTransactionID(transactionID);
        } else if (payerAccountEntity != null && validStartInstant != null) {
            chunkBuilder.setInitialTransactionID(TransactionID.newBuilder().setAccountID(ProtoUtil.toAccountID(payerAccountEntity)).setTransactionValidStart(ProtoUtil.toTimestamp(validStartInstant)).build());
        }
        consensusTopicResponseBuilder.setChunkInfo(chunkBuilder.build());
    }
    return consensusTopicResponseBuilder.build();
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) ConsensusMessageChunkInfo(com.hederahashgraph.api.proto.java.ConsensusMessageChunkInfo) Instant(java.time.Instant) TransactionID(com.hederahashgraph.api.proto.java.TransactionID)

Aggregations

TransactionID (com.hederahashgraph.api.proto.java.TransactionID)21 Test (org.junit.jupiter.api.Test)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)7 Instant (java.time.Instant)5 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)4 ByteString (com.google.protobuf.ByteString)3 HapiSpecSetup (com.hedera.services.bdd.spec.HapiSpecSetup)3 AccountID (com.hederahashgraph.api.proto.java.AccountID)3 List (java.util.List)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)2 HapiApiSpec.defaultHapiSpec (com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec)2 TransactionRecordAsserts.recordWith (com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith)2 QueryVerbs.getAccountBalance (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance)2 QueryVerbs.getAccountInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo)2 QueryVerbs.getScheduleInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getScheduleInfo)2 QueryVerbs.getTokenInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getTokenInfo)2 QueryVerbs.getTopicInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getTopicInfo)2 QueryVerbs.getTxnRecord (com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord)2