github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/token_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/assert"
    31  )
    32  
    33  func TestUnitTokenInfo_Protobuf(t *testing.T) {
    34  	t.Parallel()
    35  
    36  	tokenInfo := setupTokenInfo()
    37  	pb := tokenInfo._ToProtobuf()
    38  	actual := _TokenInfoFromProtobuf(pb)
    39  
    40  	assertTokenInfo(t, tokenInfo, actual)
    41  }
    42  
    43  func TestUnitTokenInfo_Bytes(t *testing.T) {
    44  	t.Parallel()
    45  
    46  	tokenInfo := setupTokenInfo()
    47  	pb := tokenInfo.ToBytes()
    48  	actual, _ := TokenInfoFromBytes(pb)
    49  
    50  	assertTokenInfo(t, tokenInfo, actual)
    51  }
    52  
    53  func TestUnitTokenInfo_ProtobufCoverage(t *testing.T) {
    54  	t.Parallel()
    55  
    56  	tokenInfo := setupTokenInfo()
    57  
    58  	_true := true
    59  	_false := false
    60  
    61  	tokenInfo.DefaultKycStatus = &_false
    62  	tokenInfo.DefaultFreezeStatus = &_false
    63  	tokenInfo.PauseStatus = &_true
    64  
    65  	pb := tokenInfo._ToProtobuf()
    66  	actual := _TokenInfoFromProtobuf(pb)
    67  
    68  	assertTokenInfo(t, tokenInfo, actual)
    69  }
    70  
    71  func setupTokenInfo() TokenInfo {
    72  	adminPK, _ := PrivateKeyGenerate()
    73  	adminPubK := adminPK.PublicKey()
    74  
    75  	kycPK, _ := PrivateKeyGenerate()
    76  	kycPubK := kycPK.PublicKey()
    77  
    78  	freezePK, _ := PrivateKeyGenerate()
    79  	freezePubK := freezePK.PublicKey()
    80  
    81  	wipePK, _ := PrivateKeyGenerate()
    82  	wipePubK := wipePK.PublicKey()
    83  
    84  	supplyPK, _ := PrivateKeyGenerate()
    85  	supplyPubK := supplyPK.PublicKey()
    86  
    87  	pausePK, _ := PrivateKeyGenerate()
    88  	pausePubK := pausePK.PublicKey()
    89  
    90  	metadataPK, _ := PrivateKeyGenerate()
    91  	metadataPubK := metadataPK.PublicKey()
    92  
    93  	feeSchedulePK, _ := PrivateKeyGenerate()
    94  	feeSchedulePubK := feeSchedulePK.PublicKey()
    95  
    96  	accId, _ := AccountIDFromString("0.0.1111")
    97  
    98  	_true := true
    99  	_false := false
   100  	ledgerId := NewLedgerIDTestnet()
   101  	timeDuration := time.Duration(2230000) * time.Second
   102  
   103  	timeTime := time.Unix(1230000, 0)
   104  	tokenId, _ := TokenIDFromString("0.0.123")
   105  	feeCollectorAccountId, _ := AccountIDFromString("0.0.123")
   106  
   107  	customFees := []Fee{
   108  		NewCustomFixedFee().
   109  			SetAmount(1).
   110  			SetDenominatingTokenID(tokenId).
   111  			SetFeeCollectorAccountID(feeCollectorAccountId),
   112  	}
   113  
   114  	return TokenInfo{
   115  		TokenID:             tokenId,
   116  		Name:                "Test Token",
   117  		Symbol:              "TST",
   118  		Decimals:            8,
   119  		TotalSupply:         10000,
   120  		Treasury:            accId,
   121  		AdminKey:            adminPubK,
   122  		KycKey:              kycPubK,
   123  		FreezeKey:           freezePubK,
   124  		WipeKey:             wipePubK,
   125  		SupplyKey:           supplyPubK,
   126  		DefaultFreezeStatus: &_true,
   127  		DefaultKycStatus:    &_true,
   128  		Deleted:             false,
   129  		AutoRenewPeriod:     &timeDuration,
   130  		AutoRenewAccountID:  accId,
   131  		ExpirationTime:      &timeTime,
   132  		TokenMemo:           "test-memo",
   133  		TokenType:           TokenTypeFungibleCommon,
   134  		SupplyType:          TokenSupplyTypeInfinite,
   135  		MaxSupply:           10000000,
   136  		FeeScheduleKey:      feeSchedulePubK,
   137  		CustomFees:          customFees,
   138  		PauseKey:            pausePubK,
   139  		MetadataKey:         metadataPubK,
   140  		Metadata:            testMetadata,
   141  		PauseStatus:         &_false,
   142  		LedgerID:            *ledgerId,
   143  	}
   144  }
   145  
   146  func assertTokenInfo(t assert.TestingT, tokenInfo TokenInfo, actual TokenInfo) {
   147  	assert.Equal(t, tokenInfo.TokenID, actual.TokenID)
   148  	assert.Equal(t, tokenInfo.Name, actual.Name)
   149  	assert.Equal(t, tokenInfo.Symbol, actual.Symbol)
   150  	assert.Equal(t, tokenInfo.Decimals, actual.Decimals)
   151  	assert.Equal(t, tokenInfo.TotalSupply, actual.TotalSupply)
   152  	assert.Equal(t, tokenInfo.Treasury, actual.Treasury)
   153  	assert.Equal(t, tokenInfo.AdminKey, actual.AdminKey)
   154  	assert.Equal(t, tokenInfo.KycKey, actual.KycKey)
   155  	assert.Equal(t, tokenInfo.FreezeKey, actual.FreezeKey)
   156  	assert.Equal(t, tokenInfo.WipeKey, actual.WipeKey)
   157  	assert.Equal(t, tokenInfo.SupplyKey, actual.SupplyKey)
   158  	assert.Equal(t, tokenInfo.DefaultFreezeStatus, actual.DefaultFreezeStatus)
   159  	assert.Equal(t, tokenInfo.DefaultKycStatus, actual.DefaultKycStatus)
   160  	assert.Equal(t, tokenInfo.Deleted, actual.Deleted)
   161  	assert.Equal(t, tokenInfo.AutoRenewPeriod, actual.AutoRenewPeriod)
   162  	assert.Equal(t, tokenInfo.AutoRenewAccountID, actual.AutoRenewAccountID)
   163  	assert.Equal(t, tokenInfo.ExpirationTime, actual.ExpirationTime)
   164  	assert.Equal(t, tokenInfo.TokenMemo, actual.TokenMemo)
   165  	assert.Equal(t, tokenInfo.TokenType, actual.TokenType)
   166  	assert.Equal(t, tokenInfo.SupplyType, actual.SupplyType)
   167  	assert.Equal(t, tokenInfo.MaxSupply, actual.MaxSupply)
   168  	assert.Equal(t, tokenInfo.FeeScheduleKey, actual.FeeScheduleKey)
   169  	assert.Equal(t, tokenInfo.PauseKey, actual.PauseKey)
   170  	assert.Equal(t, tokenInfo.MetadataKey, actual.MetadataKey)
   171  	assert.Equal(t, tokenInfo.Metadata, actual.Metadata)
   172  	assert.Equal(t, tokenInfo.PauseStatus, actual.PauseStatus)
   173  	assert.Equal(t, tokenInfo.LedgerID, actual.LedgerID)
   174  }