github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/contract_update_transaction_e2e_test.go (about) 1 //go:build all || e2e 2 // +build all e2e 3 4 package hedera 5 6 /*- 7 * 8 * Hedera Go SDK 9 * 10 * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC 11 * 12 * Licensed under the Apache License, Version 2.0 (the "License"); 13 * you may not use this file except in compliance with the License. 14 * You may obtain a copy of the License at 15 * 16 * http://www.apache.org/licenses/LICENSE-2.0 17 * 18 * Unless required by applicable law or agreed to in writing, software 19 * distributed under the License is distributed on an "AS IS" BASIS, 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 * See the License for the specific language governing permissions and 22 * limitations under the License. 23 * 24 */ 25 26 import ( 27 "fmt" 28 "testing" 29 30 "github.com/stretchr/testify/assert" 31 32 "github.com/stretchr/testify/require" 33 ) 34 35 func TestIntegrationContractUpdateTransactionCanExecute(t *testing.T) { 36 t.Parallel() 37 env := NewIntegrationTestEnv(t) 38 39 // Note: this is the bytecode for the contract found in the example for ./examples/_Create_simpleContract 40 testContractByteCode := []byte(`608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506101cb806100606000396000f3fe608060405260043610610046576000357c01000000000000000000000000000000000000000000000000000000009004806341c0e1b51461004b578063cfae321714610062575b600080fd5b34801561005757600080fd5b506100606100f2565b005b34801561006e57600080fd5b50610077610162565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100b757808201518184015260208101905061009c565b50505050905090810190601f1680156100e45780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610160573373ffffffffffffffffffffffffffffffffffffffff16ff5b565b60606040805190810160405280600d81526020017f48656c6c6f2c20776f726c64210000000000000000000000000000000000000081525090509056fea165627a7a72305820ae96fb3af7cde9c0abfe365272441894ab717f816f07f41f07b1cbede54e256e0029`) 41 42 resp, err := NewFileCreateTransaction(). 43 SetKeys(env.Client.GetOperatorPublicKey()). 44 SetNodeAccountIDs(env.NodeAccountIDs). 45 SetContents(testContractByteCode). 46 Execute(env.Client) 47 48 require.NoError(t, err) 49 50 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 51 require.NoError(t, err) 52 53 fileID := *receipt.FileID 54 assert.NotNil(t, fileID) 55 56 resp, err = NewContractCreateTransaction(). 57 SetAdminKey(env.Client.GetOperatorPublicKey()). 58 SetGas(100000). 59 SetNodeAccountIDs([]AccountID{resp.NodeID}). 60 SetConstructorParameters(NewContractFunctionParameters().AddString("hello from hedera")). 61 SetBytecodeFileID(fileID). 62 SetContractMemo("[e2e::ContractCreateTransaction]"). 63 Execute(env.Client) 64 require.NoError(t, err) 65 66 receipt, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 67 require.NoError(t, err) 68 69 assert.NotNil(t, receipt.ContractID) 70 contractID := *receipt.ContractID 71 72 info, err := NewContractInfoQuery(). 73 SetContractID(contractID). 74 SetNodeAccountIDs([]AccountID{resp.NodeID}). 75 SetQueryPayment(NewHbar(1)). 76 Execute(env.Client) 77 require.NoError(t, err) 78 79 assert.NotNil(t, info) 80 assert.NotNil(t, info, info.Storage) 81 assert.NotNil(t, info.ContractID) 82 assert.Equal(t, info.ContractID, contractID) 83 assert.NotNil(t, info.AccountID) 84 assert.Equal(t, info.AccountID.String(), contractID.String()) 85 assert.NotNil(t, info.AdminKey) 86 assert.Equal(t, info.AdminKey.String(), env.Client.GetOperatorPublicKey().String()) 87 assert.Equal(t, info.Storage, uint64(0x40)) 88 assert.Equal(t, info.ContractMemo, "[e2e::ContractCreateTransaction]") 89 90 resp, err = NewContractUpdateTransaction(). 91 SetContractID(contractID). 92 SetNodeAccountIDs([]AccountID{resp.NodeID}). 93 SetContractMemo("[e2e::ContractUpdateTransaction]"). 94 Execute(env.Client) 95 require.NoError(t, err) 96 97 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 98 require.NoError(t, err) 99 100 info, err = NewContractInfoQuery(). 101 SetContractID(contractID). 102 SetNodeAccountIDs([]AccountID{resp.NodeID}). 103 SetQueryPayment(NewHbar(1)). 104 Execute(env.Client) 105 require.NoError(t, err) 106 107 assert.NotNil(t, info) 108 assert.NotNil(t, info.ContractID) 109 assert.Equal(t, info.ContractID, contractID) 110 assert.NotNil(t, info.AccountID) 111 assert.Equal(t, info.AccountID.String(), contractID.String()) 112 assert.NotNil(t, info.AdminKey) 113 assert.Equal(t, info.AdminKey.String(), env.Client.GetOperatorPublicKey().String()) 114 assert.Equal(t, info.Storage, uint64(0x40)) 115 assert.Equal(t, info.ContractMemo, "[e2e::ContractUpdateTransaction]") 116 117 resp, err = NewContractDeleteTransaction(). 118 SetContractID(contractID). 119 SetTransferAccountID(env.Client.GetOperatorAccountID()). 120 SetNodeAccountIDs([]AccountID{resp.NodeID}). 121 Execute(env.Client) 122 require.NoError(t, err) 123 124 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 125 require.NoError(t, err) 126 127 resp, err = NewFileDeleteTransaction(). 128 SetFileID(fileID). 129 SetNodeAccountIDs([]AccountID{resp.NodeID}). 130 Execute(env.Client) 131 require.NoError(t, err) 132 133 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 134 require.NoError(t, err) 135 136 err = CloseIntegrationTestEnv(env, nil) 137 require.NoError(t, err) 138 } 139 140 func TestIntegrationContractUpdateTransactionNoContractID(t *testing.T) { 141 t.Parallel() 142 env := NewIntegrationTestEnv(t) 143 144 resp, err := NewContractUpdateTransaction(). 145 SetNodeAccountIDs(env.NodeAccountIDs). 146 Execute(env.Client) 147 assert.Error(t, err) 148 if err != nil { 149 assert.Equal(t, fmt.Sprintf("exceptional precheck status INVALID_CONTRACT_ID received for transaction %s", resp.TransactionID), err.Error()) 150 } 151 152 err = CloseIntegrationTestEnv(env, nil) 153 require.NoError(t, err) 154 }