github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/transaction_record_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 TestIntegrationTransactionRecordQueryCanExecute(t *testing.T) { 35 t.Parallel() 36 env := NewIntegrationTestEnv(t) 37 38 newKey, err := PrivateKeyGenerateEd25519() 39 require.NoError(t, err) 40 41 newBalance := NewHbar(2) 42 43 assert.Equal(t, 2*HbarUnits.Hbar._NumberOfTinybar(), newBalance.tinybar) 44 45 tx, err := NewAccountCreateTransaction(). 46 SetKey(newKey.PublicKey()). 47 SetNodeAccountIDs(env.NodeAccountIDs). 48 SetInitialBalance(newBalance). 49 FreezeWith(env.Client) 50 require.NoError(t, err) 51 52 tx, err = tx.SignWithOperator(env.Client) 53 require.NoError(t, err) 54 55 resp, err := tx.Execute(env.Client) 56 require.NoError(t, err) 57 58 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 59 require.NoError(t, err) 60 61 record, err := NewTransactionRecordQuery(). 62 SetTransactionID(resp.TransactionID). 63 SetNodeAccountIDs([]AccountID{resp.NodeID}). 64 Execute(env.Client) 65 require.NoError(t, err) 66 67 accountID := *record.Receipt.AccountID 68 assert.NotNil(t, accountID) 69 70 recordBytes := record.ToBytes() 71 72 _, err = TransactionRecordFromBytes(recordBytes) 73 require.NoError(t, err) 74 75 transaction, err := NewAccountDeleteTransaction(). 76 SetNodeAccountIDs([]AccountID{resp.NodeID}). 77 SetAccountID(accountID). 78 SetTransferAccountID(env.Client.GetOperatorAccountID()). 79 FreezeWith(env.Client) 80 require.NoError(t, err) 81 82 resp, err = transaction. 83 Sign(newKey). 84 Execute(env.Client) 85 require.NoError(t, err) 86 87 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 88 require.NoError(t, err) 89 90 err = CloseIntegrationTestEnv(env, nil) 91 require.NoError(t, err) 92 } 93 94 func TestIntegrationTransactionRecordQueryReceiptPaymentZero(t *testing.T) { 95 t.Parallel() 96 env := NewIntegrationTestEnv(t) 97 98 newKey, err := PrivateKeyGenerateEd25519() 99 require.NoError(t, err) 100 101 newBalance := NewHbar(2) 102 103 assert.Equal(t, 2*HbarUnits.Hbar._NumberOfTinybar(), newBalance.tinybar) 104 105 tx, err := NewAccountCreateTransaction(). 106 SetKey(newKey.PublicKey()). 107 SetNodeAccountIDs(env.NodeAccountIDs). 108 SetInitialBalance(newBalance). 109 FreezeWith(env.Client) 110 require.NoError(t, err) 111 112 tx, err = tx.SignWithOperator(env.Client) 113 require.NoError(t, err) 114 115 resp, err := tx.Execute(env.Client) 116 require.NoError(t, err) 117 118 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 119 require.NoError(t, err) 120 121 record, err := NewTransactionRecordQuery(). 122 SetTransactionID(resp.TransactionID). 123 SetNodeAccountIDs([]AccountID{resp.NodeID}). 124 Execute(env.Client) 125 require.NoError(t, err) 126 127 accountID := *record.Receipt.AccountID 128 assert.NotNil(t, accountID) 129 130 transaction, err := NewAccountDeleteTransaction(). 131 SetNodeAccountIDs([]AccountID{resp.NodeID}). 132 SetAccountID(accountID). 133 SetTransferAccountID(env.Client.GetOperatorAccountID()). 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 err = CloseIntegrationTestEnv(env, nil) 146 require.NoError(t, err) 147 } 148 149 func TestIntegrationTransactionRecordQueryInsufficientFee(t *testing.T) { 150 t.Parallel() 151 env := NewIntegrationTestEnv(t) 152 153 newKey, err := PrivateKeyGenerateEd25519() 154 require.NoError(t, err) 155 156 newBalance := NewHbar(2) 157 158 assert.Equal(t, 2*HbarUnits.Hbar._NumberOfTinybar(), newBalance.tinybar) 159 160 tx, err := NewAccountCreateTransaction(). 161 SetKey(newKey.PublicKey()). 162 SetNodeAccountIDs(env.NodeAccountIDs). 163 SetInitialBalance(newBalance). 164 FreezeWith(env.Client) 165 require.NoError(t, err) 166 167 tx, err = tx.SignWithOperator(env.Client) 168 require.NoError(t, err) 169 170 resp, err := tx.Execute(env.Client) 171 require.NoError(t, err) 172 173 receipt, err := resp.SetIncludeChildren(true).GetReceipt(env.Client) 174 require.NoError(t, err) 175 176 _, err = NewTransactionRecordQuery(). 177 SetTransactionID(resp.TransactionID). 178 SetNodeAccountIDs([]AccountID{resp.NodeID}). 179 SetMaxQueryPayment(HbarFromTinybar(99999)). 180 SetQueryPayment(HbarFromTinybar(1)). 181 Execute(env.Client) 182 assert.Error(t, err) 183 if err != nil { 184 assert.Equal(t, "exceptional receipt status: INSUFFICIENT_TX_FEE", err.Error()) 185 } 186 187 accountID := receipt.AccountID 188 assert.NotNil(t, accountID) 189 190 transaction, err := NewAccountDeleteTransaction(). 191 SetNodeAccountIDs([]AccountID{resp.NodeID}). 192 SetAccountID(*accountID). 193 SetTransferAccountID(env.Client.GetOperatorAccountID()). 194 FreezeWith(env.Client) 195 require.NoError(t, err) 196 197 resp, err = transaction. 198 Sign(newKey). 199 Execute(env.Client) 200 require.NoError(t, err) 201 202 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 203 require.NoError(t, err) 204 205 err = CloseIntegrationTestEnv(env, nil) 206 require.NoError(t, err) 207 } 208 209 func DisabledTestIntegrationTokenTransferRecordsQuery(t *testing.T) { // nolint 210 t.Parallel() 211 env := NewIntegrationTestEnv(t) 212 213 newKey, err := PrivateKeyGenerateEd25519() 214 require.NoError(t, err) 215 216 newBalance := NewHbar(2) 217 218 assert.Equal(t, 2*HbarUnits.Hbar._NumberOfTinybar(), newBalance.tinybar) 219 220 resp, err := NewAccountCreateTransaction(). 221 SetNodeAccountIDs(env.NodeAccountIDs). 222 SetKey(newKey.PublicKey()). 223 SetInitialBalance(newBalance). 224 Execute(env.Client) 225 require.NoError(t, err) 226 227 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 228 require.NoError(t, err) 229 230 accountID := *receipt.AccountID 231 232 tokenID, err := createFungibleToken(&env, func(transaction *TokenCreateTransaction) { 233 transaction.SetCustomFees([]Fee{CustomFractionalFee{ 234 CustomFee: CustomFee{ 235 FeeCollectorAccountID: &env.OperatorID, 236 }, 237 Numerator: 1, 238 Denominator: 20, 239 MinimumAmount: 1, 240 MaximumAmount: 10, 241 }}) 242 }) 243 require.NoError(t, err) 244 245 transaction, err := NewTokenAssociateTransaction(). 246 SetNodeAccountIDs([]AccountID{resp.NodeID}). 247 SetAccountID(accountID). 248 SetTokenIDs(tokenID). 249 FreezeWith(env.Client) 250 require.NoError(t, err) 251 252 resp, err = transaction. 253 Sign(newKey). 254 Execute(env.Client) 255 require.NoError(t, err) 256 257 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 258 require.NoError(t, err) 259 260 resp, err = NewTokenGrantKycTransaction(). 261 SetNodeAccountIDs([]AccountID{resp.NodeID}). 262 SetAccountID(accountID). 263 SetTokenID(tokenID). 264 Execute(env.Client) 265 require.NoError(t, err) 266 267 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 268 require.NoError(t, err) 269 270 resp, err = NewTransferTransaction(). 271 SetNodeAccountIDs([]AccountID{resp.NodeID}). 272 AddTokenTransfer(tokenID, env.Client.GetOperatorAccountID(), -10). 273 AddTokenTransfer(tokenID, accountID, 10). 274 Execute(env.Client) 275 require.NoError(t, err) 276 277 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 278 require.NoError(t, err) 279 280 record, err := resp.GetRecord(env.Client) 281 require.NoError(t, err) 282 283 assert.Equal(t, len(record.TokenTransfers), 1) 284 assert.Equal(t, len(record.AssessedCustomFees), 0) 285 286 resp, err = NewTokenWipeTransaction(). 287 SetNodeAccountIDs([]AccountID{resp.NodeID}). 288 SetTokenID(tokenID). 289 SetAccountID(accountID). 290 SetAmount(10). 291 Execute(env.Client) 292 require.NoError(t, err) 293 294 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 295 require.NoError(t, err) 296 297 tx, err := NewAccountDeleteTransaction(). 298 SetAccountID(accountID). 299 SetTransferAccountID(env.Client.GetOperatorAccountID()). 300 FreezeWith(env.Client) 301 require.NoError(t, err) 302 303 resp, err = tx. 304 Sign(newKey). 305 Execute(env.Client) 306 require.NoError(t, err) 307 308 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 309 require.NoError(t, err) 310 } 311 312 func DisabledTestIntegrationTokenNftTransferRecordQuery(t *testing.T) { // nolint 313 t.Parallel() 314 env := NewIntegrationTestEnv(t) 315 316 newKey, err := PrivateKeyGenerateEd25519() 317 require.NoError(t, err) 318 319 newBalance := NewHbar(2) 320 321 assert.Equal(t, 2*HbarUnits.Hbar._NumberOfTinybar(), newBalance.tinybar) 322 323 resp, err := NewAccountCreateTransaction(). 324 SetNodeAccountIDs(env.NodeAccountIDs). 325 SetKey(newKey.PublicKey()). 326 SetInitialBalance(newBalance). 327 Execute(env.Client) 328 require.NoError(t, err) 329 330 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 331 require.NoError(t, err) 332 333 accountID := *receipt.AccountID 334 335 tokenID, err := createNft(&env) 336 require.NoError(t, err) 337 338 metaData := [][]byte{{50}, {50}} 339 340 mint, err := NewTokenMintTransaction(). 341 SetNodeAccountIDs([]AccountID{resp.NodeID}). 342 SetTokenID(tokenID). 343 SetMetadatas(metaData). 344 Execute(env.Client) 345 require.NoError(t, err) 346 347 mintReceipt, err := mint.SetValidateStatus(true).GetReceipt(env.Client) 348 require.NoError(t, err) 349 350 transaction, err := NewTokenAssociateTransaction(). 351 SetNodeAccountIDs([]AccountID{resp.NodeID}). 352 SetAccountID(accountID). 353 SetTokenIDs(tokenID). 354 FreezeWith(env.Client) 355 require.NoError(t, err) 356 357 resp, err = transaction. 358 Sign(newKey). 359 Execute(env.Client) 360 require.NoError(t, err) 361 362 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 363 require.NoError(t, err) 364 365 resp, err = NewTokenGrantKycTransaction(). 366 SetNodeAccountIDs([]AccountID{resp.NodeID}). 367 SetAccountID(accountID). 368 SetTokenID(tokenID). 369 Execute(env.Client) 370 require.NoError(t, err) 371 372 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 373 require.NoError(t, err) 374 375 resp, err = NewTransferTransaction(). 376 SetNodeAccountIDs([]AccountID{resp.NodeID}). 377 AddNftTransfer(tokenID.Nft(mintReceipt.SerialNumbers[0]), env.OperatorID, accountID). 378 AddNftTransfer(tokenID.Nft(mintReceipt.SerialNumbers[1]), env.OperatorID, accountID). 379 Execute(env.Client) 380 require.NoError(t, err) 381 382 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 383 require.NoError(t, err) 384 385 record, err := resp.GetRecord(env.Client) 386 require.NoError(t, err) 387 388 assert.Equal(t, len(record.NftTransfers), 1) 389 390 resp, err = NewTokenWipeTransaction(). 391 SetNodeAccountIDs([]AccountID{resp.NodeID}). 392 SetTokenID(tokenID). 393 SetAccountID(accountID). 394 SetSerialNumbers(mintReceipt.SerialNumbers). 395 Execute(env.Client) 396 require.NoError(t, err) 397 398 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 399 require.NoError(t, err) 400 401 tx, err := NewAccountDeleteTransaction(). 402 SetAccountID(accountID). 403 SetTransferAccountID(env.Client.GetOperatorAccountID()). 404 FreezeWith(env.Client) 405 require.NoError(t, err) 406 407 resp, err = tx. 408 Sign(newKey). 409 Execute(env.Client) 410 require.NoError(t, err) 411 412 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 413 require.NoError(t, err) 414 }