github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/transaction_receipt_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 TestIntegrationTransactionReceiptQueryCanExecute(t *testing.T) {
    35  	t.Parallel()
    36  	env := NewIntegrationTestEnv(t)
    37  
    38  	newKey, err := PrivateKeyGenerateEd25519()
    39  	require.NoError(t, err)
    40  
    41  	newBalance := NewHbar(2)
    42  
    43  	assert.Equal(t, 2*HbarUnits.Hbar._NumberOfTinybar(), newBalance.tinybar)
    44  
    45  	tx, err := NewAccountCreateTransaction().
    46  		SetKey(newKey.PublicKey()).
    47  		SetNodeAccountIDs(env.NodeAccountIDs).
    48  		SetInitialBalance(newBalance).
    49  		FreezeWith(env.Client)
    50  	require.NoError(t, err)
    51  
    52  	tx, err = tx.SignWithOperator(env.Client)
    53  	require.NoError(t, err)
    54  
    55  	resp, err := tx.Execute(env.Client)
    56  	require.NoError(t, err)
    57  
    58  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
    59  	require.NoError(t, err)
    60  
    61  	_, err = resp.GetRecord(env.Client)
    62  	require.NoError(t, err)
    63  
    64  	err = CloseIntegrationTestEnv(env, nil)
    65  	require.NoError(t, err)
    66  }
    67  
    68  // what is this
    69  func DisabledTestIntegrationTransactionReceiptQueryInvalidTransactionID(t *testing.T) {
    70  	t.Parallel()
    71  	env := NewIntegrationTestEnv(t)
    72  
    73  	key, err := GeneratePrivateKey()
    74  	require.NoError(t, err)
    75  
    76  	resp, err := NewAccountCreateTransaction().
    77  		SetKey(key).
    78  		SetInitialBalance(NewHbar(2)).
    79  		Execute(env.Client)
    80  	require.NoError(t, err)
    81  
    82  	receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
    83  	require.NoError(t, err)
    84  
    85  	accountID := *receipt.AccountID
    86  
    87  	tx := NewTransferTransaction().
    88  		AddHbarTransfer(accountID, NewHbar(1).Negated()).
    89  		AddHbarTransfer(env.Client.GetOperatorAccountID(), NewHbar(1))
    90  
    91  	scheduleTx, err := tx.Schedule()
    92  	require.NoError(t, err)
    93  
    94  	scheduleTx = scheduleTx.
    95  		SetNodeAccountIDs(env.NodeAccountIDs).
    96  		SetPayerAccountID(env.Client.GetOperatorAccountID()).
    97  		SetAdminKey(env.Client.GetOperatorPublicKey()).
    98  		SetTransactionID(TransactionIDGenerate(env.Client.GetOperatorAccountID()))
    99  
   100  	resp, err = scheduleTx.Execute(env.Client)
   101  	require.NoError(t, err)
   102  
   103  	receipt, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   104  	require.NoError(t, err)
   105  
   106  	scheduleID := *receipt.ScheduleID
   107  
   108  	scheduleSignTx, err := NewScheduleSignTransaction().
   109  		SetNodeAccountIDs(env.NodeAccountIDs).
   110  		SetScheduleID(scheduleID).
   111  		FreezeWith(env.Client)
   112  	require.NoError(t, err)
   113  
   114  	resp, err = scheduleSignTx.Execute(env.Client)
   115  	require.NoError(t, err)
   116  
   117  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   118  	assert.Error(t, err)
   119  
   120  	switch receiptErr := err.(type) {
   121  	case ErrHederaReceiptStatus:
   122  		assert.NotNil(t, receiptErr.Receipt.ExchangeRate)
   123  	default:
   124  		panic("err was not a `ErrHederaReceiptStatus")
   125  	}
   126  
   127  	err = CloseIntegrationTestEnv(env, nil)
   128  	require.NoError(t, err)
   129  }
   130  
   131  func TestIntegrationFileUpdateTransactionHandleFeeScheduleUpload(t *testing.T) {
   132  	t.Parallel()
   133  	env := NewIntegrationTestEnv(t)
   134  	defer CloseIntegrationTestEnv(env, nil)
   135  
   136  	spenderKey, err := PrivateKeyFromString("302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137")
   137  	require.NoError(t, err)
   138  
   139  	env.Client.SetOperator(AccountID{Realm: 0, Shard: 0, Account: 2}, spenderKey)
   140  
   141  	resp, err := NewFileUpdateTransaction().
   142  		SetFileID(FileID{Shard: 0, Realm: 0, File: 111}).
   143  		SetContents([]byte("[e2e::FileUpdateTransaction]")).
   144  		Execute(env.Client)
   145  
   146  	require.NoError(t, err)
   147  
   148  	receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
   149  	require.NoError(t, err)
   150  
   151  	assert.Equal(t, StatusFeeScheduleFilePartUploaded, receipt.Status)
   152  }