github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/token_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 TestIntegrationTokenInfoQueryCanExecute(t *testing.T) { 35 t.Parallel() 36 env := NewIntegrationTestEnv(t) 37 38 tokenID, err := createFungibleToken(&env, func(transaction *TokenCreateTransaction) { 39 transaction. 40 SetTokenMetadata([]byte{1, 2, 3}). 41 SetKycKey(env.Client.GetOperatorPublicKey()). 42 SetDecimals(3) 43 }) 44 require.NoError(t, err) 45 46 info, err := NewTokenInfoQuery(). 47 SetMaxQueryPayment(NewHbar(2)). 48 SetTokenID(tokenID). 49 SetQueryPayment(NewHbar(1)). 50 Execute(env.Client) 51 require.NoError(t, err) 52 53 assert.Equal(t, info.TokenID, tokenID) 54 assert.Equal(t, info.Name, "ffff") 55 assert.Equal(t, info.Symbol, "F") 56 assert.Equal(t, info.Decimals, uint32(3)) 57 assert.Equal(t, info.Treasury, env.Client.GetOperatorAccountID()) 58 assert.NotNil(t, info.AdminKey) 59 assert.NotNil(t, info.KycKey) 60 assert.NotNil(t, info.FreezeKey) 61 assert.NotNil(t, info.WipeKey) 62 assert.NotNil(t, info.SupplyKey) 63 assert.Equal(t, info.AdminKey.String(), env.Client.GetOperatorPublicKey().String()) 64 assert.Equal(t, info.KycKey.String(), env.Client.GetOperatorPublicKey().String()) 65 assert.Equal(t, info.FreezeKey.String(), env.Client.GetOperatorPublicKey().String()) 66 assert.Equal(t, info.WipeKey.String(), env.Client.GetOperatorPublicKey().String()) 67 assert.Equal(t, info.SupplyKey.String(), env.Client.GetOperatorPublicKey().String()) 68 assert.Equal(t, info.MetadataKey.String(), env.Client.GetOperatorPublicKey().String()) 69 assert.Equal(t, info.Metadata, []byte{1, 2, 3}) 70 assert.False(t, *info.DefaultFreezeStatus) 71 assert.False(t, *info.DefaultKycStatus) 72 73 err = CloseIntegrationTestEnv(env, &tokenID) 74 require.NoError(t, err) 75 } 76 77 func TestIntegrationTokenInfoQueryGetCost(t *testing.T) { 78 t.Parallel() 79 env := NewIntegrationTestEnv(t) 80 81 tokenID, err := createFungibleToken(&env) 82 require.NoError(t, err) 83 84 infoQuery := NewTokenInfoQuery(). 85 SetMaxQueryPayment(NewHbar(1)). 86 SetTokenID(tokenID) 87 88 cost, err := infoQuery.GetCost(env.Client) 89 require.NoError(t, err) 90 91 _, err = infoQuery.SetQueryPayment(cost).Execute(env.Client) 92 require.NoError(t, err) 93 94 err = CloseIntegrationTestEnv(env, &tokenID) 95 require.NoError(t, err) 96 } 97 98 func TestIntegrationTokenInfoQuerySetBigMaxPayment(t *testing.T) { 99 t.Parallel() 100 env := NewIntegrationTestEnv(t) 101 102 tokenID, err := createFungibleToken(&env) 103 require.NoError(t, err) 104 105 infoQuery := NewTokenInfoQuery(). 106 SetMaxQueryPayment(NewHbar(1000000)). 107 SetTokenID(tokenID) 108 109 cost, err := infoQuery.GetCost(env.Client) 110 require.NoError(t, err) 111 112 _, err = infoQuery.SetQueryPayment(cost).Execute(env.Client) 113 require.NoError(t, err) 114 115 err = CloseIntegrationTestEnv(env, &tokenID) 116 require.NoError(t, err) 117 } 118 119 func TestIntegrationTokenInfoQuerySetSmallMaxPayment(t *testing.T) { 120 t.Parallel() 121 env := NewIntegrationTestEnv(t) 122 123 tokenID, err := createFungibleToken(&env) 124 require.NoError(t, err) 125 126 infoQuery := NewTokenInfoQuery(). 127 SetMaxQueryPayment(HbarFromTinybar(1)). 128 SetTokenID(tokenID) 129 130 cost, err := infoQuery.GetCost(env.Client) 131 require.NoError(t, err) 132 133 _, err = infoQuery.Execute(env.Client) 134 assert.Error(t, err) 135 if err != nil { 136 assert.Equal(t, "cost of TokenInfoQuery ("+cost.String()+") without explicit payment is greater than the max query payment of 1 tℏ", err.Error()) 137 } 138 139 err = CloseIntegrationTestEnv(env, &tokenID) 140 require.NoError(t, err) 141 } 142 143 func TestIntegrationTokenInfoQueryInsufficientCost(t *testing.T) { 144 t.Parallel() 145 env := NewIntegrationTestEnv(t) 146 147 tokenID, err := createFungibleToken(&env) 148 require.NoError(t, err) 149 150 infoQuery := NewTokenInfoQuery(). 151 SetMaxQueryPayment(NewHbar(1)). 152 SetTokenID(tokenID) 153 154 _, err = infoQuery.GetCost(env.Client) 155 require.NoError(t, err) 156 157 _, err = infoQuery.SetQueryPayment(HbarFromTinybar(1)).Execute(env.Client) 158 assert.Error(t, err) 159 if err != nil { 160 assert.Equal(t, "exceptional precheck status INSUFFICIENT_TX_FEE", err.Error()) 161 } 162 163 err = CloseIntegrationTestEnv(env, &tokenID) 164 require.NoError(t, err) 165 } 166 167 func TestIntegrationTokenInfoQueryNoPayment(t *testing.T) { 168 t.Parallel() 169 env := NewIntegrationTestEnv(t) 170 171 tokenID, err := createFungibleToken(&env, func(transaction *TokenCreateTransaction) { 172 transaction. 173 SetDecimals(3). 174 SetKycKey(env.Client.GetOperatorPublicKey()) 175 }) 176 require.NoError(t, err) 177 178 info, err := NewTokenInfoQuery(). 179 SetQueryPayment(NewHbar(1)). 180 SetTokenID(tokenID). 181 Execute(env.Client) 182 require.NoError(t, err) 183 184 assert.Equal(t, info.TokenID, tokenID) 185 assert.Equal(t, info.Name, "ffff") 186 assert.Equal(t, info.Symbol, "F") 187 assert.Equal(t, info.Decimals, uint32(3)) 188 assert.Equal(t, info.Treasury, env.Client.GetOperatorAccountID()) 189 assert.False(t, *info.DefaultFreezeStatus) 190 assert.False(t, *info.DefaultKycStatus) 191 192 err = CloseIntegrationTestEnv(env, &tokenID) 193 require.NoError(t, err) 194 } 195 196 func TestIntegrationTokenInfoQueryNoTokenID(t *testing.T) { 197 t.Parallel() 198 env := NewIntegrationTestEnv(t) 199 200 _, err := NewTokenInfoQuery(). 201 SetNodeAccountIDs(env.NodeAccountIDs). 202 SetQueryPayment(NewHbar(1)). 203 Execute(env.Client) 204 assert.Error(t, err) 205 if err != nil { 206 assert.Equal(t, "exceptional precheck status INVALID_TOKEN_ID", err.Error()) 207 } 208 209 err = CloseIntegrationTestEnv(env, nil) 210 require.NoError(t, err) 211 }