github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/token_reject_flow_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  	"time"
    29  
    30  	"github.com/stretchr/testify/assert"
    31  
    32  	"github.com/stretchr/testify/require"
    33  )
    34  
    35  func TestUnitTokenRejectFlowValidate(t *testing.T) {
    36  	t.Parallel()
    37  
    38  	client, err := _NewMockClient()
    39  	client.SetLedgerID(*NewLedgerIDTestnet())
    40  	require.NoError(t, err)
    41  	client.SetAutoValidateChecksums(true)
    42  	accountID, err := AccountIDFromString("0.0.123-esxsf")
    43  	require.NoError(t, err)
    44  	tokenID, err := TokenIDFromString("0.0.123-esxsf")
    45  	require.NoError(t, err)
    46  
    47  	tokenAssociate := NewTokenRejectFlow().
    48  		SetOwnerID(accountID).
    49  		SetTokenIDs(tokenID)
    50  
    51  	err = tokenAssociate.validateNetworkOnIDs(client)
    52  	require.NoError(t, err)
    53  }
    54  
    55  func TestUnitTokenRejectFlowValidateWrong(t *testing.T) {
    56  	t.Parallel()
    57  
    58  	client, err := _NewMockClient()
    59  	client.SetLedgerID(*NewLedgerIDTestnet())
    60  	require.NoError(t, err)
    61  	client.SetAutoValidateChecksums(true)
    62  	accountID, err := AccountIDFromString("0.0.123-rmkykd")
    63  	require.NoError(t, err)
    64  	tokenID, err := TokenIDFromString("0.0.123-rmkykd")
    65  	require.NoError(t, err)
    66  
    67  	tokenAssociate := NewTokenRejectFlow().
    68  		SetOwnerID(accountID).
    69  		SetTokenIDs(tokenID)
    70  
    71  	err = tokenAssociate.validateNetworkOnIDs(client)
    72  	assert.Error(t, err)
    73  	if err != nil {
    74  		assert.Equal(t, "network mismatch or wrong checksum given, given checksum: rmkykd, correct checksum esxsf, network: testnet", err.Error())
    75  	}
    76  }
    77  
    78  func TestUnitTokenRejectFlowGet(t *testing.T) {
    79  	t.Parallel()
    80  
    81  	tokenIDs := []TokenID{{Token: 3}, {Token: 5}, {Token: 7}}
    82  
    83  	nodeAccountID := []AccountID{{Account: 10}, {Account: 11}, {Account: 12}}
    84  	transactionID := TransactionIDGenerate(AccountID{Account: 324})
    85  
    86  	transaction, err := NewTokenRejectFlow().
    87  		SetTransactionID(transactionID).
    88  		SetNodeAccountIDs(nodeAccountID).
    89  		SetTokenIDs(tokenIDs...).
    90  		SetOwnerID(AccountID{Account: 7}).
    91  		SetMaxTransactionFee(NewHbar(10)).
    92  		SetTransactionMemo("").
    93  		SetTransactionValidDuration(60 * time.Second).
    94  		SetRegenerateTransactionID(false).
    95  		Freeze()
    96  	require.NoError(t, err)
    97  
    98  	transaction.GetTransactionID()
    99  	transaction.GetNodeAccountIDs()
   100  
   101  	_, err = transaction.GetTransactionHash()
   102  	require.NoError(t, err)
   103  
   104  	transaction.GetOwnerID()
   105  	transaction.GetTokenIDs()
   106  	transaction.GetMaxTransactionFee()
   107  	transaction.GetTransactionMemo()
   108  	transaction.GetRegenerateTransactionID()
   109  	_, err = transaction.GetSignatures()
   110  	require.NoError(t, err)
   111  	transaction.GetRegenerateTransactionID()
   112  	transaction.GetMaxTransactionFee()
   113  	transaction.GetRegenerateTransactionID()
   114  }
   115  
   116  func TestUnitTokenRejectFlowNothingSet(t *testing.T) {
   117  	t.Parallel()
   118  
   119  	nodeAccountID := []AccountID{{Account: 10}, {Account: 11}, {Account: 12}}
   120  	transactionID := TransactionIDGenerate(AccountID{Account: 324})
   121  
   122  	transaction, err := NewTokenRejectFlow().
   123  		SetTransactionID(transactionID).
   124  		SetNodeAccountIDs(nodeAccountID).
   125  		Freeze()
   126  	require.NoError(t, err)
   127  
   128  	transaction.GetTransactionID()
   129  	transaction.GetNodeAccountIDs()
   130  
   131  	_, err = transaction.GetTransactionHash()
   132  	require.NoError(t, err)
   133  
   134  	transaction.GetOwnerID()
   135  	transaction.GetTokenIDs()
   136  	transaction.GetMaxTransactionFee()
   137  	transaction.GetTransactionMemo()
   138  	transaction.GetRegenerateTransactionID()
   139  	_, err = transaction.GetSignatures()
   140  	require.NoError(t, err)
   141  	transaction.GetRegenerateTransactionID()
   142  	transaction.GetMaxTransactionFee()
   143  	transaction.GetRegenerateTransactionID()
   144  }
   145  
   146  func TestUnitTokenRejectFlowCoverage(t *testing.T) {
   147  	t.Parallel()
   148  
   149  	checksum := "dmqui"
   150  	grpc := time.Second * 30
   151  	token := TokenID{Token: 3, checksum: &checksum}
   152  	account := AccountID{Account: 3, checksum: &checksum}
   153  	nodeAccountID := []AccountID{{Account: 10}}
   154  	transactionID := TransactionIDGenerate(AccountID{Account: 324})
   155  
   156  	client, err := _NewMockClient()
   157  	client.SetLedgerID(*NewLedgerIDTestnet())
   158  	require.NoError(t, err)
   159  	client.SetAutoValidateChecksums(true)
   160  
   161  	transaction, err := NewTokenRejectFlow().
   162  		SetTransactionID(transactionID).
   163  		SetNodeAccountIDs(nodeAccountID).
   164  		SetTokenIDs(token).
   165  		AddTokenID(token).
   166  		SetOwnerID(account).
   167  		SetGrpcDeadline(&grpc).
   168  		SetMaxTransactionFee(NewHbar(3)).
   169  		SetMaxRetry(3).
   170  		SetMaxBackoff(time.Second * 30).
   171  		SetMinBackoff(time.Second * 10).
   172  		SetTransactionMemo("no").
   173  		SetTransactionValidDuration(time.Second * 30).
   174  		SetRegenerateTransactionID(false).
   175  		Freeze()
   176  	require.NoError(t, err)
   177  
   178  	err = transaction.validateNetworkOnIDs(client)
   179  	require.NoError(t, err)
   180  	_, err = transaction.Schedule()
   181  	require.NoError(t, err)
   182  	transaction.GetTransactionID()
   183  	transaction.GetNodeAccountIDs()
   184  	transaction.GetMaxRetry()
   185  	transaction.GetMaxTransactionFee()
   186  	transaction.GetMaxBackoff()
   187  	transaction.GetMinBackoff()
   188  	transaction.GetRegenerateTransactionID()
   189  
   190  	_, err = transaction.GetTransactionHash()
   191  	require.NoError(t, err)
   192  	transaction.GetMaxTransactionFee()
   193  	transaction.GetTransactionMemo()
   194  	transaction.GetRegenerateTransactionID()
   195  	transaction.GetTokenIDs()
   196  	transaction.GetOwnerID()
   197  	_, err = transaction.GetSignatures()
   198  	require.NoError(t, err)
   199  	transaction.getName()
   200  }