Skip to content

Commit

Permalink
Added crypto_transfer_transaction_test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrix10 committed Oct 9, 2020
1 parent 9bb77fd commit 2181b9b
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions crypto_transfer_transaction_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package hedera

import (
"github.com/stretchr/testify/assert"
"os"
"strings"
"testing"
)

func TestSerializeCryptoTransferTransaction(t *testing.T) {
mockClient, err := newMockClient()
assert.NoError(t, err)

privateKey, err := PrivateKeyFromString(mockPrivateKey)
assert.NoError(t, err)

tx, err := NewCryptoTransferTransaction().
AddSender(AccountID{Account: 2}, HbarFromTinybar(100)).
AddRecipient(AccountID{Account: 3}, HbarFromTinybar(100)).
SetMaxTransactionFee(HbarFrom(1, HbarUnits.Hbar)).
SetTransactionID(testTransactionID).
FreezeWith(mockClient)

// tx, err := NewCryptoTransferTransaction().
// AddSender(AccountID{Account: 2}, HbarFromTinybar(100)).
// AddRecipient(AccountID{Account: 3}, HbarFromTinybar(100)).
// SetMaxTransactionFee(HbarFrom(1, HbarUnits.Hbar)).
// SetTransactionID(testTransactionID).
// Build(client)

assert.NoError(t, err)

tx.Sign(privateKey)

assert.Equal(t, `bodyBytes:"\n\016\n\010\010\334\311\007\020\333\237\t\022\002\030\003\022\002\030\003\030\200\302\327/\"\002\010xr\024\n\022\n\007\n\002\030\002\020\307\001\n\007\n\002\030\003\020\310\001"sigMap:<sigPair:<pubKeyPrefix:"\344\361\300\353L}\315\303\347\353\021p\263\010\212=\022\242\227\364\243\353\342\362\205\003\375g5F\355\216"ed25519:"\022&5\226\373\264\034]P\273%\354P\233k\315\231\013\337\274\254)\246+\322<\227+\273\214\212f\313\332i\027T4{\367\363UYn\n\217\253ep\004\366\203\017\272FUP\243\321/\035\235\032\013">>transactionID:<transactionValidStart:<seconds:124124nanos:151515>accountID:<accountNum:3>>nodeAccountID:<accountNum:3>transactionFee:100000000transactionValidDuration:<seconds:120>cryptoTransfer:<transfers:<accountAmounts:<accountID:<accountNum:2>amount:-100>accountAmounts:<accountID:<accountNum:3>amount:100>>>`, strings.ReplaceAll(strings.ReplaceAll(tx.String(), " ", ""), "\n", ""))}

func TestCryptoTransferTransaction_Execute(t *testing.T) {
client, err := ClientFromJsonFile(os.Getenv("CONFIG_FILE"))

if err != nil {
client = ClientForTestnet()
}

configOperatorID := os.Getenv("OPERATOR_ID")
configOperatorKey := os.Getenv("OPERATOR_KEY")

if configOperatorID != "" && configOperatorKey != "" {
operatorAccountID, err := AccountIDFromString(configOperatorID)
assert.NoError(t, err)

operatorKey, err := PrivateKeyFromString(configOperatorKey)
assert.NoError(t, err)

client.SetOperator(operatorAccountID, operatorKey)
}

txID, err := NewCryptoTransferTransaction().
AddSender(client.GetOperatorID(), NewHbar(1)).
AddRecipient(AccountID{Account: 3}, NewHbar(1)).
SetMaxTransactionFee(NewHbar(1)).
Execute(client)
assert.NoError(t, err)

println("TransactionID", txID.TransactionID.String())
//_, err = txID.GetReceipt(client)
//assert.NoError(t, err)
}

0 comments on commit 2181b9b

Please sign in to comment.