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