Search in sources :

Example 1 with TopicDeleteTransaction

use of com.hedera.hashgraph.sdk.TopicDeleteTransaction in project hedera-sdk-java by hashgraph.

the class TopicInfoIntegrationTest method getCostInsufficientTxFeeQueryTopicInfo.

@Test
@DisplayName("Can get cost for topic info query")
void getCostInsufficientTxFeeQueryTopicInfo() 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 infoQuery = new TopicInfoQuery().setTopicId(topicId);
    var cost = infoQuery.getCost(testEnv.client);
    assertThat(cost).isNotNull();
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        infoQuery.setQueryPayment(Hbar.fromTinybars(1)).execute(testEnv.client);
    }).satisfies(error -> assertThat(error.status.toString()).isEqualTo("INSUFFICIENT_TX_FEE"));
    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 2 with TopicDeleteTransaction

use of com.hedera.hashgraph.sdk.TopicDeleteTransaction in project hedera-sdk-java by hashgraph.

the class TopicMessageIntegrationTest method canReceiveATopicMessage.

@Test
@DisplayName("Can receive a topic message")
void canReceiveATopicMessage() 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.topicId).isEqualTo(topicId);
    assertThat(info.topicMemo).isEqualTo("[e2e::TopicCreateTransaction]");
    assertThat(info.sequenceNumber).isEqualTo(0);
    assertThat(info.adminKey).isEqualTo(testEnv.operatorKey);
    Thread.sleep(3000);
    var receivedMessage = new boolean[] { false };
    var start = Instant.now();
    var handle = new TopicMessageQuery().setTopicId(topicId).setStartTime(Instant.EPOCH).subscribe(testEnv.client, (message) -> {
        receivedMessage[0] = new String(message.contents, StandardCharsets.UTF_8).equals("Hello, from HCS!");
    });
    Thread.sleep(3000);
    new TopicMessageSubmitTransaction().setTopicId(topicId).setMessage("Hello, from HCS!").execute(testEnv.client).getReceipt(testEnv.client);
    while (!receivedMessage[0]) {
        if (Duration.between(start, Instant.now()).compareTo(Duration.ofSeconds(60)) > 0) {
            throw new Exception("TopicMessage was not received in 60 seconds or less");
        }
        Thread.sleep(2000);
    }
    handle.unsubscribe();
    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) TopicMessageQuery(com.hedera.hashgraph.sdk.TopicMessageQuery) 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 3 with TopicDeleteTransaction

use of com.hedera.hashgraph.sdk.TopicDeleteTransaction in project hedera-sdk-java by hashgraph.

the class TopicMessageIntegrationTest method canReceiveALargeTopicMessage.

@Test
@DisplayName("Can receive a large topic message")
void canReceiveALargeTopicMessage() throws Exception {
    var testEnv = new IntegrationTestEnv(2);
    var response = new TopicCreateTransaction().setAdminKey(testEnv.operatorKey).setTopicMemo("[e2e::TopicCreateTransaction]").execute(testEnv.client);
    var topicId = Objects.requireNonNull(response.getReceipt(testEnv.client).topicId);
    Thread.sleep(5000);
    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);
    var receivedMessage = new boolean[] { false };
    var start = Instant.now();
    var handle = new TopicMessageQuery().setTopicId(topicId).setStartTime(Instant.EPOCH).subscribe(testEnv.client, (message) -> {
        receivedMessage[0] = new String(message.contents, StandardCharsets.UTF_8).equals(Contents.BIG_CONTENTS);
    });
    new TopicMessageSubmitTransaction().setTopicId(topicId).setMessage(Contents.BIG_CONTENTS).execute(testEnv.client).getReceipt(testEnv.client);
    while (!receivedMessage[0]) {
        if (Duration.between(start, Instant.now()).compareTo(Duration.ofSeconds(60)) > 0) {
            throw new Exception("TopicMessage was not received in 60 seconds or less");
        }
        Thread.sleep(1000);
    }
    handle.unsubscribe();
    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) TopicMessageQuery(com.hedera.hashgraph.sdk.TopicMessageQuery) 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 4 with TopicDeleteTransaction

use of com.hedera.hashgraph.sdk.TopicDeleteTransaction in project hedera-sdk-java by hashgraph.

the class TopicMessageSubmitIntegrationTest method cannotSubmitMessageWhenMessageIsNotSet.

@Test
@DisplayName("Cannot submit message when message is not set")
void cannotSubmitMessageWhenMessageIsNotSet() {
    // 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().setTopicId(topicId).execute(testEnv.client).getReceipt(testEnv.client);
        }).withMessageContaining(Status.INVALID_TOPIC_MESSAGE.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 5 with TopicDeleteTransaction

use of com.hedera.hashgraph.sdk.TopicDeleteTransaction in project hedera-sdk-java by hashgraph.

the class TopicMessageSubmitIntegrationTest method canSubmitALargeTopicMessage.

@Test
@DisplayName("Can submit a large topic message")
void canSubmitALargeTopicMessage() {
    // Skip if using PreviewNet
    Assumptions.assumeTrue(!System.getProperty("HEDERA_NETWORK").equals("previewnet"));
    assertThatNoException().isThrownBy(() -> {
        var testEnv = new IntegrationTestEnv(2);
        var response = new TopicCreateTransaction().setAdminKey(testEnv.operatorKey).setTopicMemo("[e2e::TopicCreateTransaction]").execute(testEnv.client);
        var topicId = Objects.requireNonNull(response.getReceipt(testEnv.client).topicId);
        Thread.sleep(5000);
        @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);
        var responses = new TopicMessageSubmitTransaction().setTopicId(topicId).setMaxChunks(15).setMessage(Contents.BIG_CONTENTS).executeAll(testEnv.client);
        for (var resp : responses) {
            resp.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(14);
        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)

Aggregations

TopicDeleteTransaction (com.hedera.hashgraph.sdk.TopicDeleteTransaction)18 Test (org.junit.jupiter.api.Test)17 TopicCreateTransaction (com.hedera.hashgraph.sdk.TopicCreateTransaction)15 DisplayName (org.junit.jupiter.api.DisplayName)15 TopicInfoQuery (com.hedera.hashgraph.sdk.TopicInfoQuery)10 TopicMessageSubmitTransaction (com.hedera.hashgraph.sdk.TopicMessageSubmitTransaction)6 Var (com.google.errorprone.annotations.Var)2 TopicMessageQuery (com.hedera.hashgraph.sdk.TopicMessageQuery)2 AbstractTransactionSupplierTest (com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)2 Hbar (com.hedera.hashgraph.sdk.Hbar)1 MaxQueryPaymentExceededException (com.hedera.hashgraph.sdk.MaxQueryPaymentExceededException)1 TopicUpdateTransaction (com.hedera.hashgraph.sdk.TopicUpdateTransaction)1 NetworkTransactionResponse (com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse)1