github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/topic_update_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  const oldTopicMemo = "go-sdk::TestConsensusTopicUpdateTransaction_Execute::initial"
    35  
    36  func TestIntegrationTopicUpdateTransactionCanExecute(t *testing.T) {
    37  	t.Parallel()
    38  	env := NewIntegrationTestEnv(t)
    39  
    40  	resp, err := NewTopicCreateTransaction().
    41  		SetAdminKey(env.Client.GetOperatorPublicKey()).
    42  		SetNodeAccountIDs(env.NodeAccountIDs).
    43  		SetTopicMemo(oldTopicMemo).
    44  		Execute(env.Client)
    45  
    46  	require.NoError(t, err)
    47  
    48  	receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
    49  	require.NoError(t, err)
    50  
    51  	topicID := *receipt.TopicID
    52  	require.NoError(t, err)
    53  
    54  	info, err := NewTopicInfoQuery().
    55  		SetTopicID(topicID).
    56  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
    57  		SetMaxQueryPayment(NewHbar(1)).
    58  		Execute(env.Client)
    59  	require.NoError(t, err)
    60  	assert.NotNil(t, info)
    61  
    62  	assert.Equal(t, oldTopicMemo, info.TopicMemo)
    63  	assert.Equal(t, uint64(0), info.SequenceNumber)
    64  	assert.Equal(t, env.Client.GetOperatorPublicKey().String(), info.AdminKey.String())
    65  
    66  	newTopicMemo := "go-sdk::TestConsensusTopicUpdateTransaction_Execute::updated"
    67  
    68  	resp, err = NewTopicUpdateTransaction().
    69  		SetTopicID(topicID).
    70  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
    71  		SetTopicMemo(newTopicMemo).
    72  		Execute(env.Client)
    73  	require.NoError(t, err)
    74  
    75  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
    76  	require.NoError(t, err)
    77  
    78  	info, err = NewTopicInfoQuery().
    79  		SetTopicID(topicID).
    80  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
    81  		SetMaxQueryPayment(NewHbar(1)).
    82  		Execute(env.Client)
    83  	require.NoError(t, err)
    84  	assert.NotNil(t, info)
    85  
    86  	assert.Equal(t, newTopicMemo, info.TopicMemo)
    87  	assert.Equal(t, uint64(0), info.SequenceNumber)
    88  	assert.Equal(t, env.Client.GetOperatorPublicKey().String(), info.AdminKey.String())
    89  
    90  	resp, err = NewTopicDeleteTransaction().
    91  		SetTopicID(topicID).
    92  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
    93  		Execute(env.Client)
    94  	require.NoError(t, err)
    95  
    96  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
    97  	require.NoError(t, err)
    98  
    99  	err = CloseIntegrationTestEnv(env, nil)
   100  	require.NoError(t, err)
   101  }
   102  
   103  func TestIntegrationTopicUpdateTransactionNoMemo(t *testing.T) {
   104  	t.Parallel()
   105  	env := NewIntegrationTestEnv(t)
   106  
   107  	resp, err := NewTopicCreateTransaction().
   108  		SetAdminKey(env.Client.GetOperatorPublicKey()).
   109  		SetNodeAccountIDs(env.NodeAccountIDs).
   110  		SetTopicMemo(oldTopicMemo).
   111  		Execute(env.Client)
   112  
   113  	require.NoError(t, err)
   114  
   115  	receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
   116  	require.NoError(t, err)
   117  
   118  	topicID := *receipt.TopicID
   119  	require.NoError(t, err)
   120  
   121  	info, err := NewTopicInfoQuery().
   122  		SetTopicID(topicID).
   123  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   124  		SetMaxQueryPayment(NewHbar(1)).
   125  		Execute(env.Client)
   126  	require.NoError(t, err)
   127  	assert.NotNil(t, info)
   128  
   129  	assert.Equal(t, oldTopicMemo, info.TopicMemo)
   130  	assert.Equal(t, uint64(0), info.SequenceNumber)
   131  	assert.Equal(t, env.Client.GetOperatorPublicKey().String(), info.AdminKey.String())
   132  
   133  	resp, err = NewTopicUpdateTransaction().
   134  		SetTopicID(topicID).
   135  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   136  		Execute(env.Client)
   137  	require.NoError(t, err)
   138  
   139  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   140  	require.NoError(t, err)
   141  
   142  	resp, err = NewTopicDeleteTransaction().
   143  		SetTopicID(topicID).
   144  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   145  		Execute(env.Client)
   146  	require.NoError(t, err)
   147  
   148  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   149  	require.NoError(t, err)
   150  
   151  	err = CloseIntegrationTestEnv(env, nil)
   152  	require.NoError(t, err)
   153  }
   154  
   155  func TestIntegrationTopicUpdateTransactionNoTopicID(t *testing.T) {
   156  	t.Parallel()
   157  	env := NewIntegrationTestEnv(t)
   158  
   159  	resp, err := NewTopicCreateTransaction().
   160  		SetAdminKey(env.Client.GetOperatorPublicKey()).
   161  		SetNodeAccountIDs(env.NodeAccountIDs).
   162  		SetTopicMemo(oldTopicMemo).
   163  		Execute(env.Client)
   164  	require.NoError(t, err)
   165  
   166  	receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
   167  	require.NoError(t, err)
   168  
   169  	topicID := *receipt.TopicID
   170  	require.NoError(t, err)
   171  
   172  	info, err := NewTopicInfoQuery().
   173  		SetTopicID(topicID).
   174  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   175  		SetMaxQueryPayment(NewHbar(1)).
   176  		Execute(env.Client)
   177  	require.NoError(t, err)
   178  	assert.NotNil(t, info)
   179  
   180  	assert.Equal(t, oldTopicMemo, info.TopicMemo)
   181  	assert.Equal(t, uint64(0), info.SequenceNumber)
   182  	assert.Equal(t, env.Client.GetOperatorPublicKey().String(), info.AdminKey.String())
   183  
   184  	_, err = NewTopicUpdateTransaction().
   185  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   186  		Execute(env.Client)
   187  	require.Error(t, err)
   188  	if err != nil {
   189  		assert.ErrorContains(t, err, "exceptional precheck status INVALID_TOPIC_ID")
   190  	}
   191  
   192  	resp, err = NewTopicDeleteTransaction().
   193  		SetTopicID(topicID).
   194  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   195  		Execute(env.Client)
   196  	require.NoError(t, err)
   197  
   198  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   199  	require.NoError(t, err)
   200  
   201  	err = CloseIntegrationTestEnv(env, nil)
   202  	require.NoError(t, err)
   203  }