github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/contract_bytecode_query_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 TestIntegrationContractBytecodeQueryCanExecute(t *testing.T) {
    35  	t.Parallel()
    36  	env := NewIntegrationTestEnv(t)
    37  
    38  	smartContractBytecode := []byte("608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033")
    39  
    40  	resp, err := NewFileCreateTransaction().
    41  		SetKeys(env.OperatorKey).
    42  		SetNodeAccountIDs(env.NodeAccountIDs).
    43  		SetContents(smartContractBytecode).
    44  		Execute(env.Client)
    45  	require.NoError(t, err)
    46  
    47  	receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
    48  	require.NoError(t, err)
    49  
    50  	assert.NotNil(t, receipt.FileID)
    51  	fileID := *receipt.FileID
    52  
    53  	contractResponse, err := NewContractCreateTransaction().
    54  		SetAdminKey(env.OperatorKey).
    55  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
    56  		SetGas(200000).
    57  		SetConstructorParameters(NewContractFunctionParameters().AddString("Hello from Hedera.")).
    58  		SetBytecodeFileID(fileID).
    59  		SetContractMemo("[e2e::ContractCreateTransaction]").
    60  		Execute(env.Client)
    61  	require.NoError(t, err)
    62  
    63  	contractReceipt, err := contractResponse.SetValidateStatus(true).GetReceipt(env.Client)
    64  	require.NoError(t, err)
    65  
    66  	assert.NotNil(t, contractReceipt.ContractID)
    67  
    68  	assert.True(t, contractReceipt.ContractID.Contract > 0)
    69  
    70  	contractID := *contractReceipt.ContractID
    71  
    72  	bytecode, err := NewContractBytecodeQuery().
    73  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
    74  		SetContractID(contractID).
    75  		SetMaxQueryPayment(NewHbar(2)).
    76  		SetQueryPayment(NewHbar(1)).
    77  		Execute(env.Client)
    78  	require.NoError(t, err)
    79  
    80  	assert.Equal(t, len(bytecode), 798)
    81  
    82  	resp, err = NewContractDeleteTransaction().
    83  		SetContractID(contractID).
    84  		SetTransferAccountID(env.Client.GetOperatorAccountID()).
    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  	resp, err = NewFileDeleteTransaction().
    93  		SetFileID(fileID).
    94  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
    95  		Execute(env.Client)
    96  	require.NoError(t, err)
    97  
    98  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
    99  	require.NoError(t, err)
   100  
   101  	err = CloseIntegrationTestEnv(env, nil)
   102  	require.NoError(t, err)
   103  }
   104  
   105  func TestIntegrationContractBytecodeQueryGetCostExecute(t *testing.T) {
   106  	t.Parallel()
   107  	env := NewIntegrationTestEnv(t)
   108  
   109  	smartContractBytecode := []byte("608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033")
   110  
   111  	resp, err := NewFileCreateTransaction().
   112  		SetKeys(env.OperatorKey).
   113  		SetContents(smartContractBytecode).
   114  		SetNodeAccountIDs(env.NodeAccountIDs).
   115  		Execute(env.Client)
   116  	require.NoError(t, err)
   117  
   118  	receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
   119  	require.NoError(t, err)
   120  
   121  	assert.NotNil(t, receipt.FileID)
   122  	fileID := *receipt.FileID
   123  
   124  	contractResponse, err := NewContractCreateTransaction().
   125  		SetAdminKey(env.OperatorKey).
   126  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   127  		SetGas(200000).
   128  		SetConstructorParameters(NewContractFunctionParameters().AddString("Hello from Hedera.")).
   129  		SetBytecodeFileID(fileID).
   130  		SetContractMemo("[e2e::ContractCreateTransaction]").
   131  		Execute(env.Client)
   132  	require.NoError(t, err)
   133  
   134  	contractReceipt, err := contractResponse.SetValidateStatus(true).GetReceipt(env.Client)
   135  	require.NoError(t, err)
   136  
   137  	assert.NotNil(t, contractReceipt.ContractID)
   138  
   139  	assert.True(t, contractReceipt.ContractID.Contract > 0)
   140  
   141  	contractID := *contractReceipt.ContractID
   142  
   143  	bytecodeQuery := NewContractBytecodeQuery().
   144  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   145  		SetMaxQueryPayment(NewHbar(1)).
   146  		SetContractID(contractID)
   147  
   148  	cost, err := bytecodeQuery.GetCost(env.Client)
   149  	require.NoError(t, err)
   150  
   151  	bytecode, err := bytecodeQuery.SetQueryPayment(cost).Execute(env.Client)
   152  	require.NoError(t, err)
   153  
   154  	assert.Equal(t, len(bytecode), 798)
   155  
   156  	resp, err = NewContractDeleteTransaction().
   157  		SetContractID(contractID).
   158  		SetTransferAccountID(env.Client.GetOperatorAccountID()).
   159  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   160  		Execute(env.Client)
   161  	require.NoError(t, err)
   162  
   163  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   164  	require.NoError(t, err)
   165  
   166  	resp, err = NewFileDeleteTransaction().
   167  		SetFileID(fileID).
   168  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   169  		Execute(env.Client)
   170  	require.NoError(t, err)
   171  
   172  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   173  	require.NoError(t, err)
   174  
   175  	err = CloseIntegrationTestEnv(env, nil)
   176  	require.NoError(t, err)
   177  }
   178  
   179  func TestIntegrationContractBytecodeQuerySetBigMaxPayment(t *testing.T) {
   180  	t.Parallel()
   181  	env := NewIntegrationTestEnv(t)
   182  
   183  	smartContractBytecode := []byte("608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033")
   184  
   185  	resp, err := NewFileCreateTransaction().
   186  		SetNodeAccountIDs(env.NodeAccountIDs).
   187  		SetKeys(env.OperatorKey).
   188  		SetContents(smartContractBytecode).
   189  		Execute(env.Client)
   190  	require.NoError(t, err)
   191  
   192  	receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
   193  	require.NoError(t, err)
   194  
   195  	assert.NotNil(t, receipt.FileID)
   196  	fileID := *receipt.FileID
   197  
   198  	contractResponse, err := NewContractCreateTransaction().
   199  		SetAdminKey(env.OperatorKey).
   200  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   201  		SetGas(200000).
   202  		SetConstructorParameters(NewContractFunctionParameters().AddString("Hello from Hedera.")).
   203  		SetBytecodeFileID(fileID).
   204  		SetContractMemo("[e2e::ContractCreateTransaction]").
   205  		Execute(env.Client)
   206  	require.NoError(t, err)
   207  
   208  	contractReceipt, err := contractResponse.SetValidateStatus(true).GetReceipt(env.Client)
   209  	require.NoError(t, err)
   210  
   211  	assert.NotNil(t, contractReceipt.ContractID)
   212  
   213  	assert.True(t, contractReceipt.ContractID.Contract > 0)
   214  
   215  	contractID := *contractReceipt.ContractID
   216  
   217  	bytecodeQuery := NewContractBytecodeQuery().
   218  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   219  		SetMaxQueryPayment(NewHbar(200000)).
   220  		SetContractID(contractID)
   221  
   222  	cost, err := bytecodeQuery.GetCost(env.Client)
   223  	require.NoError(t, err)
   224  
   225  	bytecode, err := bytecodeQuery.SetQueryPayment(cost).Execute(env.Client)
   226  	require.NoError(t, err)
   227  
   228  	assert.Equal(t, len(bytecode), 798)
   229  
   230  	resp, err = NewContractDeleteTransaction().
   231  		SetContractID(contractID).
   232  		SetTransferAccountID(env.Client.GetOperatorAccountID()).
   233  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   234  		Execute(env.Client)
   235  	require.NoError(t, err)
   236  
   237  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   238  	require.NoError(t, err)
   239  
   240  	resp, err = NewFileDeleteTransaction().
   241  		SetFileID(fileID).
   242  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   243  		Execute(env.Client)
   244  	require.NoError(t, err)
   245  
   246  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   247  	require.NoError(t, err)
   248  
   249  	err = CloseIntegrationTestEnv(env, nil)
   250  	require.NoError(t, err)
   251  }
   252  
   253  func TestIntegrationContractBytecodeQuerySetSmallMaxPayment(t *testing.T) {
   254  	t.Parallel()
   255  	env := NewIntegrationTestEnv(t)
   256  
   257  	smartContractBytecode := []byte("608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033")
   258  
   259  	resp, err := NewFileCreateTransaction().
   260  		SetKeys(env.OperatorKey).
   261  		SetNodeAccountIDs(env.NodeAccountIDs).
   262  		SetContents(smartContractBytecode).
   263  		Execute(env.Client)
   264  	require.NoError(t, err)
   265  
   266  	receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
   267  	require.NoError(t, err)
   268  
   269  	assert.NotNil(t, receipt.FileID)
   270  	fileID := *receipt.FileID
   271  
   272  	contractResponse, err := NewContractCreateTransaction().
   273  		SetAdminKey(env.OperatorKey).
   274  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   275  		SetGas(200000).
   276  		SetConstructorParameters(NewContractFunctionParameters().AddString("Hello from Hedera.")).
   277  		SetBytecodeFileID(fileID).
   278  		SetContractMemo("[e2e::ContractCreateTransaction]").
   279  		Execute(env.Client)
   280  	require.NoError(t, err)
   281  
   282  	contractReceipt, err := contractResponse.SetValidateStatus(true).GetReceipt(env.Client)
   283  	require.NoError(t, err)
   284  
   285  	assert.NotNil(t, contractReceipt.ContractID)
   286  
   287  	assert.True(t, contractReceipt.ContractID.Contract > 0)
   288  
   289  	contractID := *contractReceipt.ContractID
   290  
   291  	bytecodeQuery := NewContractBytecodeQuery().
   292  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   293  		SetMaxQueryPayment(HbarFromTinybar(1)).
   294  		SetContractID(contractID)
   295  
   296  	cost, err := bytecodeQuery.GetCost(env.Client)
   297  	require.NoError(t, err)
   298  
   299  	_, err = bytecodeQuery.Execute(env.Client)
   300  	assert.Error(t, err)
   301  	if err != nil {
   302  		assert.Equal(t, "cost of ContractBytecodeQuery ("+cost.String()+") without explicit payment is greater than the max query payment of 1 tℏ", err.Error())
   303  	}
   304  
   305  	resp, err = NewContractDeleteTransaction().
   306  		SetContractID(contractID).
   307  		SetTransferAccountID(env.Client.GetOperatorAccountID()).
   308  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   309  		Execute(env.Client)
   310  	require.NoError(t, err)
   311  
   312  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   313  	require.NoError(t, err)
   314  
   315  	resp, err = NewFileDeleteTransaction().
   316  		SetFileID(fileID).
   317  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   318  		Execute(env.Client)
   319  	require.NoError(t, err)
   320  
   321  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   322  	require.NoError(t, err)
   323  
   324  	err = CloseIntegrationTestEnv(env, nil)
   325  	require.NoError(t, err)
   326  }
   327  
   328  func TestIntegrationContractBytecodeQueryInsufficientFee(t *testing.T) {
   329  	t.Parallel()
   330  	env := NewIntegrationTestEnv(t)
   331  
   332  	smartContractBytecode := []byte("608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033")
   333  
   334  	resp, err := NewFileCreateTransaction().
   335  		SetKeys(env.OperatorKey).
   336  		SetContents(smartContractBytecode).
   337  		SetNodeAccountIDs(env.NodeAccountIDs).
   338  		Execute(env.Client)
   339  	require.NoError(t, err)
   340  
   341  	receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
   342  	require.NoError(t, err)
   343  
   344  	assert.NotNil(t, receipt.FileID)
   345  	fileID := *receipt.FileID
   346  
   347  	contractResponse, err := NewContractCreateTransaction().
   348  		SetAdminKey(env.OperatorKey).
   349  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   350  		SetGas(200000).
   351  		SetConstructorParameters(NewContractFunctionParameters().AddString("Hello from Hedera.")).
   352  		SetBytecodeFileID(fileID).
   353  		SetContractMemo("[e2e::ContractCreateTransaction]").
   354  		Execute(env.Client)
   355  	require.NoError(t, err)
   356  
   357  	contractReceipt, err := contractResponse.SetValidateStatus(true).GetReceipt(env.Client)
   358  	require.NoError(t, err)
   359  
   360  	assert.NotNil(t, contractReceipt.ContractID)
   361  
   362  	assert.True(t, contractReceipt.ContractID.Contract > 0)
   363  
   364  	contractID := *contractReceipt.ContractID
   365  
   366  	bytecodeQuery := NewContractBytecodeQuery().
   367  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   368  		SetMaxQueryPayment(NewHbar(1)).
   369  		SetContractID(contractID)
   370  
   371  	_, err = bytecodeQuery.GetCost(env.Client)
   372  	require.NoError(t, err)
   373  
   374  	_, err = bytecodeQuery.SetQueryPayment(HbarFromTinybar(1)).Execute(env.Client)
   375  	assert.Error(t, err)
   376  	if err != nil {
   377  		assert.Equal(t, "exceptional precheck status INSUFFICIENT_TX_FEE", err.Error())
   378  	}
   379  
   380  	resp, err = NewContractDeleteTransaction().
   381  		SetContractID(contractID).
   382  		SetTransferAccountID(env.Client.GetOperatorAccountID()).
   383  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   384  		Execute(env.Client)
   385  	require.NoError(t, err)
   386  
   387  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   388  	require.NoError(t, err)
   389  
   390  	resp, err = NewFileDeleteTransaction().
   391  		SetFileID(fileID).
   392  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   393  		Execute(env.Client)
   394  	require.NoError(t, err)
   395  
   396  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   397  	require.NoError(t, err)
   398  
   399  	err = CloseIntegrationTestEnv(env, nil)
   400  	require.NoError(t, err)
   401  }
   402  
   403  func TestIntegrationContractBytecodeQueryNoContractID(t *testing.T) {
   404  	t.Parallel()
   405  	env := NewIntegrationTestEnv(t)
   406  
   407  	smartContractBytecode := []byte("608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033")
   408  
   409  	resp, err := NewFileCreateTransaction().
   410  		SetKeys(env.OperatorKey).
   411  		SetNodeAccountIDs(env.NodeAccountIDs).
   412  		SetContents(smartContractBytecode).
   413  		Execute(env.Client)
   414  	require.NoError(t, err)
   415  
   416  	receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
   417  	require.NoError(t, err)
   418  
   419  	fileID := *receipt.FileID
   420  	assert.NotNil(t, fileID)
   421  
   422  	contractResponse, err := NewContractCreateTransaction().
   423  		SetAdminKey(env.OperatorKey).
   424  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   425  		SetGas(200000).
   426  		SetConstructorParameters(NewContractFunctionParameters().AddString("Hello from Hedera.")).
   427  		SetBytecodeFileID(fileID).
   428  		SetContractMemo("[e2e::ContractCreateTransaction]").
   429  		Execute(env.Client)
   430  	require.NoError(t, err)
   431  
   432  	contractReceipt, err := contractResponse.SetValidateStatus(true).GetReceipt(env.Client)
   433  	require.NoError(t, err)
   434  
   435  	assert.NotNil(t, contractReceipt.ContractID)
   436  
   437  	assert.True(t, contractReceipt.ContractID.Contract > 0)
   438  
   439  	contractID := *contractReceipt.ContractID
   440  
   441  	_, err = NewContractBytecodeQuery().
   442  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   443  		SetMaxQueryPayment(NewHbar(2)).
   444  		Execute(env.Client)
   445  	assert.Error(t, err)
   446  	if err != nil {
   447  		assert.Equal(t, "exceptional precheck status INVALID_CONTRACT_ID", err.Error())
   448  	}
   449  
   450  	resp, err = NewContractDeleteTransaction().
   451  		SetContractID(contractID).
   452  		SetTransferAccountID(env.Client.GetOperatorAccountID()).
   453  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   454  		Execute(env.Client)
   455  	require.NoError(t, err)
   456  
   457  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   458  	require.NoError(t, err)
   459  
   460  	resp, err = NewFileDeleteTransaction().
   461  		SetFileID(fileID).
   462  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   463  		Execute(env.Client)
   464  	require.NoError(t, err)
   465  
   466  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   467  	require.NoError(t, err)
   468  
   469  	err = CloseIntegrationTestEnv(env, nil)
   470  	require.NoError(t, err)
   471  }