github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/contract_create_flow_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 "time" 29 30 "github.com/stretchr/testify/require" 31 ) 32 33 func TestIntegrationContractCreateFlowCanExecute(t *testing.T) { 34 testContractByteCode := []byte(`608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033`) 35 36 t.Parallel() 37 env := NewIntegrationTestEnv(t) 38 39 resp, err := NewContractCreateFlow(). 40 SetBytecode(testContractByteCode). 41 SetAdminKey(env.OperatorKey). 42 SetGas(200000). 43 SetConstructorParameters(NewContractFunctionParameters().AddString("hello from hedera")). 44 SetContractMemo("[e2e::ContractCreateFlow]"). 45 Execute(env.Client) 46 require.NoError(t, err) 47 48 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 49 require.NoError(t, err) 50 51 require.NotNil(t, receipt.ContractID) 52 contractID := *receipt.ContractID 53 54 resp, err = NewContractExecuteTransaction(). 55 SetContractID(contractID). 56 SetNodeAccountIDs([]AccountID{resp.NodeID}). 57 SetGas(200000). 58 SetFunction("setMessage", NewContractFunctionParameters().AddString("new message")). 59 Execute(env.Client) 60 require.NoError(t, err) 61 62 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 63 require.NoError(t, err) 64 65 resp, err = NewContractDeleteTransaction(). 66 SetContractID(contractID). 67 SetNodeAccountIDs([]AccountID{resp.NodeID}). 68 SetTransferAccountID(AccountID{Account: 3}). 69 Execute(env.Client) 70 require.NoError(t, err) 71 72 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 73 require.NoError(t, err) 74 75 err = CloseIntegrationTestEnv(env, nil) 76 require.NoError(t, err) 77 } 78 79 func TestIntegrationContractCreateFlowSmallContractCanExecute(t *testing.T) { 80 t.Skip("Possible bug in services is causing this test to behave flaky") 81 82 testContractByteCode := []byte(`6080604052348015600f57600080fd5b50604051601a90603b565b604051809103906000f0801580156035573d6000803e3d6000fd5b50506047565b605c8061009483390190565b603f806100556000396000f3fe6080604052600080fdfea2646970667358221220a20122cbad3457fedcc0600363d6e895f17048f5caa4afdab9e655123737567d64736f6c634300081200336080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea264697066735822122053dfd8835e3dc6fedfb8b4806460b9b7163f8a7248bac510c6d6808d9da9d6d364736f6c63430008120033`) 83 84 t.Parallel() 85 env := NewIntegrationTestEnv(t) 86 87 resp, err := NewContractCreateFlow(). 88 SetBytecode(testContractByteCode). 89 SetAdminKey(env.OperatorKey). 90 SetGas(100000). 91 Execute(env.Client) 92 require.NoError(t, err) 93 94 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 95 require.NoError(t, err) 96 require.NotNil(t, receipt.ContractID) 97 98 err = CloseIntegrationTestEnv(env, nil) 99 require.NoError(t, err) 100 } 101 102 func TestIntegrationContractCreateFlowGettersAndSetters(t *testing.T) { 103 t.Parallel() 104 env := NewIntegrationTestEnv(t) 105 106 testContractByteCode := "608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033" 107 testOperatorKey := env.OperatorKey 108 testGas := int64(100000) 109 testMemo := "[e2e::ContractCreateFlow]" 110 testInitialBalance := HbarFromTinybar(1000000000000000000) 111 autoRenewPeriod := 131500 * time.Minute 112 testProxyAccountID := AccountID{Account: 3} 113 testAutoTokenAssociations := int32(10) 114 testMaxChuncks := uint64(4) 115 testNodeAccountID := AccountID{Account: 55} 116 117 constructorFuncName := "constructor" 118 constructorParams := ContractFunctionParameters{ 119 function: ContractFunctionSelector{ 120 function: &constructorFuncName, 121 params: "wooow", 122 paramTypes: []_Solidity{}}, 123 arguments: []Argument{Argument{ 124 value: []byte("hello from hedera"), 125 dynamic: false, 126 }}} 127 128 createChain := NewContractCreateFlow(). 129 SetBytecodeWithString(testContractByteCode). 130 SetAdminKey(env.OperatorKey). 131 SetGas(100000). 132 SetConstructorParameters(NewContractFunctionParameters().AddString("hello from hedera")). 133 SetContractMemo("[e2e::ContractCreateFlow]"). 134 SetInitialBalance(testInitialBalance). 135 SetProxyAccountID(testProxyAccountID). 136 SetConstructorParameters(&constructorParams). 137 SetAutoRenewAccountID(testProxyAccountID). 138 SetMaxAutomaticTokenAssociations(testAutoTokenAssociations). 139 SetMaxChunks(testMaxChuncks). 140 SetNodeAccountIDs([]AccountID{testNodeAccountID, testProxyAccountID}) 141 142 require.Equal(t, createChain.GetBytecode(), testContractByteCode) 143 require.Equal(t, createChain.GetAdminKey(), testOperatorKey) 144 require.Equal(t, createChain.GetGas(), testGas) 145 require.Equal(t, createChain.GetContractMemo(), testMemo) 146 require.Equal(t, createChain.GetInitialBalance(), testInitialBalance) 147 require.Equal(t, createChain.GetAutoRenewPeriod(), autoRenewPeriod) 148 require.Equal(t, createChain.GetProxyAccountID(), testProxyAccountID) 149 require.Equal(t, createChain.GetAutoRenewAccountID(), testProxyAccountID) 150 require.Equal(t, createChain.GetMaxAutomaticTokenAssociations(), testAutoTokenAssociations) 151 require.Equal(t, createChain.GetMaxChunks(), testMaxChuncks) 152 require.Equal(t, createChain.GetNodeAccountIDs(), []AccountID{testNodeAccountID, testProxyAccountID}) 153 154 }