github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/account_info_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/require"
    31  )
    32  
    33  // The function checks the conversation methods on the AccountInfo struct. We check wether it is correctly converted to protobuf and back.
    34  func TestUnitAccountInfoToBytes(t *testing.T) {
    35  	t.Parallel()
    36  
    37  	accInfoOriginal := *_MockAccountInfo()
    38  	accInfoBytes := accInfoOriginal.ToBytes()
    39  
    40  	accInfoFromBytes, err := AccountInfoFromBytes(accInfoBytes)
    41  
    42  	require.NoError(t, err)
    43  	require.Equal(t, accInfoOriginal.AccountID, accInfoFromBytes.AccountID)
    44  	require.Equal(t, accInfoOriginal.ContractAccountID, accInfoFromBytes.ContractAccountID)
    45  	require.Equal(t, accInfoOriginal.Key, accInfoFromBytes.Key)
    46  	require.Equal(t, accInfoOriginal.LedgerID, accInfoFromBytes.LedgerID)
    47  }
    48  func _MockAccountInfo() *AccountInfo {
    49  	privateKey, _ := PrivateKeyFromString(mockPrivateKey)
    50  	accountID, _ := AccountIDFromString("0.0.123-esxsf")
    51  	accountID.checksum = nil
    52  
    53  	return &AccountInfo{
    54  		AccountID:                      accountID,
    55  		ContractAccountID:              "",
    56  		IsDeleted:                      false,
    57  		ProxyReceived:                  Hbar{},
    58  		Key:                            privateKey.PublicKey(),
    59  		Balance:                        HbarFromTinybar(100000000000),
    60  		GenerateSendRecordThreshold:    Hbar{},
    61  		GenerateReceiveRecordThreshold: Hbar{},
    62  		ReceiverSigRequired:            false,
    63  		ExpirationTime:                 time.Date(2222, 2, 2, 2, 2, 2, 2, time.Now().UTC().Location()),
    64  		AutoRenewPeriod:                time.Duration(time.Duration(5).Seconds()),
    65  		LiveHashes:                     nil,
    66  		AccountMemo:                    "",
    67  		OwnedNfts:                      0,
    68  		MaxAutomaticTokenAssociations:  0,
    69  		AliasKey:                       nil,
    70  		LedgerID:                       *NewLedgerIDTestnet(),
    71  		EthereumNonce:                  0,
    72  		StakingInfo:                    nil,
    73  	}
    74  
    75  }