github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/contract_call_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 TestIntegrationContractCallQueryCanExecute(t *testing.T) { 35 t.Parallel() 36 env := NewIntegrationTestEnv(t) 37 38 smartContractBytecode := []byte("608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033") 39 40 resp, err := NewFileCreateTransaction(). 41 SetNodeAccountIDs(env.NodeAccountIDs). 42 SetKeys(env.OperatorKey.PublicKey()). 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 fileID := *receipt.FileID 51 assert.NotNil(t, fileID) 52 53 resp, err = NewContractCreateTransaction(). 54 SetAdminKey(env.OperatorKey.PublicKey()). 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 := resp.SetValidateStatus(true).GetReceipt(env.Client) 64 require.NoError(t, err) 65 66 assert.True(t, contractReceipt.ContractID.Contract > 0) 67 68 assert.NotNil(t, contractReceipt.ContractID) 69 70 contractID := *contractReceipt.ContractID 71 72 result, err := NewContractCallQuery(). 73 SetNodeAccountIDs([]AccountID{resp.NodeID}). 74 SetContractID(contractID). 75 SetQueryPayment(NewHbar(1)). 76 SetGas(100000). 77 SetFunction("getMessage", nil). 78 SetMaxQueryPayment(NewHbar(5)). 79 Execute(env.Client) 80 require.NoError(t, err) 81 82 assert.Equal(t, "Hello from Hedera.", result.GetString(0)) 83 84 resp, err = NewContractExecuteTransaction(). 85 SetContractID(contractID). 86 SetNodeAccountIDs([]AccountID{resp.NodeID}). 87 SetGas(100000). 88 SetFunction("setMessage", NewContractFunctionParameters().AddString("new message")). 89 Execute(env.Client) 90 require.NoError(t, err) 91 92 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 93 require.NoError(t, err) 94 95 result, err = NewContractCallQuery(). 96 SetContractID(contractID). 97 SetNodeAccountIDs([]AccountID{resp.NodeID}). 98 SetMaxQueryPayment(NewHbar(2)). 99 SetQueryPayment(NewHbar(1)). 100 SetGas(100000). 101 SetFunction("getMessage", nil). 102 Execute(env.Client) 103 require.NoError(t, err) 104 105 assert.Equal(t, "new message", result.GetString(0)) 106 107 resp, err = NewContractDeleteTransaction(). 108 SetContractID(contractID). 109 SetTransferAccountID(env.Client.GetOperatorAccountID()). 110 SetNodeAccountIDs([]AccountID{resp.NodeID}). 111 Execute(env.Client) 112 require.NoError(t, err) 113 114 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 115 require.NoError(t, err) 116 117 resp, err = NewFileDeleteTransaction(). 118 SetFileID(fileID). 119 SetNodeAccountIDs([]AccountID{resp.NodeID}). 120 Execute(env.Client) 121 require.NoError(t, err) 122 123 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 124 require.NoError(t, err) 125 126 err = CloseIntegrationTestEnv(env, nil) 127 require.NoError(t, err) 128 } 129 130 func TestIntegrationContractCallQueryGetCost(t *testing.T) { 131 t.Parallel() 132 env := NewIntegrationTestEnv(t) 133 134 smartContractBytecode := []byte("608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033") 135 136 resp, err := NewFileCreateTransaction(). 137 SetNodeAccountIDs(env.NodeAccountIDs). 138 SetKeys(env.OperatorKey.PublicKey()). 139 SetContents(smartContractBytecode). 140 Execute(env.Client) 141 require.NoError(t, err) 142 143 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 144 require.NoError(t, err) 145 146 fileID := *receipt.FileID 147 assert.NotNil(t, fileID) 148 149 resp, err = NewContractCreateTransaction(). 150 SetAdminKey(env.OperatorKey.PublicKey()). 151 SetNodeAccountIDs([]AccountID{resp.NodeID}). 152 SetGas(200000). 153 SetConstructorParameters(NewContractFunctionParameters().AddString("Hello from Hedera.")). 154 SetBytecodeFileID(fileID). 155 SetContractMemo("[e2e::ContractCreateTransaction]"). 156 Execute(env.Client) 157 require.NoError(t, err) 158 159 contractReceipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 160 require.NoError(t, err) 161 162 assert.True(t, contractReceipt.ContractID.Contract > 0) 163 164 assert.NotNil(t, contractReceipt.ContractID) 165 166 contractID := *contractReceipt.ContractID 167 168 callQuery := NewContractCallQuery(). 169 SetNodeAccountIDs([]AccountID{resp.NodeID}). 170 SetContractID(contractID). 171 SetMaxQueryPayment(NewHbar(1)). 172 SetGas(200000). 173 SetFunction("getMessage", nil) 174 175 cost, err := callQuery.GetCost(env.Client) 176 require.NoError(t, err) 177 178 _, err = callQuery.SetQueryPayment(HbarFromTinybar(cost.tinybar + 10000)).Execute(env.Client) 179 require.NoError(t, err) 180 181 resp, err = NewContractDeleteTransaction(). 182 SetContractID(contractID). 183 SetTransferAccountID(env.Client.GetOperatorAccountID()). 184 SetNodeAccountIDs([]AccountID{resp.NodeID}). 185 Execute(env.Client) 186 require.NoError(t, err) 187 188 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 189 require.NoError(t, err) 190 191 resp, err = NewFileDeleteTransaction(). 192 SetFileID(fileID). 193 SetNodeAccountIDs([]AccountID{resp.NodeID}). 194 Execute(env.Client) 195 require.NoError(t, err) 196 197 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 198 require.NoError(t, err) 199 200 err = CloseIntegrationTestEnv(env, nil) 201 require.NoError(t, err) 202 } 203 204 func TestIntegrationContractCallQuerySetMaxPaymentBig(t *testing.T) { 205 t.Parallel() 206 env := NewIntegrationTestEnv(t) 207 208 smartContractBytecode := []byte("608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033") 209 210 resp, err := NewFileCreateTransaction(). 211 SetNodeAccountIDs(env.NodeAccountIDs). 212 SetKeys(env.OperatorKey.PublicKey()). 213 SetContents(smartContractBytecode). 214 Execute(env.Client) 215 require.NoError(t, err) 216 217 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 218 require.NoError(t, err) 219 220 fileID := *receipt.FileID 221 assert.NotNil(t, fileID) 222 223 resp, err = NewContractCreateTransaction(). 224 SetAdminKey(env.OperatorKey.PublicKey()). 225 SetNodeAccountIDs([]AccountID{resp.NodeID}). 226 SetGas(200000). 227 SetConstructorParameters(NewContractFunctionParameters().AddString("Hello from Hedera.")). 228 SetBytecodeFileID(fileID). 229 SetContractMemo("[e2e::ContractCreateTransaction]"). 230 Execute(env.Client) 231 require.NoError(t, err) 232 233 contractReceipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 234 require.NoError(t, err) 235 236 assert.True(t, contractReceipt.ContractID.Contract > 0) 237 238 assert.NotNil(t, contractReceipt.ContractID) 239 240 contractID := *contractReceipt.ContractID 241 242 callQuery := NewContractCallQuery(). 243 SetNodeAccountIDs([]AccountID{resp.NodeID}). 244 SetContractID(contractID). 245 SetMaxQueryPayment(NewHbar(20000)). 246 SetGas(200000). 247 SetFunction("getMessage", nil) 248 249 _, err = callQuery.GetCost(env.Client) 250 require.NoError(t, err) 251 252 _, err = callQuery.SetQueryPayment(NewHbar(1)).Execute(env.Client) 253 require.NoError(t, err) 254 255 resp, err = NewContractDeleteTransaction(). 256 SetContractID(contractID). 257 SetTransferAccountID(env.Client.GetOperatorAccountID()). 258 SetNodeAccountIDs([]AccountID{resp.NodeID}). 259 Execute(env.Client) 260 require.NoError(t, err) 261 262 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 263 require.NoError(t, err) 264 265 resp, err = NewFileDeleteTransaction(). 266 SetFileID(fileID). 267 SetNodeAccountIDs([]AccountID{resp.NodeID}). 268 Execute(env.Client) 269 require.NoError(t, err) 270 271 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 272 require.NoError(t, err) 273 274 err = CloseIntegrationTestEnv(env, nil) 275 require.NoError(t, err) 276 } 277 278 func TestIntegrationContractCallQuerySetSmallMaxPayment(t *testing.T) { 279 t.Parallel() 280 env := NewIntegrationTestEnv(t) 281 282 smartContractBytecode := []byte("608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033") 283 284 resp, err := NewFileCreateTransaction(). 285 SetKeys(env.OperatorKey.PublicKey()). 286 SetNodeAccountIDs(env.NodeAccountIDs). 287 SetContents(smartContractBytecode). 288 Execute(env.Client) 289 require.NoError(t, err) 290 291 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 292 require.NoError(t, err) 293 294 fileID := *receipt.FileID 295 assert.NotNil(t, fileID) 296 297 resp, err = NewContractCreateTransaction(). 298 SetAdminKey(env.OperatorKey.PublicKey()). 299 SetNodeAccountIDs([]AccountID{resp.NodeID}). 300 SetGas(200000). 301 SetConstructorParameters(NewContractFunctionParameters().AddString("Hello from Hedera.")). 302 SetBytecodeFileID(fileID). 303 SetContractMemo("[e2e::ContractCreateTransaction]"). 304 Execute(env.Client) 305 require.NoError(t, err) 306 307 contractReceipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 308 require.NoError(t, err) 309 310 assert.True(t, contractReceipt.ContractID.Contract > 0) 311 312 assert.NotNil(t, contractReceipt.ContractID) 313 314 contractID := *contractReceipt.ContractID 315 316 callQuery := NewContractCallQuery(). 317 SetNodeAccountIDs([]AccountID{resp.NodeID}). 318 SetContractID(contractID). 319 SetMaxQueryPayment(HbarFromTinybar(1)). 320 SetGas(200000). 321 SetFunction("getMessage", nil) 322 323 cost, err := callQuery.GetCost(env.Client) 324 require.NoError(t, err) 325 326 _, err = callQuery.Execute(env.Client) 327 assert.Error(t, err) 328 if err != nil { 329 assert.Equal(t, "cost of ContractCallQuery ("+cost.String()+") without explicit payment is greater than the max query payment of 1 tℏ", err.Error()) 330 } 331 332 resp, err = NewContractDeleteTransaction(). 333 SetContractID(contractID). 334 SetTransferAccountID(env.Client.GetOperatorAccountID()). 335 SetNodeAccountIDs([]AccountID{resp.NodeID}). 336 Execute(env.Client) 337 require.NoError(t, err) 338 339 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 340 require.NoError(t, err) 341 342 resp, err = NewFileDeleteTransaction(). 343 SetFileID(fileID). 344 SetNodeAccountIDs([]AccountID{resp.NodeID}). 345 Execute(env.Client) 346 require.NoError(t, err) 347 348 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 349 require.NoError(t, err) 350 351 err = CloseIntegrationTestEnv(env, nil) 352 require.NoError(t, err) 353 } 354 355 func TestIntegrationContractCallQueryInsufficientFee(t *testing.T) { 356 t.Parallel() 357 env := NewIntegrationTestEnv(t) 358 359 smartContractBytecode := []byte("608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033") 360 361 resp, err := NewFileCreateTransaction(). 362 SetNodeAccountIDs(env.NodeAccountIDs). 363 SetKeys(env.OperatorKey.PublicKey()). 364 SetContents(smartContractBytecode). 365 Execute(env.Client) 366 require.NoError(t, err) 367 368 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 369 require.NoError(t, err) 370 371 fileID := *receipt.FileID 372 assert.NotNil(t, fileID) 373 374 resp, err = NewContractCreateTransaction(). 375 SetAdminKey(env.Client.GetOperatorPublicKey()). 376 SetNodeAccountIDs([]AccountID{resp.NodeID}). 377 SetGas(200000). 378 SetConstructorParameters(NewContractFunctionParameters().AddString("Hello from Hedera.")). 379 SetBytecodeFileID(fileID). 380 SetContractMemo("[e2e::ContractCreateTransaction]"). 381 Execute(env.Client) 382 require.NoError(t, err) 383 384 contractReceipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 385 require.NoError(t, err) 386 387 assert.True(t, contractReceipt.ContractID.Contract > 0) 388 389 assert.NotNil(t, contractReceipt.ContractID) 390 391 contractID := *contractReceipt.ContractID 392 393 callQuery := NewContractCallQuery(). 394 SetNodeAccountIDs([]AccountID{resp.NodeID}). 395 SetContractID(contractID). 396 SetMaxQueryPayment(NewHbar(1)). 397 SetGas(200000). 398 SetFunction("getMessage", nil) 399 400 _, err = callQuery.GetCost(env.Client) 401 require.NoError(t, err) 402 403 _, err = callQuery.SetQueryPayment(HbarFromTinybar(1)).Execute(env.Client) 404 assert.Error(t, err) 405 if err != nil { 406 assert.Equal(t, "exceptional precheck status INSUFFICIENT_TX_FEE", err.Error()) 407 } 408 409 resp, err = NewContractDeleteTransaction(). 410 SetContractID(contractID). 411 SetTransferAccountID(env.Client.GetOperatorAccountID()). 412 SetNodeAccountIDs([]AccountID{resp.NodeID}). 413 Execute(env.Client) 414 require.NoError(t, err) 415 416 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 417 require.NoError(t, err) 418 419 resp, err = NewFileDeleteTransaction(). 420 SetFileID(fileID). 421 SetNodeAccountIDs([]AccountID{resp.NodeID}). 422 Execute(env.Client) 423 require.NoError(t, err) 424 425 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 426 require.NoError(t, err) 427 428 err = CloseIntegrationTestEnv(env, nil) 429 require.NoError(t, err) 430 } 431 432 func TestIntegrationContractCallQueryNoContractID(t *testing.T) { 433 t.Parallel() 434 env := NewIntegrationTestEnv(t) 435 436 _, err := NewContractCallQuery(). 437 SetGas(100000). 438 SetNodeAccountIDs(env.NodeAccountIDs). 439 // test getCost 440 SetFunction("getMessage", nil). 441 Execute(env.Client) 442 assert.Error(t, err) 443 if err != nil { 444 assert.Equal(t, "exceptional precheck status INVALID_CONTRACT_ID", err.Error()) 445 } 446 447 err = CloseIntegrationTestEnv(env, nil) 448 require.NoError(t, err) 449 } 450 451 func TestIntegrationContractCallQueryNoGas(t *testing.T) { 452 t.Parallel() 453 env := NewIntegrationTestEnv(t) 454 455 smartContractBytecode := []byte("608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033") 456 457 resp, err := NewFileCreateTransaction(). 458 SetKeys(env.OperatorKey.PublicKey()). 459 SetNodeAccountIDs(env.NodeAccountIDs). 460 SetContents(smartContractBytecode). 461 Execute(env.Client) 462 require.NoError(t, err) 463 464 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 465 require.NoError(t, err) 466 467 fileID := *receipt.FileID 468 assert.NotNil(t, fileID) 469 470 resp, err = NewContractCreateTransaction(). 471 SetAdminKey(env.OperatorKey.PublicKey()). 472 SetNodeAccountIDs([]AccountID{resp.NodeID}). 473 SetGas(200000). 474 SetConstructorParameters(NewContractFunctionParameters().AddString("Hello from Hedera.")). 475 SetBytecodeFileID(fileID). 476 SetContractMemo("[e2e::ContractCreateTransaction]"). 477 Execute(env.Client) 478 require.NoError(t, err) 479 480 contractReceipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 481 require.NoError(t, err) 482 483 assert.True(t, contractReceipt.ContractID.Contract > 0) 484 485 assert.NotNil(t, contractReceipt.ContractID) 486 487 contractID := *contractReceipt.ContractID 488 489 _, err = NewContractCallQuery(). 490 SetNodeAccountIDs([]AccountID{resp.NodeID}). 491 SetContractID(contractID). 492 SetQueryPayment(NewHbar(1)). 493 SetFunction("getMessage", nil). 494 Execute(env.Client) 495 assert.Error(t, err) 496 if err != nil { 497 assert.Equal(t, "exceptional precheck status INSUFFICIENT_GAS", err.Error()) 498 } 499 500 resp, err = NewContractDeleteTransaction(). 501 SetContractID(contractID). 502 SetTransferAccountID(env.Client.GetOperatorAccountID()). 503 SetNodeAccountIDs([]AccountID{resp.NodeID}). 504 Execute(env.Client) 505 require.NoError(t, err) 506 507 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 508 require.NoError(t, err) 509 510 resp, err = NewFileDeleteTransaction(). 511 SetFileID(fileID). 512 SetNodeAccountIDs([]AccountID{resp.NodeID}). 513 Execute(env.Client) 514 require.NoError(t, err) 515 516 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 517 require.NoError(t, err) 518 519 err = CloseIntegrationTestEnv(env, nil) 520 require.NoError(t, err) 521 } 522 523 func TestIntegrationContractCallQueryNoFunction(t *testing.T) { 524 t.Parallel() 525 env := NewIntegrationTestEnv(t) 526 527 smartContractBytecode := []byte("608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033") 528 529 resp, err := NewFileCreateTransaction(). 530 SetKeys(env.OperatorKey.PublicKey()). 531 SetNodeAccountIDs(env.NodeAccountIDs). 532 SetContents(smartContractBytecode). 533 Execute(env.Client) 534 require.NoError(t, err) 535 536 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 537 require.NoError(t, err) 538 539 fileID := *receipt.FileID 540 assert.NotNil(t, fileID) 541 542 resp, err = NewContractCreateTransaction(). 543 SetAdminKey(env.OperatorKey.PublicKey()). 544 SetNodeAccountIDs([]AccountID{resp.NodeID}). 545 SetGas(200000). 546 SetConstructorParameters(NewContractFunctionParameters().AddString("Hello from Hedera.")). 547 SetBytecodeFileID(fileID). 548 SetContractMemo("[e2e::ContractCreateTransaction]"). 549 Execute(env.Client) 550 require.NoError(t, err) 551 552 contractReceipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 553 require.NoError(t, err) 554 555 assert.True(t, contractReceipt.ContractID.Contract > 0) 556 557 assert.NotNil(t, contractReceipt.ContractID) 558 559 contractID := *contractReceipt.ContractID 560 561 _, err = NewContractCallQuery(). 562 SetNodeAccountIDs([]AccountID{resp.NodeID}). 563 SetContractID(contractID). 564 SetGas(200000). 565 SetQueryPayment(NewHbar(1)). 566 // test getCost 567 Execute(env.Client) 568 assert.Error(t, err) 569 if err != nil { 570 assert.Equal(t, "exceptional precheck status CONTRACT_REVERT_EXECUTED", err.Error()) 571 } 572 573 resp, err = NewContractDeleteTransaction(). 574 SetContractID(contractID). 575 SetTransferAccountID(env.Client.GetOperatorAccountID()). 576 SetNodeAccountIDs([]AccountID{resp.NodeID}). 577 Execute(env.Client) 578 require.NoError(t, err) 579 580 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 581 require.NoError(t, err) 582 583 resp, err = NewFileDeleteTransaction(). 584 SetFileID(fileID). 585 SetNodeAccountIDs([]AccountID{resp.NodeID}). 586 Execute(env.Client) 587 require.NoError(t, err) 588 589 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 590 require.NoError(t, err) 591 592 err = CloseIntegrationTestEnv(env, nil) 593 require.NoError(t, err) 594 }