github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/transfer_transaction_unit_test.go (about)

     1  //go:build all || unit
     2  // +build all unit
     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 TestUnitTransferTransactionSetTokenTransferWithDecimals(t *testing.T) {
    33  	t.Parallel()
    34  
    35  	tokenID := TokenID{Token: 1}
    36  	senderAccountID := AccountID{Account: 2}
    37  	amount := int64(10)
    38  	decimals := uint32(5)
    39  
    40  	transaction := NewTransferTransaction().
    41  		AddTokenTransferWithDecimals(tokenID, senderAccountID, amount, decimals)
    42  
    43  	require.Equal(t, transaction.GetTokenIDDecimals()[tokenID], decimals)
    44  }
    45  
    46  func TestUnitTransferTransactionValidate(t *testing.T) {
    47  	t.Parallel()
    48  
    49  	client, err := _NewMockClient()
    50  	client.SetLedgerID(*NewLedgerIDTestnet())
    51  	require.NoError(t, err)
    52  	client.SetAutoValidateChecksums(true)
    53  	accountID, err := AccountIDFromString("0.0.123-esxsf")
    54  	require.NoError(t, err)
    55  
    56  	transfer := NewTransferTransaction().
    57  		AddHbarTransfer(accountID, HbarFromTinybar(1))
    58  
    59  	err = transfer.validateNetworkOnIDs(client)
    60  	require.NoError(t, err)
    61  }
    62  
    63  func TestUnitTransferTransactionValidateWrong(t *testing.T) {
    64  	t.Parallel()
    65  
    66  	client, err := _NewMockClient()
    67  	client.SetLedgerID(*NewLedgerIDTestnet())
    68  	require.NoError(t, err)
    69  	client.SetAutoValidateChecksums(true)
    70  	accountID, err := AccountIDFromString("0.0.123-rmkykd")
    71  	require.NoError(t, err)
    72  
    73  	transfer := NewTransferTransaction().
    74  		AddHbarTransfer(accountID, HbarFromTinybar(1))
    75  
    76  	err = transfer.validateNetworkOnIDs(client)
    77  	require.Error(t, err)
    78  }