github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/token_freeze_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 TestIntegrationTokenFreezeTransactionCanExecute(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 transaction, err := NewTokenAssociateTransaction(). 62 SetNodeAccountIDs([]AccountID{resp.NodeID}). 63 SetAccountID(accountID). 64 SetTokenIDs(tokenID). 65 FreezeWith(env.Client) 66 require.NoError(t, err) 67 68 resp, err = transaction. 69 Sign(newKey). 70 Execute(env.Client) 71 require.NoError(t, err) 72 73 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 74 require.NoError(t, err) 75 76 resp, err = NewTokenFreezeTransaction(). 77 SetNodeAccountIDs([]AccountID{resp.NodeID}). 78 SetAccountID(accountID). 79 SetTokenID(tokenID). 80 Execute(env.Client) 81 require.NoError(t, err) 82 83 receipt, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 84 require.NoError(t, err) 85 86 tx, err := NewAccountDeleteTransaction(). 87 SetAccountID(accountID). 88 SetTransferAccountID(env.Client.GetOperatorAccountID()). 89 FreezeWith(env.Client) 90 require.NoError(t, err) 91 92 resp, err = tx. 93 Sign(newKey). 94 Execute(env.Client) 95 require.NoError(t, err) 96 97 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 98 require.NoError(t, err) 99 100 err = CloseIntegrationTestEnv(env, &tokenID) 101 require.NoError(t, err) 102 } 103 104 func TestIntegrationTokenFreezeTransactionNoAccountID(t *testing.T) { 105 t.Parallel() 106 env := NewIntegrationTestEnv(t) 107 108 newKey, err := PrivateKeyGenerateEd25519() 109 require.NoError(t, err) 110 111 newBalance := NewHbar(2) 112 113 assert.Equal(t, 2*HbarUnits.Hbar._NumberOfTinybar(), newBalance.tinybar) 114 115 resp, err := NewAccountCreateTransaction(). 116 SetNodeAccountIDs(env.NodeAccountIDs). 117 SetKey(newKey.PublicKey()). 118 SetInitialBalance(newBalance). 119 Execute(env.Client) 120 require.NoError(t, err) 121 122 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 123 require.NoError(t, err) 124 125 accountID := *receipt.AccountID 126 127 tokenID, err := createFungibleToken(&env) 128 require.NoError(t, err) 129 130 transaction, err := NewTokenAssociateTransaction(). 131 SetNodeAccountIDs([]AccountID{resp.NodeID}). 132 SetAccountID(accountID). 133 SetTokenIDs(tokenID). 134 FreezeWith(env.Client) 135 require.NoError(t, err) 136 137 resp, err = transaction. 138 Sign(newKey). 139 Execute(env.Client) 140 require.NoError(t, err) 141 142 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 143 require.NoError(t, err) 144 145 resp, err = NewTokenFreezeTransaction(). 146 SetNodeAccountIDs([]AccountID{resp.NodeID}). 147 Execute(env.Client) 148 assert.Error(t, err) 149 if err != nil { 150 assert.Equal(t, fmt.Sprintf("exceptional precheck status INVALID_TOKEN_ID received for transaction %s", resp.TransactionID), err.Error()) 151 } 152 153 err = CloseIntegrationTestEnv(env, &tokenID) 154 require.NoError(t, err) 155 }