github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/topic_create_transaction_e2e_test.go (about) 1 //go:build all || e2e 2 // +build all e2e 3 4 package hedera 5 6 /*- 7 * 8 * Hedera Go SDK 9 * 10 * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC 11 * 12 * Licensed under the Apache License, Version 2.0 (the "License"); 13 * you may not use this file except in compliance with the License. 14 * You may obtain a copy of the License at 15 * 16 * http://www.apache.org/licenses/LICENSE-2.0 17 * 18 * Unless required by applicable law or agreed to in writing, software 19 * distributed under the License is distributed on an "AS IS" BASIS, 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 * See the License for the specific language governing permissions and 22 * limitations under the License. 23 * 24 */ 25 26 import ( 27 "testing" 28 29 "github.com/stretchr/testify/assert" 30 31 "github.com/stretchr/testify/require" 32 ) 33 34 func TestIntegrationTopicCreateTransactionCanExecute(t *testing.T) { 35 t.Parallel() 36 env := NewIntegrationTestEnv(t) 37 38 resp, err := NewTopicCreateTransaction(). 39 SetAdminKey(env.Client.GetOperatorPublicKey()). 40 SetNodeAccountIDs(env.NodeAccountIDs). 41 SetSubmitKey(env.Client.GetOperatorPublicKey()). 42 SetTopicMemo(topicMemo). 43 Execute(env.Client) 44 require.NoError(t, err) 45 46 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 47 require.NoError(t, err) 48 49 topicID := *receipt.TopicID 50 assert.NotNil(t, topicID) 51 52 info, err := NewTopicInfoQuery(). 53 SetTopicID(topicID). 54 SetNodeAccountIDs([]AccountID{resp.NodeID}). 55 SetQueryPayment(NewHbar(1)). 56 Execute(env.Client) 57 require.NoError(t, err) 58 assert.NotNil(t, info) 59 60 assert.Equal(t, topicMemo, info.TopicMemo) 61 assert.Equal(t, uint64(0), info.SequenceNumber) 62 assert.Equal(t, env.Client.GetOperatorPublicKey().String(), info.AdminKey.String()) 63 64 resp, err = NewTopicDeleteTransaction(). 65 SetTopicID(topicID). 66 SetNodeAccountIDs([]AccountID{resp.NodeID}). 67 Execute(env.Client) 68 require.NoError(t, err) 69 70 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 71 require.NoError(t, err) 72 73 err = CloseIntegrationTestEnv(env, nil) 74 require.NoError(t, err) 75 } 76 77 func TestIntegrationTopicCreateTransactionDifferentKeys(t *testing.T) { 78 t.Parallel() 79 env := NewIntegrationTestEnv(t) 80 81 keys := make([]PrivateKey, 2) 82 pubKeys := make([]PublicKey, 2) 83 84 for i := range keys { 85 newKey, err := PrivateKeyGenerateEd25519() 86 require.NoError(t, err) 87 88 keys[i] = newKey 89 pubKeys[i] = newKey.PublicKey() 90 } 91 92 tx, err := NewTopicCreateTransaction(). 93 SetNodeAccountIDs(env.NodeAccountIDs). 94 SetAdminKey(pubKeys[0]). 95 SetSubmitKey(pubKeys[1]). 96 SetTopicMemo(topicMemo). 97 FreezeWith(env.Client) 98 require.NoError(t, err) 99 100 tx, err = tx.SignWithOperator(env.Client) 101 require.NoError(t, err) 102 tx.Sign(keys[0]) 103 resp, err := tx.Execute(env.Client) 104 require.NoError(t, err) 105 106 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 107 require.NoError(t, err) 108 109 topicID := *receipt.TopicID 110 assert.NotNil(t, topicID) 111 112 info, err := NewTopicInfoQuery(). 113 SetTopicID(topicID). 114 SetNodeAccountIDs([]AccountID{resp.NodeID}). 115 SetQueryPayment(NewHbar(1)). 116 Execute(env.Client) 117 require.NoError(t, err) 118 assert.NotNil(t, info) 119 120 assert.Equal(t, topicMemo, info.TopicMemo) 121 assert.Equal(t, uint64(0), info.SequenceNumber) 122 assert.Equal(t, pubKeys[0].String(), info.AdminKey.String()) 123 124 txDelete, err := NewTopicDeleteTransaction(). 125 SetTopicID(topicID). 126 SetNodeAccountIDs([]AccountID{resp.NodeID}). 127 FreezeWith(env.Client) 128 require.NoError(t, err) 129 130 resp, err = txDelete.Sign(keys[0]). 131 Execute(env.Client) 132 require.NoError(t, err) 133 134 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 135 require.NoError(t, err) 136 137 err = CloseIntegrationTestEnv(env, nil) 138 require.NoError(t, err) 139 } 140 141 func TestIntegrationTopicCreateTransactionJustSetMemo(t *testing.T) { 142 t.Parallel() 143 env := NewIntegrationTestEnv(t) 144 145 resp, err := NewTopicCreateTransaction(). 146 SetNodeAccountIDs(env.NodeAccountIDs). 147 SetTopicMemo(topicMemo). 148 Execute(env.Client) 149 require.NoError(t, err) 150 151 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 152 require.NoError(t, err) 153 154 err = CloseIntegrationTestEnv(env, nil) 155 require.NoError(t, err) 156 }