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

     1  //go:build all || e2e
     2  // +build all e2e
     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  
    31  	"github.com/stretchr/testify/require"
    32  )
    33  
    34  func TestIntegrationTokenNftGetInfoByNftIDCanExecute(t *testing.T) { // nolint
    35  	t.Parallel()
    36  	env := NewIntegrationTestEnv(t)
    37  
    38  	newBalance := NewHbar(2)
    39  
    40  	assert.Equal(t, 2*HbarUnits.Hbar._NumberOfTinybar(), newBalance.tinybar)
    41  
    42  	tokenID, err := createNft(&env)
    43  	require.NoError(t, err)
    44  
    45  	metaData := []byte{50}
    46  
    47  	mint, err := NewTokenMintTransaction().
    48  		SetTokenID(tokenID).
    49  		SetMetadata(metaData).
    50  		Execute(env.Client)
    51  	require.NoError(t, err)
    52  
    53  	mintReceipt, err := mint.SetValidateStatus(true).GetReceipt(env.Client)
    54  	require.NoError(t, err)
    55  
    56  	nftID := tokenID.Nft(mintReceipt.SerialNumbers[0])
    57  
    58  	info, err := NewTokenNftInfoQuery().
    59  		SetNftID(nftID).
    60  		Execute(env.Client)
    61  	require.NoError(t, err)
    62  
    63  	value := false
    64  	for _, nftInfo := range info {
    65  		if tokenID.String() == nftInfo.NftID.TokenID.String() {
    66  			value = true
    67  		}
    68  	}
    69  	assert.Truef(t, value, "token nft transfer transaction failed")
    70  	assert.Equal(t, len(info), 1)
    71  	assert.Equal(t, info[0].NftID, nftID)
    72  	assert.Equal(t, info[0].Metadata[0], byte(50))
    73  	parsedInfo, err := TokenNftInfoFromBytes(info[0].ToBytes())
    74  	assert.NoError(t, err)
    75  	assert.Equal(t, parsedInfo, info[0])
    76  }