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