github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/token_burn_transaction_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 "fmt" 28 "testing" 29 30 "github.com/stretchr/testify/assert" 31 32 "github.com/stretchr/testify/require" 33 ) 34 35 func TestIntegrationTokenBurnTransactionCanExecute(t *testing.T) { 36 t.Parallel() 37 env := NewIntegrationTestEnv(t) 38 39 newKey, err := PrivateKeyGenerateEd25519() 40 require.NoError(t, err) 41 42 newBalance := NewHbar(2) 43 44 assert.Equal(t, 2*HbarUnits.Hbar._NumberOfTinybar(), newBalance.tinybar) 45 46 resp, err := NewAccountCreateTransaction(). 47 SetKey(newKey.PublicKey()). 48 SetNodeAccountIDs(env.NodeAccountIDs). 49 SetInitialBalance(newBalance). 50 Execute(env.Client) 51 require.NoError(t, err) 52 53 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 54 require.NoError(t, err) 55 56 accountID := *receipt.AccountID 57 58 tokenID, err := createFungibleToken(&env) 59 require.NoError(t, err) 60 61 resp, err = NewTokenBurnTransaction(). 62 SetNodeAccountIDs([]AccountID{resp.NodeID}). 63 SetAmount(10). 64 SetTokenID(tokenID). 65 Execute(env.Client) 66 require.NoError(t, err) 67 68 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 69 require.NoError(t, err) 70 71 info, err := NewTokenInfoQuery(). 72 SetTokenID(tokenID). 73 SetNodeAccountIDs([]AccountID{resp.NodeID}). 74 Execute(env.Client) 75 require.NoError(t, err) 76 77 assert.Equal(t, uint64(999990), info.TotalSupply) 78 79 tx, err := NewAccountDeleteTransaction(). 80 SetAccountID(accountID). 81 SetTransferAccountID(env.Client.GetOperatorAccountID()). 82 SetNodeAccountIDs([]AccountID{resp.NodeID}). 83 FreezeWith(env.Client) 84 require.NoError(t, err) 85 86 resp, err = tx. 87 Sign(newKey). 88 Execute(env.Client) 89 require.NoError(t, err) 90 91 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 92 require.NoError(t, err) 93 94 err = CloseIntegrationTestEnv(env, &tokenID) 95 require.NoError(t, err) 96 } 97 98 func TestIntegrationTokenBurnTransactionNoAmount(t *testing.T) { 99 t.Parallel() 100 env := NewIntegrationTestEnv(t) 101 102 newKey, err := PrivateKeyGenerateEd25519() 103 require.NoError(t, err) 104 105 newBalance := NewHbar(2) 106 107 assert.Equal(t, 2*HbarUnits.Hbar._NumberOfTinybar(), newBalance.tinybar) 108 109 resp, err := NewAccountCreateTransaction(). 110 SetKey(newKey.PublicKey()). 111 SetNodeAccountIDs(env.NodeAccountIDs). 112 SetInitialBalance(newBalance). 113 Execute(env.Client) 114 require.NoError(t, err) 115 116 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 117 require.NoError(t, err) 118 119 accountID := *receipt.AccountID 120 121 tokenID, err := createFungibleToken(&env) 122 require.NoError(t, err) 123 124 resp2, err := NewTokenBurnTransaction(). 125 SetNodeAccountIDs([]AccountID{resp.NodeID}). 126 SetTokenID(tokenID). 127 Execute(env.Client) 128 receipt, err = resp2.SetValidateStatus(true).GetReceipt(env.Client) 129 // It is now possible to perform Zero Token Operations https://hips.hedera.com/hip/hip-564 130 require.NoError(t, err) 131 132 tx, err := NewAccountDeleteTransaction(). 133 SetAccountID(accountID). 134 SetTransferAccountID(env.Client.GetOperatorAccountID()). 135 FreezeWith(env.Client) 136 require.NoError(t, err) 137 138 resp, err = tx. 139 Sign(newKey). 140 Execute(env.Client) 141 require.NoError(t, err) 142 143 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 144 require.NoError(t, err) 145 146 err = CloseIntegrationTestEnv(env, &tokenID) 147 require.NoError(t, err) 148 } 149 150 func TestIntegrationTokenBurnTransactionNoTokenID(t *testing.T) { 151 t.Parallel() 152 env := NewIntegrationTestEnv(t) 153 154 newKey, err := PrivateKeyGenerateEd25519() 155 require.NoError(t, err) 156 157 newBalance := NewHbar(2) 158 159 assert.Equal(t, 2*HbarUnits.Hbar._NumberOfTinybar(), newBalance.tinybar) 160 161 resp, err := NewAccountCreateTransaction(). 162 SetKey(newKey.PublicKey()). 163 SetNodeAccountIDs(env.NodeAccountIDs). 164 SetInitialBalance(newBalance). 165 Execute(env.Client) 166 require.NoError(t, err) 167 168 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 169 require.NoError(t, err) 170 171 accountID := *receipt.AccountID 172 173 resp2, err := NewTokenBurnTransaction(). 174 SetNodeAccountIDs([]AccountID{resp.NodeID}). 175 SetAmount(10). 176 Execute(env.Client) 177 assert.Error(t, err) 178 if err != nil { 179 assert.Equal(t, fmt.Sprintf("exceptional precheck status INVALID_TOKEN_ID received for transaction %s", resp2.TransactionID), err.Error()) 180 } 181 182 tx, err := NewAccountDeleteTransaction(). 183 SetAccountID(accountID). 184 SetTransferAccountID(env.Client.GetOperatorAccountID()). 185 FreezeWith(env.Client) 186 require.NoError(t, err) 187 188 resp, err = tx. 189 Sign(newKey). 190 Execute(env.Client) 191 require.NoError(t, err) 192 193 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 194 require.NoError(t, err) 195 196 err = CloseIntegrationTestEnv(env, receipt.TokenID) 197 require.NoError(t, err) 198 } 199 200 func DisabledTestIntegrationTokenBurnTransactionTreasuryMustOwnBurnedNft(t *testing.T) { // nolint 201 t.Parallel() 202 env := NewIntegrationTestEnv(t) 203 204 newBalance := NewHbar(2) 205 206 assert.Equal(t, 2*HbarUnits.Hbar._NumberOfTinybar(), newBalance.tinybar) 207 208 tokenID, err := createNft(&env) 209 require.NoError(t, err) 210 211 metaData := []byte{50, 50} 212 213 mint, err := NewTokenMintTransaction(). 214 SetTokenID(tokenID). 215 SetMetadata(metaData). 216 Execute(env.Client) 217 require.NoError(t, err) 218 219 mintReceipt, err := mint.SetValidateStatus(true).GetReceipt(env.Client) 220 require.NoError(t, err) 221 222 newKey, err := PrivateKeyGenerateEd25519() 223 require.NoError(t, err) 224 225 resp, err := NewAccountCreateTransaction(). 226 SetKey(newKey). 227 SetNodeAccountIDs(env.NodeAccountIDs). 228 SetInitialBalance(NewHbar(2)). 229 Execute(env.Client) 230 require.NoError(t, err) 231 232 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 233 require.NoError(t, err) 234 235 freezeAssociate, err := NewTokenAssociateTransaction(). 236 SetAccountID(*receipt.AccountID). 237 SetTokenIDs(tokenID). 238 SetNodeAccountIDs(env.NodeAccountIDs). 239 FreezeWith(env.Client) 240 require.NoError(t, err) 241 242 freezeAssociate.Sign(newKey) 243 244 resp, err = freezeAssociate.Execute(env.Client) 245 require.NoError(t, err) 246 247 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 248 require.NoError(t, err) 249 250 resp, err = NewTokenBurnTransaction(). 251 SetSerialNumbers(mintReceipt.SerialNumbers). 252 SetTokenID(tokenID). 253 Execute(env.Client) 254 require.NoError(t, err) 255 256 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 257 require.NoError(t, err) 258 } 259 260 func DisabledTestIntegrationTokenBurnTransactionInvalidMetadata(t *testing.T) { // nolint 261 t.Parallel() 262 env := NewIntegrationTestEnv(t) 263 264 newBalance := NewHbar(2) 265 266 assert.Equal(t, 2*HbarUnits.Hbar._NumberOfTinybar(), newBalance.tinybar) 267 268 tokenID, err := createNft(&env) 269 require.NoError(t, err) 270 271 resp, err := NewTokenBurnTransaction(). 272 SetAmount(1). 273 SetTokenID(tokenID). 274 Execute(env.Client) 275 require.NoError(t, err) 276 277 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 278 assert.Error(t, err) 279 if err != nil { 280 assert.Equal(t, "exceptional receipt status: INVALID_TOKEN_BURN_METADATA", err.Error()) 281 } 282 }