use of com.hedera.hashgraph.sdk.TopicCreateTransaction in project hedera-sdk-java by hashgraph.
the class TopicInfoIntegrationTest method canQueryTopicInfo.
@Test
@DisplayName("Can query topic info")
void canQueryTopicInfo() 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 info = new TopicInfoQuery().setTopicId(topicId).execute(testEnv.client);
assertThat(info.topicMemo).isEqualTo("[e2e::TopicCreateTransaction]");
new TopicDeleteTransaction().setTopicId(topicId).execute(testEnv.client).getReceipt(testEnv.client);
testEnv.close();
}
use of com.hedera.hashgraph.sdk.TopicCreateTransaction 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.TopicCreateTransaction 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.TopicCreateTransaction in project hedera-sdk-java by hashgraph.
the class TopicUpdateIntegrationTest method canUpdateTopic.
@Test
@DisplayName("Can update topic")
void canUpdateTopic() throws Exception {
var testEnv = new IntegrationTestEnv(1);
var response = new TopicCreateTransaction().setAdminKey(testEnv.operatorKey).setAutoRenewAccountId(testEnv.operatorId).setTopicMemo("[e2e::TopicCreateTransaction]").execute(testEnv.client);
var topicId = Objects.requireNonNull(response.getReceipt(testEnv.client).topicId);
new TopicUpdateTransaction().clearAutoRenewAccountId().setTopicMemo("hello").setTopicId(topicId).execute(testEnv.client).getReceipt(testEnv.client);
var topicInfo = new TopicInfoQuery().setTopicId(topicId).execute(testEnv.client);
assertThat(topicInfo.topicMemo).isEqualTo("hello");
assertThat(topicInfo.autoRenewAccountId).isNull();
new TopicDeleteTransaction().setTopicId(topicId).execute(testEnv.client).getReceipt(testEnv.client);
testEnv.close();
}
use of com.hedera.hashgraph.sdk.TopicCreateTransaction in project hedera-sdk-java by hashgraph.
the class ConsensusPubSubWithSubmitKeyExample method createTopicWithSubmitKey.
/**
* Generate a brand new ED25519 key pair.
* <p>
* Create a new topic with that key as the topic's submitKey; required to sign all future
* ConsensusMessageSubmitTransactions for that topic.
*/
private void createTopicWithSubmitKey() throws TimeoutException, PrecheckStatusException, ReceiptStatusException {
// Generate a Ed25519 private, public key pair
submitKey = PrivateKey.generateED25519();
PublicKey submitPublicKey = submitKey.getPublicKey();
TransactionResponse transactionResponse = new TopicCreateTransaction().setTopicMemo("HCS topic with submit key").setSubmitKey(submitPublicKey).execute(client);
topicId = Objects.requireNonNull(transactionResponse.getReceipt(client).topicId);
System.out.println("Created new topic " + topicId + " with ED25519 submitKey of " + submitKey);
}
Aggregations