github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/topic_delete_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 TestIntegrationTopicDeleteTransactionCanExecute(t *testing.T) {
    35  	t.Parallel()
    36  	env := NewIntegrationTestEnv(t)
    37  
    38  	topicMemo := "go-sdk::TestConsensusTopicDeleteTransaction_Execute"
    39  
    40  	resp, err := NewTopicCreateTransaction().
    41  		SetAdminKey(env.Client.GetOperatorPublicKey()).
    42  		SetNodeAccountIDs(env.NodeAccountIDs).
    43  		SetTopicMemo(topicMemo).
    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  	assert.NotNil(t, topicID)
    53  
    54  	_, err = NewTopicInfoQuery().
    55  		SetTopicID(topicID).
    56  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
    57  		SetQueryPayment(NewHbar(1)).
    58  		Execute(env.Client)
    59  	require.NoError(t, err)
    60  
    61  	resp, err = NewTopicDeleteTransaction().
    62  		SetTopicID(topicID).
    63  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
    64  		Execute(env.Client)
    65  	require.NoError(t, err)
    66  
    67  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
    68  	require.NoError(t, err)
    69  
    70  	_, err = NewTopicInfoQuery().
    71  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
    72  		SetTopicID(topicID).
    73  		SetQueryPayment(NewHbar(1)).
    74  		Execute(env.Client)
    75  	assert.Error(t, err)
    76  	if err != nil {
    77  		assert.Equal(t, "exceptional precheck status INVALID_TOPIC_ID", err.Error())
    78  	}
    79  
    80  	err = CloseIntegrationTestEnv(env, nil)
    81  	require.NoError(t, err)
    82  }
    83  
    84  func TestIntegrationTopicDeleteTransactionNoTopicID(t *testing.T) {
    85  	t.Parallel()
    86  	env := NewIntegrationTestEnv(t)
    87  
    88  	topicMemo := "go-sdk::TestConsensusTopicDeleteTransaction_Execute"
    89  
    90  	resp, err := NewTopicCreateTransaction().
    91  		SetAdminKey(env.Client.GetOperatorPublicKey()).
    92  		SetNodeAccountIDs(env.NodeAccountIDs).
    93  		SetTopicMemo(topicMemo).
    94  		Execute(env.Client)
    95  
    96  	require.NoError(t, err)
    97  
    98  	receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
    99  	require.NoError(t, err)
   100  
   101  	topicID := *receipt.TopicID
   102  	assert.NotNil(t, topicID)
   103  
   104  	_, err = NewTopicInfoQuery().
   105  		SetTopicID(topicID).
   106  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   107  		SetQueryPayment(NewHbar(1)).
   108  		Execute(env.Client)
   109  	require.NoError(t, err)
   110  
   111  	resp, err = NewTopicDeleteTransaction().
   112  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   113  		Execute(env.Client)
   114  	require.Error(t, err)
   115  	if err != nil {
   116  		assert.ErrorContains(t, err, "exceptional precheck status INVALID_TOPIC_ID")
   117  	}
   118  
   119  	err = CloseIntegrationTestEnv(env, nil)
   120  	require.NoError(t, err)
   121  }