Search in sources :

Example 11 with TopicMessageSubmitTransaction

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);
}
Also used : ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TopicMessageSubmitTransaction(com.hedera.hashgraph.sdk.TopicMessageSubmitTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) STRING(org.assertj.core.api.InstanceOfAssertFactories.STRING) AbstractTransactionSupplierTest(com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest) TopicMessageSubmitTransaction(com.hedera.hashgraph.sdk.TopicMessageSubmitTransaction) Test(org.junit.jupiter.api.Test) AbstractTransactionSupplierTest(com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)

Example 12 with TopicMessageSubmitTransaction

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);
}
Also used : ByteString(com.google.protobuf.ByteString) TopicMessageSubmitTransaction(com.hedera.hashgraph.sdk.TopicMessageSubmitTransaction) Test(org.junit.jupiter.api.Test) AbstractTransactionSupplierTest(com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)

Example 13 with TopicMessageSubmitTransaction

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();
    });
}
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 14 with TopicMessageSubmitTransaction

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();
}
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 15 with TopicMessageSubmitTransaction

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

Aggregations

TopicMessageSubmitTransaction (com.hedera.hashgraph.sdk.TopicMessageSubmitTransaction)15 TopicCreateTransaction (com.hedera.hashgraph.sdk.TopicCreateTransaction)10 Test (org.junit.jupiter.api.Test)10 DisplayName (org.junit.jupiter.api.DisplayName)7 TopicDeleteTransaction (com.hedera.hashgraph.sdk.TopicDeleteTransaction)6 Var (com.google.errorprone.annotations.Var)4 TopicInfoQuery (com.hedera.hashgraph.sdk.TopicInfoQuery)4 TopicMessageQuery (com.hedera.hashgraph.sdk.TopicMessageQuery)4 ByteString (com.google.protobuf.ByteString)3 Client (com.hedera.hashgraph.sdk.Client)3 Hbar (com.hedera.hashgraph.sdk.Hbar)3 AbstractTransactionSupplierTest (com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)3 TopicId (com.hedera.hashgraph.sdk.TopicId)2 TransactionReceipt (com.hedera.hashgraph.sdk.TransactionReceipt)2 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 STRING (org.assertj.core.api.InstanceOfAssertFactories.STRING)2 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)1 KeyList (com.hedera.hashgraph.sdk.KeyList)1 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)1