Search in sources :

Example 21 with TopicCreateTransaction

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();
}
Also used : TopicCreateTransaction(com.hedera.hashgraph.sdk.TopicCreateTransaction) TopicInfoQuery(com.hedera.hashgraph.sdk.TopicInfoQuery) TopicDeleteTransaction(com.hedera.hashgraph.sdk.TopicDeleteTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 22 with TopicCreateTransaction

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();
    });
}
Also used : TopicCreateTransaction(com.hedera.hashgraph.sdk.TopicCreateTransaction) TopicMessageSubmitTransaction(com.hedera.hashgraph.sdk.TopicMessageSubmitTransaction) TopicDeleteTransaction(com.hedera.hashgraph.sdk.TopicDeleteTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 23 with TopicCreateTransaction

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();
}
Also used : TopicCreateTransaction(com.hedera.hashgraph.sdk.TopicCreateTransaction) TopicInfoQuery(com.hedera.hashgraph.sdk.TopicInfoQuery) Var(com.google.errorprone.annotations.Var) TopicMessageSubmitTransaction(com.hedera.hashgraph.sdk.TopicMessageSubmitTransaction) TopicDeleteTransaction(com.hedera.hashgraph.sdk.TopicDeleteTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 24 with TopicCreateTransaction

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();
}
Also used : TopicCreateTransaction(com.hedera.hashgraph.sdk.TopicCreateTransaction) TopicUpdateTransaction(com.hedera.hashgraph.sdk.TopicUpdateTransaction) TopicInfoQuery(com.hedera.hashgraph.sdk.TopicInfoQuery) TopicDeleteTransaction(com.hedera.hashgraph.sdk.TopicDeleteTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 25 with TopicCreateTransaction

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);
}
Also used : TopicCreateTransaction(com.hedera.hashgraph.sdk.TopicCreateTransaction) TransactionResponse(com.hedera.hashgraph.sdk.TransactionResponse) PublicKey(com.hedera.hashgraph.sdk.PublicKey)

Aggregations

TopicCreateTransaction (com.hedera.hashgraph.sdk.TopicCreateTransaction)26 Test (org.junit.jupiter.api.Test)19 DisplayName (org.junit.jupiter.api.DisplayName)17 TopicDeleteTransaction (com.hedera.hashgraph.sdk.TopicDeleteTransaction)15 TopicInfoQuery (com.hedera.hashgraph.sdk.TopicInfoQuery)10 TopicMessageSubmitTransaction (com.hedera.hashgraph.sdk.TopicMessageSubmitTransaction)10 Var (com.google.errorprone.annotations.Var)4 TopicMessageQuery (com.hedera.hashgraph.sdk.TopicMessageQuery)4 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)4 Client (com.hedera.hashgraph.sdk.Client)3 PublicKey (com.hedera.hashgraph.sdk.PublicKey)3 TopicId (com.hedera.hashgraph.sdk.TopicId)3 Hbar (com.hedera.hashgraph.sdk.Hbar)2 KeyList (com.hedera.hashgraph.sdk.KeyList)2 TransactionReceipt (com.hedera.hashgraph.sdk.TransactionReceipt)2 AbstractTransactionSupplierTest (com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)2 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)1 MaxQueryPaymentExceededException (com.hedera.hashgraph.sdk.MaxQueryPaymentExceededException)1 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)1 ScheduleInfoQuery (com.hedera.hashgraph.sdk.ScheduleInfoQuery)1