use of com.hedera.hashgraph.sdk.TopicCreateTransaction in project hedera-sdk-java by hashgraph.
the class TopicCreateIntegrationTest method canCreateTopicWithNoFieldsSet.
@Test
@DisplayName("Can create topic with no field set")
void canCreateTopicWithNoFieldsSet() throws Exception {
var testEnv = new IntegrationTestEnv(1);
var response = new TopicCreateTransaction().execute(testEnv.client);
assertThat(response.getReceipt(testEnv.client).topicId).isNotNull();
testEnv.close();
}
use of com.hedera.hashgraph.sdk.TopicCreateTransaction 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();
}
use of com.hedera.hashgraph.sdk.TopicCreateTransaction 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();
}
use of com.hedera.hashgraph.sdk.TopicCreateTransaction 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();
}
use of com.hedera.hashgraph.sdk.TopicCreateTransaction 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();
});
}
Aggregations