github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/token_revoke_kyc_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 TestIntegrationTokenRevokeKycTransactionCanExecute(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 SetNodeAccountIDs(env.NodeAccountIDs). 48 SetKey(newKey.PublicKey()). 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, func(transaction *TokenCreateTransaction) { 59 transaction.SetKycKey(env.Client.GetOperatorPublicKey()) 60 }) 61 require.NoError(t, err) 62 63 transaction, err := NewTokenAssociateTransaction(). 64 SetNodeAccountIDs([]AccountID{resp.NodeID}). 65 SetAccountID(accountID). 66 SetTokenIDs(tokenID). 67 FreezeWith(env.Client) 68 require.NoError(t, err) 69 70 resp, err = transaction. 71 Sign(newKey). 72 Execute(env.Client) 73 require.NoError(t, err) 74 75 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 76 require.NoError(t, err) 77 78 resp, err = NewTokenGrantKycTransaction(). 79 SetNodeAccountIDs([]AccountID{resp.NodeID}). 80 SetAccountID(accountID). 81 SetTokenID(tokenID). 82 Execute(env.Client) 83 require.NoError(t, err) 84 85 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 86 require.NoError(t, err) 87 88 resp, err = NewTokenRevokeKycTransaction(). 89 SetNodeAccountIDs([]AccountID{resp.NodeID}). 90 SetAccountID(accountID). 91 SetTokenID(tokenID). 92 Execute(env.Client) 93 require.NoError(t, err) 94 95 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 96 require.NoError(t, err) 97 98 tx, err := NewAccountDeleteTransaction(). 99 SetAccountID(accountID). 100 SetTransferAccountID(env.Client.GetOperatorAccountID()). 101 FreezeWith(env.Client) 102 require.NoError(t, err) 103 104 resp, err = tx. 105 Sign(newKey). 106 Execute(env.Client) 107 require.NoError(t, err) 108 109 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 110 require.NoError(t, err) 111 112 err = CloseIntegrationTestEnv(env, &tokenID) 113 require.NoError(t, err) 114 } 115 116 func TestIntegrationTokenRevokeKycTransactionNoTokenID(t *testing.T) { 117 t.Parallel() 118 env := NewIntegrationTestEnv(t) 119 120 newKey, err := PrivateKeyGenerateEd25519() 121 require.NoError(t, err) 122 123 newBalance := NewHbar(2) 124 125 assert.Equal(t, 2*HbarUnits.Hbar._NumberOfTinybar(), newBalance.tinybar) 126 127 resp, err := NewAccountCreateTransaction(). 128 SetNodeAccountIDs(env.NodeAccountIDs). 129 SetKey(newKey.PublicKey()). 130 SetInitialBalance(newBalance). 131 Execute(env.Client) 132 require.NoError(t, err) 133 134 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 135 require.NoError(t, err) 136 137 accountID := *receipt.AccountID 138 139 tokenID, err := createFungibleToken(&env, func(transaction *TokenCreateTransaction) { 140 transaction.SetKycKey(env.Client.GetOperatorPublicKey()) 141 }) 142 require.NoError(t, err) 143 144 transaction, err := NewTokenAssociateTransaction(). 145 SetNodeAccountIDs([]AccountID{resp.NodeID}). 146 SetAccountID(accountID). 147 SetTokenIDs(tokenID). 148 FreezeWith(env.Client) 149 require.NoError(t, err) 150 151 resp, err = transaction. 152 Sign(newKey). 153 Execute(env.Client) 154 require.NoError(t, err) 155 156 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 157 require.NoError(t, err) 158 159 resp, err = NewTokenGrantKycTransaction(). 160 SetNodeAccountIDs([]AccountID{resp.NodeID}). 161 SetAccountID(accountID). 162 SetTokenID(tokenID). 163 Execute(env.Client) 164 require.NoError(t, err) 165 166 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 167 require.NoError(t, err) 168 169 resp2, err := NewTokenRevokeKycTransaction(). 170 SetNodeAccountIDs([]AccountID{resp.NodeID}). 171 SetAccountID(accountID). 172 Execute(env.Client) 173 assert.Error(t, err) 174 if err != nil { 175 assert.Equal(t, fmt.Sprintf("exceptional precheck status INVALID_TOKEN_ID received for transaction %s", resp2.TransactionID), err.Error()) 176 } 177 178 tx, err := NewAccountDeleteTransaction(). 179 SetAccountID(accountID). 180 SetTransferAccountID(env.Client.GetOperatorAccountID()). 181 FreezeWith(env.Client) 182 require.NoError(t, err) 183 184 resp, err = tx. 185 Sign(newKey). 186 Execute(env.Client) 187 require.NoError(t, err) 188 189 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 190 require.NoError(t, err) 191 192 err = CloseIntegrationTestEnv(env, &tokenID) 193 require.NoError(t, err) 194 } 195 196 func TestIntegrationTokenRevokeKycTransactionNoAccountID(t *testing.T) { 197 t.Parallel() 198 env := NewIntegrationTestEnv(t) 199 200 newKey, err := PrivateKeyGenerateEd25519() 201 require.NoError(t, err) 202 203 newBalance := NewHbar(2) 204 205 assert.Equal(t, 2*HbarUnits.Hbar._NumberOfTinybar(), newBalance.tinybar) 206 207 resp, err := NewAccountCreateTransaction(). 208 SetNodeAccountIDs(env.NodeAccountIDs). 209 SetKey(newKey.PublicKey()). 210 SetInitialBalance(newBalance). 211 Execute(env.Client) 212 require.NoError(t, err) 213 214 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 215 require.NoError(t, err) 216 217 accountID := *receipt.AccountID 218 219 tokenID, err := createFungibleToken(&env, func(transaction *TokenCreateTransaction) { 220 transaction.SetKycKey(env.Client.GetOperatorPublicKey()) 221 }) 222 require.NoError(t, err) 223 224 transaction, err := NewTokenAssociateTransaction(). 225 SetNodeAccountIDs([]AccountID{resp.NodeID}). 226 SetAccountID(accountID). 227 SetTokenIDs(tokenID). 228 FreezeWith(env.Client) 229 require.NoError(t, err) 230 231 resp, err = transaction. 232 Sign(newKey). 233 Execute(env.Client) 234 require.NoError(t, err) 235 236 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 237 require.NoError(t, err) 238 239 resp, err = NewTokenGrantKycTransaction(). 240 SetNodeAccountIDs([]AccountID{resp.NodeID}). 241 SetAccountID(accountID). 242 SetTokenID(tokenID). 243 Execute(env.Client) 244 require.NoError(t, err) 245 246 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 247 require.NoError(t, err) 248 249 resp2, err := NewTokenRevokeKycTransaction(). 250 SetNodeAccountIDs([]AccountID{resp.NodeID}). 251 SetTokenID(tokenID). 252 Execute(env.Client) 253 assert.Error(t, err) 254 if err != nil { 255 assert.Equal(t, fmt.Sprintf("exceptional precheck status INVALID_ACCOUNT_ID received for transaction %s", resp2.TransactionID), err.Error()) 256 } 257 258 tx, err := NewAccountDeleteTransaction(). 259 SetAccountID(accountID). 260 SetTransferAccountID(env.Client.GetOperatorAccountID()). 261 FreezeWith(env.Client) 262 require.NoError(t, err) 263 264 resp, err = tx. 265 Sign(newKey). 266 Execute(env.Client) 267 require.NoError(t, err) 268 269 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 270 require.NoError(t, err) 271 272 err = CloseIntegrationTestEnv(env, &tokenID) 273 require.NoError(t, err) 274 }