github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/contract_id_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 TestIntegrationContractIDCanPopulateAccountNumber(t *testing.T) {
    34  	t.Parallel()
    35  	env := NewIntegrationTestEnv(t)
    36  	testContractByteCode := []byte(`608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506101cb806100606000396000f3fe608060405260043610610046576000357c01000000000000000000000000000000000000000000000000000000009004806341c0e1b51461004b578063cfae321714610062575b600080fd5b34801561005757600080fd5b506100606100f2565b005b34801561006e57600080fd5b50610077610162565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100b757808201518184015260208101905061009c565b50505050905090810190601f1680156100e45780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610160573373ffffffffffffffffffffffffffffffffffffffff16ff5b565b60606040805190810160405280600d81526020017f48656c6c6f2c20776f726c64210000000000000000000000000000000000000081525090509056fea165627a7a72305820ae96fb3af7cde9c0abfe365272441894ab717f816f07f41f07b1cbede54e256e0029`)
    37  
    38  	resp, err := NewFileCreateTransaction().
    39  		SetNodeAccountIDs(env.NodeAccountIDs).
    40  		SetKeys(env.Client.GetOperatorPublicKey()).
    41  		SetContents(testContractByteCode).
    42  		Execute(env.Client)
    43  	require.NoError(t, err)
    44  
    45  	receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
    46  	require.NoError(t, err)
    47  
    48  	fileID := *receipt.FileID
    49  	require.NotNil(t, fileID)
    50  
    51  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
    52  	require.NoError(t, err)
    53  
    54  	resp, err = NewContractCreateTransaction().
    55  		SetAdminKey(env.Client.GetOperatorPublicKey()).
    56  		SetGas(100000).
    57  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
    58  		SetConstructorParameters(NewContractFunctionParameters().AddString("hello from hedera")).
    59  		SetBytecodeFileID(fileID).
    60  		SetContractMemo("hedera-sdk-go::TestContractInfoQuery_Execute").
    61  		Execute(env.Client)
    62  	require.NoError(t, err)
    63  
    64  	receipt, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
    65  	require.NoError(t, err)
    66  
    67  	require.NotNil(t, receipt.ContractID)
    68  
    69  	contractID := *receipt.ContractID
    70  	info, err := NewContractInfoQuery().SetContractID(contractID).Execute(env.Client)
    71  	require.NoError(t, err)
    72  	idMirror, err := ContractIDFromEvmAddress(0, 0, info.ContractAccountID)
    73  	require.NoError(t, err)
    74  	time.Sleep(5 * time.Second)
    75  	err = idMirror.PopulateContract(env.Client)
    76  	require.NoError(t, err)
    77  	require.Equal(t, contractID.Contract, idMirror.Contract)
    78  }