github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/file_id_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/assert"
    30  	"github.com/stretchr/testify/require"
    31  )
    32  
    33  func TestUnitFileIDChecksumFromString(t *testing.T) {
    34  	t.Parallel()
    35  
    36  	id, err := FileIDFromString("0.0.123-rmkyk")
    37  	require.NoError(t, err)
    38  
    39  	client, err := _NewMockClient()
    40  	client.SetLedgerID(*NewLedgerIDTestnet())
    41  	require.NoError(t, err)
    42  	id.ToStringWithChecksum(*client)
    43  	sol := id.ToSolidityAddress()
    44  	FileIDFromSolidityAddress(sol)
    45  	id.Validate(client)
    46  
    47  	pb := id._ToProtobuf()
    48  	_FileIDFromProtobuf(pb)
    49  
    50  	idByte := id.ToBytes()
    51  	FileIDFromBytes(idByte)
    52  
    53  	require.Equal(t, FileID{File: 111}.String(), FileIDForFeeSchedule().String())
    54  	require.Equal(t, FileID{File: 102}.String(), FileIDForAddressBook().String())
    55  	require.Equal(t, FileID{File: 112}.String(), FileIDForExchangeRate().String())
    56  
    57  	assert.Equal(t, id.File, uint64(123))
    58  }
    59  
    60  func TestUnitFileIDChecksumToString(t *testing.T) {
    61  	t.Parallel()
    62  
    63  	id := AccountID{
    64  		Shard:   50,
    65  		Realm:   150,
    66  		Account: 520,
    67  	}
    68  	assert.Equal(t, "50.150.520", id.String())
    69  }