github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/contract_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  	"fmt"
    28  
    29  	"github.com/stretchr/testify/assert"
    30  
    31  	"github.com/stretchr/testify/require"
    32  
    33  	"testing"
    34  )
    35  
    36  func TestIntegrationContractDeleteTransactionCanExecute(t *testing.T) {
    37  	// Note: this is the bytecode for the contract found in the example for ./examples/_Create_simpleContract
    38  	testContractByteCode := []byte(`608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506101cb806100606000396000f3fe608060405260043610610046576000357c01000000000000000000000000000000000000000000000000000000009004806341c0e1b51461004b578063cfae321714610062575b600080fd5b34801561005757600080fd5b506100606100f2565b005b34801561006e57600080fd5b50610077610162565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100b757808201518184015260208101905061009c565b50505050905090810190601f1680156100e45780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610160573373ffffffffffffffffffffffffffffffffffffffff16ff5b565b60606040805190810160405280600d81526020017f48656c6c6f2c20776f726c64210000000000000000000000000000000000000081525090509056fea165627a7a72305820ae96fb3af7cde9c0abfe365272441894ab717f816f07f41f07b1cbede54e256e0029`)
    39  
    40  	t.Parallel()
    41  	env := NewIntegrationTestEnv(t)
    42  
    43  	resp, err := NewFileCreateTransaction().
    44  		SetKeys(env.Client.GetOperatorPublicKey()).
    45  		SetNodeAccountIDs(env.NodeAccountIDs).
    46  		SetContents(testContractByteCode).
    47  		Execute(env.Client)
    48  
    49  	require.NoError(t, err)
    50  
    51  	receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
    52  	require.NoError(t, err)
    53  
    54  	fileID := *receipt.FileID
    55  	assert.NotNil(t, fileID)
    56  
    57  	resp, err = NewContractCreateTransaction().
    58  		SetAdminKey(env.Client.GetOperatorPublicKey()).
    59  		SetGas(100000).
    60  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
    61  		SetConstructorParameters(NewContractFunctionParameters().AddString("hello from hedera")).
    62  		SetBytecodeFileID(fileID).
    63  		SetContractMemo("hedera-sdk-go::TestContractDeleteTransaction_Execute").
    64  		Execute(env.Client)
    65  	require.NoError(t, err)
    66  
    67  	receipt, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
    68  	require.NoError(t, err)
    69  
    70  	assert.NotNil(t, receipt.ContractID)
    71  	contractID := *receipt.ContractID
    72  
    73  	resp, err = NewContractDeleteTransaction().
    74  		SetContractID(contractID).
    75  		SetTransferAccountID(env.Client.GetOperatorAccountID()).
    76  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
    77  		Execute(env.Client)
    78  	require.NoError(t, err)
    79  
    80  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
    81  	require.NoError(t, err)
    82  
    83  	resp, err = NewFileDeleteTransaction().
    84  		SetFileID(fileID).
    85  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
    86  		Execute(env.Client)
    87  	require.NoError(t, err)
    88  
    89  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
    90  	require.NoError(t, err)
    91  
    92  	err = CloseIntegrationTestEnv(env, nil)
    93  	require.NoError(t, err)
    94  }
    95  
    96  func TestIntegrationContractDeleteTransactionNoContractID(t *testing.T) {
    97  	// Note: this is the bytecode for the contract found in the example for ./examples/_Create_simpleContract
    98  	testContractByteCode := []byte(`608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506101cb806100606000396000f3fe608060405260043610610046576000357c01000000000000000000000000000000000000000000000000000000009004806341c0e1b51461004b578063cfae321714610062575b600080fd5b34801561005757600080fd5b506100606100f2565b005b34801561006e57600080fd5b50610077610162565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100b757808201518184015260208101905061009c565b50505050905090810190601f1680156100e45780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610160573373ffffffffffffffffffffffffffffffffffffffff16ff5b565b60606040805190810160405280600d81526020017f48656c6c6f2c20776f726c64210000000000000000000000000000000000000081525090509056fea165627a7a72305820ae96fb3af7cde9c0abfe365272441894ab717f816f07f41f07b1cbede54e256e0029`)
    99  
   100  	t.Parallel()
   101  	env := NewIntegrationTestEnv(t)
   102  
   103  	resp, err := NewFileCreateTransaction().
   104  		SetKeys(env.Client.GetOperatorPublicKey()).
   105  		SetNodeAccountIDs(env.NodeAccountIDs).
   106  		SetContents(testContractByteCode).
   107  		Execute(env.Client)
   108  
   109  	require.NoError(t, err)
   110  
   111  	receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
   112  	require.NoError(t, err)
   113  
   114  	fileID := *receipt.FileID
   115  	assert.NotNil(t, fileID)
   116  
   117  	resp, err = NewContractCreateTransaction().
   118  		SetAdminKey(env.Client.GetOperatorPublicKey()).
   119  		SetGas(100000).
   120  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   121  		SetConstructorParameters(NewContractFunctionParameters().AddString("hello from hedera")).
   122  		SetBytecodeFileID(fileID).
   123  		SetContractMemo("hedera-sdk-go::TestContractDeleteTransaction_Execute").
   124  		Execute(env.Client)
   125  	require.NoError(t, err)
   126  
   127  	receipt, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   128  	require.NoError(t, err)
   129  
   130  	resp2, err := NewContractDeleteTransaction().
   131  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   132  		Execute(env.Client)
   133  	assert.Error(t, err)
   134  	if err != nil {
   135  		assert.Equal(t, fmt.Sprintf("exceptional precheck status INVALID_CONTRACT_ID received for transaction %s", resp2.TransactionID), err.Error())
   136  	}
   137  
   138  	resp, err = NewFileDeleteTransaction().
   139  		SetFileID(fileID).
   140  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   141  		Execute(env.Client)
   142  	require.NoError(t, err)
   143  
   144  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   145  	require.NoError(t, err)
   146  
   147  	err = CloseIntegrationTestEnv(env, nil)
   148  	require.NoError(t, err)
   149  }