github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/multi_app_transfer_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/require" 30 ) 31 32 func TestIntegrationMultiAppTransfer(t *testing.T) { 33 t.Parallel() 34 env := NewIntegrationTestEnv(t) 35 36 txID := TransactionIDGenerate(env.OperatorID) 37 38 transaction, err := NewTransferTransaction(). 39 SetTransactionID(txID). 40 AddHbarTransfer(env.OperatorID, NewHbar(-1)). 41 AddHbarTransfer(AccountID{Account: 3}, NewHbar(1)). 42 FreezeWith(env.Client) 43 require.NoError(t, err) 44 45 txBytes, err := transaction.ToBytes() 46 require.NoError(t, err) 47 signedTxBytes, err := signingService(txBytes, env.OperatorKey) 48 require.NoError(t, err) 49 50 var signedTx TransferTransaction 51 tx, err := TransactionFromBytes(signedTxBytes) 52 require.NoError(t, err) 53 54 switch t := tx.(type) { 55 case TransferTransaction: 56 signedTx = t 57 default: 58 panic("Did not receive `TransferTransaction` back from signed bytes") 59 } 60 61 response, err := signedTx.Execute(env.Client) 62 require.NoError(t, err) 63 64 _, err = response.SetValidateStatus(true).GetReceipt(env.Client) 65 require.NoError(t, err) 66 67 err = CloseIntegrationTestEnv(env, nil) 68 require.NoError(t, err) 69 } 70 71 func signingService(txBytes []byte, key PrivateKey) ([]byte, error) { 72 var unsignedTx TransferTransaction 73 tx, err := TransactionFromBytes(txBytes) 74 if err != nil { 75 return txBytes, err 76 } 77 78 switch t := tx.(type) { 79 case TransferTransaction: 80 unsignedTx = t 81 default: 82 panic("Did not receive `TransferTransaction` back from signed bytes") 83 } 84 85 return unsignedTx. 86 Sign(key). 87 ToBytes() 88 }