use of com.hedera.hashgraph.sdk.TopicMessageSubmitTransaction in project hedera-mirror-node by hashgraph.
the class ConsensusSubmitMessageTransactionSupplierTest method createWithMinimumData.
@Test
void createWithMinimumData() {
ConsensusSubmitMessageTransactionSupplier consensusSubmitMessageTransactionSupplier = new ConsensusSubmitMessageTransactionSupplier();
consensusSubmitMessageTransactionSupplier.setTopicId(TOPIC_ID.toString());
TopicMessageSubmitTransaction actual = consensusSubmitMessageTransactionSupplier.get();
assertThat(actual).returns(MAX_TRANSACTION_FEE_HBAR, TopicMessageSubmitTransaction::getMaxTransactionFee).returns(TOPIC_ID, TopicMessageSubmitTransaction::getTopicId).extracting(a -> a.getMessage().toStringUtf8(), STRING).hasSize(256);
}
use of com.hedera.hashgraph.sdk.TopicMessageSubmitTransaction in project hedera-mirror-node by hashgraph.
the class ConsensusSubmitMessageTransactionSupplierTest method createWithCustomMessage.
@Test
void createWithCustomMessage() {
String message = "ConsensusSubmitMessageTransactionSupplierTest.createWithCustomData";
ConsensusSubmitMessageTransactionSupplier consensusSubmitMessageTransactionSupplier = new ConsensusSubmitMessageTransactionSupplier();
consensusSubmitMessageTransactionSupplier.setMaxTransactionFee(1);
consensusSubmitMessageTransactionSupplier.setMessage(message);
consensusSubmitMessageTransactionSupplier.setTopicId(TOPIC_ID.toString());
TopicMessageSubmitTransaction actual = consensusSubmitMessageTransactionSupplier.get();
assertThat(actual).returns(ByteString.copyFromUtf8(message), TopicMessageSubmitTransaction::getMessage).returns(ONE_TINYBAR, TopicMessageSubmitTransaction::getMaxTransactionFee).returns(TOPIC_ID, TopicMessageSubmitTransaction::getTopicId);
}
use of com.hedera.hashgraph.sdk.TopicMessageSubmitTransaction in project hedera-sdk-java by hashgraph.
the class TopicMessageSubmitIntegrationTest method cannotSubmitMessageWhenTopicIDIsNotSet.
@Test
@DisplayName("Cannot submit message when topic ID is not set")
void cannotSubmitMessageWhenTopicIDIsNotSet() {
// Skip if using PreviewNet
Assumptions.assumeTrue(!System.getProperty("HEDERA_NETWORK").equals("previewnet"));
assertThatNoException().isThrownBy(() -> {
var testEnv = new IntegrationTestEnv(1);
var response = new TopicCreateTransaction().setAdminKey(testEnv.operatorKey).setTopicMemo("[e2e::TopicCreateTransaction]").execute(testEnv.client);
var topicId = Objects.requireNonNull(response.getReceipt(testEnv.client).topicId);
assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
new TopicMessageSubmitTransaction().setMessage(Contents.BIG_CONTENTS).setMaxChunks(15).execute(testEnv.client).getReceipt(testEnv.client);
}).withMessageContaining(Status.INVALID_TOPIC_ID.toString());
new TopicDeleteTransaction().setTopicId(topicId).execute(testEnv.client).getReceipt(testEnv.client);
testEnv.close();
});
}
use of com.hedera.hashgraph.sdk.TopicMessageSubmitTransaction in project hedera-sdk-java by hashgraph.
the class TopicMessageSubmitIntegrationTest method canSubmitATopicMessage.
@Test
@DisplayName("Can submit a topic message")
void canSubmitATopicMessage() throws Exception {
var testEnv = new IntegrationTestEnv(1);
var response = new TopicCreateTransaction().setAdminKey(testEnv.operatorKey).setTopicMemo("[e2e::TopicCreateTransaction]").execute(testEnv.client);
var topicId = Objects.requireNonNull(response.getReceipt(testEnv.client).topicId);
@Var var info = new TopicInfoQuery().setTopicId(topicId).execute(testEnv.client);
assertThat(info.topicId).isEqualTo(topicId);
assertThat(info.topicMemo).isEqualTo("[e2e::TopicCreateTransaction]");
assertThat(info.sequenceNumber).isEqualTo(0);
assertThat(info.adminKey).isEqualTo(testEnv.operatorKey);
new TopicMessageSubmitTransaction().setTopicId(topicId).setMessage("Hello, from HCS!").execute(testEnv.client).getReceipt(testEnv.client);
info = new TopicInfoQuery().setTopicId(topicId).execute(testEnv.client);
assertThat(info.topicId).isEqualTo(topicId);
assertThat(info.topicMemo).isEqualTo("[e2e::TopicCreateTransaction]");
assertThat(info.sequenceNumber).isEqualTo(1);
assertThat(info.adminKey).isEqualTo(testEnv.operatorKey);
new TopicDeleteTransaction().setTopicId(topicId).execute(testEnv.client).getReceipt(testEnv.client);
testEnv.close();
}
use of com.hedera.hashgraph.sdk.TopicMessageSubmitTransaction in project hedera-sdk-java by hashgraph.
the class CreateTopicExample method main.
public static void main(String[] args) throws TimeoutException, PrecheckStatusException, ReceiptStatusException {
Client client = Client.forName(HEDERA_NETWORK);
// Defaults the operator account ID and key such that all generated transactions will be paid for
// by this account and be signed by this key
client.setOperator(OPERATOR_ID, OPERATOR_KEY);
// Create three accounts, Alice, Bob, and Charlie. Alice will be the treasury for our example token.
// Fees only apply in transactions not involving the treasury, so we need two other accounts.
TransactionResponse createResponse = new TopicCreateTransaction().execute(client);
TransactionReceipt createReceipt = createResponse.getReceipt(client);
System.out.println("topic id = " + createReceipt.topicId);
TransactionResponse sendResponse = new TopicMessageSubmitTransaction().setTopicId(createReceipt.topicId).setMessage("Hello World").execute(client);
TransactionReceipt sendReceipt = sendResponse.getReceipt(client);
System.out.println("topic sequence number = " + sendReceipt.topicSequenceNumber);
}
Aggregations