diff --git a/account_delete_transaction_e2e_test.go b/account_delete_transaction_e2e_test.go index 1cf8f1bd..86d9ba42 100644 --- a/account_delete_transaction_e2e_test.go +++ b/account_delete_transaction_e2e_test.go @@ -222,7 +222,8 @@ func TestIntegrationAccountDeleteTransactionCannotDeleteWithPendingAirdrops(t *t nftSerials := receipt.SerialNumbers // Create receiver - receiver, _ := createAccountHelper(t, &env, 0) + receiver, _, err := createAccount(&env) + require.NoError(t, err) // Airdrop the tokens airdropTx, err := NewTokenAirdropTransaction(). diff --git a/max_auto_associations_e2e_test.go b/max_auto_associations_e2e_test.go index fa93e085..a052f276 100644 --- a/max_auto_associations_e2e_test.go +++ b/max_auto_associations_e2e_test.go @@ -30,23 +30,6 @@ import ( * */ -func createAccountHelper(t *testing.T, env *IntegrationTestEnv, maxAutoAssociations int32) (AccountID, PrivateKey) { - newKey, err := PrivateKeyGenerateEd25519() - require.NoError(t, err) - - accountCreate, err := NewAccountCreateTransaction(). - SetKey(newKey). - SetNodeAccountIDs(env.NodeAccountIDs). - SetInitialBalance(NewHbar(3)). - SetMaxAutomaticTokenAssociations(maxAutoAssociations). - Execute(env.Client) - require.NoError(t, err) - - receipt, err := accountCreate.SetValidateStatus(true).GetReceipt(env.Client) - require.NoError(t, err) - return *receipt.AccountID, newKey -} - // Limited max auto association tests func TestLimitedMaxAutoAssociationsFungibleTokensFlow(t *testing.T) { t.Parallel() @@ -61,7 +44,10 @@ func TestLimitedMaxAutoAssociationsFungibleTokensFlow(t *testing.T) { require.NoError(t, err) // account create with 1 max auto associations - receiver, _ := createAccountHelper(t, &env, 1) + receiver, _, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(1) + }) + require.NoError(t, err) // transfer token1 to receiver account tokenTransferTransaction, err := NewTransferTransaction(). @@ -106,7 +92,10 @@ func TestLimitedMaxAutoAssociationsNFTsFlow(t *testing.T) { serials := receipt.SerialNumbers // account create with 1 max auto associations - receiver, _ := createAccountHelper(t, &env, 1) + receiver, _, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(1) + }) + require.NoError(t, err) // transfer nftID1 nfts to receiver account tokenTransferTransaction, err := NewTransferTransaction(). @@ -137,8 +126,9 @@ func TestLimitedMaxAutoAssociationsFungibleTokensWithManualAssociate(t *testing. // create token1 tokenID1, err := createFungibleToken(&env) - // account create with 0 max auto associations - receiver, key := createAccountHelper(t, &env, 0) + // account create + receiver, key, err := createAccount(&env) + require.NoError(t, err) frozenAssociateTxn, err := NewTokenAssociateTransaction().SetAccountID(receiver).AddTokenID(tokenID1).FreezeWith(env.Client) require.NoError(t, err) @@ -178,8 +168,9 @@ func TestLimitedMaxAutoAssociationsNFTsManualAssociate(t *testing.T) { serials := receipt.SerialNumbers - // account create with 0 max auto associations - receiver, key := createAccountHelper(t, &env, 0) + // account create + receiver, key, err := createAccount(&env) + require.NoError(t, err) frozenAssociateTxn, err := NewTokenAssociateTransaction().SetAccountID(receiver).AddTokenID(nftID1).FreezeWith(env.Client) require.NoError(t, err) @@ -208,9 +199,15 @@ func TestUnlimitedMaxAutoAssociationsExecutes(t *testing.T) { env := NewIntegrationTestEnv(t) // account create with unlimited max auto associations - verify it executes - createAccountHelper(t, &env, -1) + _, _, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(-1) + }) + require.NoError(t, err) - accountID, newKey := createAccountHelper(t, &env, 100) + accountID, newKey, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(100) + }) + require.NoError(t, err) // update the account with unlimited max auto associations accountUpdateFrozen, err := NewAccountUpdateTransaction(). @@ -239,9 +236,15 @@ func TestUnlimitedMaxAutoAssociationsAllowsToTransferFungibleTokens(t *testing.T require.NoError(t, err) // account create with unlimited max auto associations - accountID1, _ := createAccountHelper(t, &env, -1) + accountID1, _, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(-1) + }) + require.NoError(t, err) // create account with 100 max auto associations - accountID2, newKey := createAccountHelper(t, &env, 100) + accountID2, newKey, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(100) + }) + require.NoError(t, err) // update the account with unlimited max auto associations accountUpdateFrozen, err := NewAccountUpdateTransaction(). @@ -309,7 +312,10 @@ func TestUnlimitedMaxAutoAssociationsAllowsToTransferFungibleTokensWithDecimals( require.NoError(t, err) // account create with unlimited max auto associations - accountID, _ := createAccountHelper(t, &env, -1) + accountID, _, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(-1) + }) + require.NoError(t, err) // transfer some token1 and token2 tokens tokenTransferTransaction, err := NewTransferTransaction(). @@ -335,7 +341,10 @@ func TestUnlimitedMaxAutoAssociationsAllowsToTransferFromFungibleTokens(t *testi env := NewIntegrationTestEnv(t) // create spender account which will be approved to spend - spender, spenderKey := createAccountHelper(t, &env, 10) + spender, spenderKey, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(10) + }) + require.NoError(t, err) // create token1 tokenID1, err := createFungibleToken(&env) @@ -346,7 +355,10 @@ func TestUnlimitedMaxAutoAssociationsAllowsToTransferFromFungibleTokens(t *testi require.NoError(t, err) // account create with unlimited max auto associations - accountID, _ := createAccountHelper(t, &env, -1) + accountID, _, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(-1) + }) + require.NoError(t, err) // approve the spender approve, err := NewAccountAllowanceApproveTransaction(). @@ -405,8 +417,15 @@ func TestUnlimitedMaxAutoAssociationsAllowsToTransferNFTs(t *testing.T) { serials := receipt.SerialNumbers // account create with unlimited max auto associations - accountID1, _ := createAccountHelper(t, &env, -1) - accountID2, newKey := createAccountHelper(t, &env, 100) + accountID1, _, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(-1) + }) + require.NoError(t, err) + + accountID2, newKey, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(100) + }) + require.NoError(t, err) // account update with unlimited max auto associations accountUpdateFrozen, err := NewAccountUpdateTransaction(). @@ -467,7 +486,10 @@ func TestUnlimitedMaxAutoAssociationsAllowsToTransferFromNFTs(t *testing.T) { env := NewIntegrationTestEnv(t) // create spender account which will be approved to spend - spender, spenderKey := createAccountHelper(t, &env, 10) + spender, spenderKey, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(10) + }) + require.NoError(t, err) // create 2 NFT collections and mint 10 NFTs for each collection nftID1, err := createNft(&env) @@ -487,7 +509,10 @@ func TestUnlimitedMaxAutoAssociationsAllowsToTransferFromNFTs(t *testing.T) { serials := receipt.SerialNumbers // account create with unlimited max auto associations - accountID, _ := createAccountHelper(t, &env, -1) + accountID, _, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(-1) + }) + require.NoError(t, err) // approve the spender approve, err := NewAccountAllowanceApproveTransaction(). @@ -548,7 +573,10 @@ func TestUnlimitedMaxAutoAssociationsFailsWithInvalid(t *testing.T) { require.ErrorContains(t, err, "INVALID_MAX_AUTO_ASSOCIATIONS") // create account with 100 max auto associations - accountID, newKey := createAccountHelper(t, &env, 100) + accountID, newKey, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(100) + }) + require.NoError(t, err) // account update with -2 max auto associations - should fail accountUpdateFrozen, err := NewAccountUpdateTransaction(). diff --git a/token_airdrop_transaction_e2e_test.go b/token_airdrop_transaction_e2e_test.go index 90f85d78..4b1a0586 100644 --- a/token_airdrop_transaction_e2e_test.go +++ b/token_airdrop_transaction_e2e_test.go @@ -53,7 +53,10 @@ func TestIntegrationTokenAirdropTransactionTransfersTokensWhenAssociated(t *test nftSerials := receipt.SerialNumbers // Create receiver with unlimited auto associations and receiverSig = false - receiver, _ := createAccountHelper(t, &env, -1) + receiver, _, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(-1) + }) + require.NoError(t, err) // Airdrop the tokens airdropTx, err := NewTokenAirdropTransaction(). @@ -105,8 +108,9 @@ func TestIntegrationTokenAirdropTransactionPendingTokensWhenNotAssociated(t *tes nftSerials := receipt.SerialNumbers - // Create receiver with 0 auto associations and receiverSig = false - receiver, _ := createAccountHelper(t, &env, 0) + // Create receiver + receiver, _, err := createAccount(&env) + require.NoError(t, err) // Airdrop the tokens airdropTx, err := NewTokenAirdropTransaction(). @@ -217,7 +221,10 @@ func TestIntegrationTokenAirdropTransactionWithCustomFees(t *testing.T) { defer CloseIntegrationTestEnv(env, nil) // Create receiver with unlimited auto associations and receiverSig = false - receiver, _ := createAccountHelper(t, &env, -1) + receiver, _, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(-1) + }) + require.NoError(t, err) // create fungible token with custom fee another token customFeeTokenID, err := createFungibleToken(&env) @@ -253,7 +260,10 @@ func TestIntegrationTokenAirdropTransactionWithCustomFees(t *testing.T) { tokenID := receipt.TokenID // create sender account with unlimited associations and send some tokens to it - sender, senderKey := createAccountHelper(t, &env, -1) + sender, senderKey, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(-1) + }) + require.NoError(t, err) // associate the token to the sender frozenTxn, err := NewTokenAssociateTransaction(). @@ -372,10 +382,16 @@ func TestIntegrationTokenAirdropTransactionWithNoBalanceFT(t *testing.T) { tokenID, _ := createFungibleToken(&env) // create spender and approve to it some tokens - spender, spenderKey := createAccountHelper(t, &env, -1) + spender, spenderKey, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(-1) + }) + require.NoError(t, err) // create sender - sender, senderKey := createAccountHelper(t, &env, -1) + sender, senderKey, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(-1) + }) + require.NoError(t, err) // transfer ft to sender txResponse, err := NewTransferTransaction(). @@ -430,10 +446,16 @@ func TestIntegrationTokenAirdropTransactionWithNoBalanceNFT(t *testing.T) { nftSerials := receipt.SerialNumbers // create spender and approve to it some tokens - spender, spenderKey := createAccountHelper(t, &env, -1) + spender, spenderKey, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(-1) + }) + require.NoError(t, err) // create sender - sender, senderKey := createAccountHelper(t, &env, -1) + sender, senderKey, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(-1) + }) + require.NoError(t, err) // transfer ft to sender txResponse, err = NewTransferTransaction(). @@ -476,9 +498,12 @@ func TestIntegrationTokenAirdropTransactionWithInvalidBody(t *testing.T) { tokenID, _ := createFungibleToken(&env) // create receiver - receiver, _ := createAccountHelper(t, &env, -1) + receiver, _, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(-1) + }) + require.NoError(t, err) - _, err := NewTokenAirdropTransaction(). + _, err = NewTokenAirdropTransaction(). Execute(env.Client) require.ErrorContains(t, err, "EMPTY_TOKEN_TRANSFER_BODY") diff --git a/token_cancel_airdrop_transaction_e2e_test.go b/token_cancel_airdrop_transaction_e2e_test.go index 89b20782..5e81a2a6 100644 --- a/token_cancel_airdrop_transaction_e2e_test.go +++ b/token_cancel_airdrop_transaction_e2e_test.go @@ -55,8 +55,9 @@ func TestIntegrationTokenCancelAirdropCanExecute(t *testing.T) { require.NoError(t, err) nftSerials := receipt.SerialNumbers - // Create receiver with 0 auto associations - receiver, _ := createAccountHelper(t, &env, 0) + // Create receiver + receiver, _, err := createAccount(&env) + require.NoError(t, err) // Airdrop the tokens airdropTx, err := NewTokenAirdropTransaction(). @@ -117,11 +118,13 @@ func TestIntegrationTokenCancelAirdropMultipleReceivers(t *testing.T) { require.NoError(t, err) nftSerials := receipt.SerialNumbers - // Create receiver1 with 0 auto associations - receiver1, receiver1Key := createAccountHelper(t, &env, 0) + // Create receiver1 + receiver1, receiver1Key, err := createAccount(&env) + require.NoError(t, err) - // Create receiver2 with 0 auto associations - receiver2, receiver2Key := createAccountHelper(t, &env, 0) + // Create receiver2 + receiver2, receiver2Key, err := createAccount(&env) + require.NoError(t, err) // Airdrop the tokens to both airdropTx, err := NewTokenAirdropTransaction(). @@ -193,8 +196,9 @@ func TestIntegrationTokenCancelAirdropMultipleAirdropTxns(t *testing.T) { require.NoError(t, err) nftSerials := receipt.SerialNumbers - // Create receiver with 0 auto associations - receiver, _ := createAccountHelper(t, &env, 0) + // Create receiver + receiver, _, err := createAccount(&env) + require.NoError(t, err) // Airdrop some of the tokens airdropTx, err := NewTokenAirdropTransaction(). @@ -272,10 +276,12 @@ func TestIntegrationTokenCancelAirdropCannotCancelNonExistingAirdrop(t *testing. tokenID, err := createFungibleToken(&env) require.NoError(t, err) - // Create receiver with 0 auto associations - receiver, _ := createAccountHelper(t, &env, 0) + // Create receiver + receiver, _, err := createAccount(&env) + require.NoError(t, err) // Create random account - randomAccount, _ := createAccountHelper(t, &env, 0) + randomAccount, _, err := createAccount(&env) + require.NoError(t, err) // Airdrop the tokens airdropTx, err := NewTokenAirdropTransaction(). @@ -303,8 +309,9 @@ func TestIntegrationTokenCancelAirdropCannotCancelAlreadyCanceledAirdrop(t *test tokenID, err := createFungibleToken(&env) require.NoError(t, err) - // Create receiver with 0 auto associations - receiver, _ := createAccountHelper(t, &env, 0) + // Create receiver + receiver, _, err := createAccount(&env) + require.NoError(t, err) // Airdrop the tokens airdropTx, err := NewTokenAirdropTransaction(). @@ -359,8 +366,9 @@ func TestIntegrationTokenCancelAirdropCannotCancelWithDupblicateEntries(t *testi tokenID, err := createFungibleToken(&env) require.NoError(t, err) - // Create receiver with 0 auto associations - receiver, _ := createAccountHelper(t, &env, 0) + // Create receiver + receiver, _, err := createAccount(&env) + require.NoError(t, err) // Airdrop the tokens airdropTx, err := NewTokenAirdropTransaction(). @@ -391,8 +399,9 @@ func TestIntegrationTokenCancelAirdropCanCancelWithPausedToken(t *testing.T) { tokenID, err := createFungibleToken(&env) require.NoError(t, err) - // Create receiver with 0 auto associations - receiver, _ := createAccountHelper(t, &env, 0) + // Create receiver + receiver, _, err := createAccount(&env) + require.NoError(t, err) // Airdrop the tokens airdropTx, err := NewTokenAirdropTransaction(). @@ -431,8 +440,9 @@ func TestIntegrationTokenCancelAirdropCanCancelWithDeletedToken(t *testing.T) { tokenID, err := createFungibleToken(&env) require.NoError(t, err) - // Create receiver with 0 auto associations - receiver, _ := createAccountHelper(t, &env, 0) + // Create receiver + receiver, _, err := createAccount(&env) + require.NoError(t, err) // Airdrop the tokens airdropTx, err := NewTokenAirdropTransaction(). @@ -471,8 +481,9 @@ func TestIntegrationTokenCancelAirdropCanCancelWithFrozenToken(t *testing.T) { tokenID, err := createFungibleToken(&env) require.NoError(t, err) - // Create receiver with 0 auto associations - receiver, receiverKey := createAccountHelper(t, &env, 0) + // Create receiver + receiver, receiverKey, err := createAccount(&env) + require.NoError(t, err) // Airdrop the tokens airdropTx, err := NewTokenAirdropTransaction(). diff --git a/token_claim_airdrop_transaction_e2e_test.go b/token_claim_airdrop_transaction_e2e_test.go index 65543c57..1be0990e 100644 --- a/token_claim_airdrop_transaction_e2e_test.go +++ b/token_claim_airdrop_transaction_e2e_test.go @@ -56,7 +56,8 @@ func TestIntegrationTokenClaimAirdropCanExecute(t *testing.T) { nftSerials := receipt.SerialNumbers // Create receiver with 0 auto associations - receiver, receiverKey := createAccountHelper(t, &env, 0) + receiver, receiverKey, err := createAccount(&env) + require.NoError(t, err) // Airdrop the tokens airdropTx, err := NewTokenAirdropTransaction(). @@ -126,11 +127,13 @@ func TestIntegrationTokenClaimAirdropMultipleReceivers(t *testing.T) { require.NoError(t, err) nftSerials := receipt.SerialNumbers - // Create receiver1 with 0 auto associations - receiver1, receiver1Key := createAccountHelper(t, &env, 0) + // Create receiver1 + receiver1, receiver1Key, err := createAccount(&env) + require.NoError(t, err) - // Create receiver2 with 0 auto associations - receiver2, receiver2Key := createAccountHelper(t, &env, 0) + // Create receiver2 + receiver2, receiver2Key, err := createAccount(&env) + require.NoError(t, err) // Airdrop the tokens to both airdropTx, err := NewTokenAirdropTransaction(). @@ -220,8 +223,9 @@ func TestIntegrationTokenClaimAirdropMultipleAirdropTxns(t *testing.T) { require.NoError(t, err) nftSerials := receipt.SerialNumbers - // Create receiver with 0 auto associations - receiver, receiverKey := createAccountHelper(t, &env, 0) + // Create receiver + receiver, receiverKey, err := createAccount(&env) + require.NoError(t, err) // Airdrop some of the tokens airdropTx, err := NewTokenAirdropTransaction(). @@ -299,8 +303,9 @@ func TestIntegrationTokenClaimAirdropCannotClaimNonExistingAirdrop(t *testing.T) tokenID, err := createFungibleToken(&env) require.NoError(t, err) - // Create receiver with 0 auto associations - receiver, _ := createAccountHelper(t, &env, 0) + // Create receiver + receiver, _, err := createAccount(&env) + require.NoError(t, err) // Airdrop the tokens airdropTx, err := NewTokenAirdropTransaction(). @@ -330,8 +335,9 @@ func TestIntegrationTokenClaimAirdropCannotClaimAlreadyClaimedAirdrop(t *testing tokenID, err := createFungibleToken(&env) require.NoError(t, err) - // Create receiver with 0 auto associations - receiver, receiverKey := createAccountHelper(t, &env, 0) + // Create receiver + receiver, receiverKey, err := createAccount(&env) + require.NoError(t, err) // Airdrop the tokens airdropTx, err := NewTokenAirdropTransaction(). @@ -386,8 +392,9 @@ func TestIntegrationTokenClaimAirdropCannotClaimWithDupblicateEntries(t *testing tokenID, err := createFungibleToken(&env) require.NoError(t, err) - // Create receiver with 0 auto associations - receiver, receiverKey := createAccountHelper(t, &env, 0) + // Create receiver + receiver, receiverKey, err := createAccount(&env) + require.NoError(t, err) // Airdrop the tokens airdropTx, err := NewTokenAirdropTransaction(). @@ -418,8 +425,9 @@ func TestIntegrationTokenClaimAirdropCannotClaimWithPausedToken(t *testing.T) { tokenID, err := createFungibleToken(&env) require.NoError(t, err) - // Create receiver with 0 auto associations - receiver, receiverKey := createAccountHelper(t, &env, 0) + // Create receiver + receiver, receiverKey, err := createAccount(&env) + require.NoError(t, err) // Airdrop the tokens airdropTx, err := NewTokenAirdropTransaction(). @@ -458,8 +466,9 @@ func TestIntegrationTokenClaimAirdropCannotClaimWithDeletedToken(t *testing.T) { tokenID, err := createFungibleToken(&env) require.NoError(t, err) - // Create receiver with 0 auto associations - receiver, receiverKey := createAccountHelper(t, &env, 0) + // Create receiver + receiver, receiverKey, err := createAccount(&env) + require.NoError(t, err) // Airdrop the tokens airdropTx, err := NewTokenAirdropTransaction(). @@ -498,8 +507,9 @@ func TestIntegrationTokenClaimAirdropCannotClaimWithFrozenToken(t *testing.T) { tokenID, err := createFungibleToken(&env) require.NoError(t, err) - // Create receiver with 0 auto associations - receiver, receiverKey := createAccountHelper(t, &env, 0) + // Create receiver + receiver, receiverKey, err := createAccount(&env) + require.NoError(t, err) // Airdrop the tokens airdropTx, err := NewTokenAirdropTransaction(). diff --git a/token_reject_flow_e2e_test.go b/token_reject_flow_e2e_test.go index e9086a74..bbc49849 100644 --- a/token_reject_flow_e2e_test.go +++ b/token_reject_flow_e2e_test.go @@ -55,7 +55,8 @@ func TestIntegrationTokenRejectFlowCanExecuteForFungibleToken(t *testing.T) { require.NoError(t, err) // create receiver account with 0 auto associations - receiver, key := createAccountHelper(t, &env, 0) + receiver, key, err := createAccount(&env) + require.NoError(t, err) // associate the tokens with the receiver frozenAssociateTxn, err := NewTokenAssociateTransaction().SetAccountID(receiver).AddTokenID(tokenID1).AddTokenID(tokenID2).FreezeWith(env.Client) @@ -142,7 +143,8 @@ func TestIntegrationTokenRejectFlowCanExecuteForNFT(t *testing.T) { serials := receipt.SerialNumbers // create receiver account - receiver, key := createAccountHelper(t, &env, 0) + receiver, key, err := createAccount(&env) + require.NoError(t, err) // associate the tokens with the receiver frozenAssociateTxn, err := NewTokenAssociateTransaction().SetAccountID(receiver).AddTokenID(nftID1).AddTokenID(nftID2).FreezeWith(env.Client) @@ -224,7 +226,8 @@ func TestIntegrationTokenRejectFlowFailsWhenNotRejectingAllNFTs(t *testing.T) { serials := receipt.SerialNumbers // create receiver account - receiver, key := createAccountHelper(t, &env, 0) + receiver, key, err := createAccount(&env) + require.NoError(t, err) // associate the tokens with the receiver frozenAssociateTxn, err := NewTokenAssociateTransaction().SetAccountID(receiver).AddTokenID(nftID1).AddTokenID(nftID2).FreezeWith(env.Client) diff --git a/token_reject_transaction_e2e_test.go b/token_reject_transaction_e2e_test.go index 7e71c42a..1c9119e5 100644 --- a/token_reject_transaction_e2e_test.go +++ b/token_reject_transaction_e2e_test.go @@ -41,7 +41,10 @@ func TestIntegrationTokenRejectTransactionCanExecuteForFungibleToken(t *testing. require.NoError(t, err) // create receiver account with auto associations - receiver, key := createAccountHelper(t, &env, 100) + receiver, key, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(100) + }) + require.NoError(t, err) // transfer fts to the receiver tx, err := NewTransferTransaction(). @@ -102,7 +105,10 @@ func TestIntegrationTokenRejectTransactionCanExecuteForNFT(t *testing.T) { serials := receipt.SerialNumbers // create receiver account with auto associations - receiver, key := createAccountHelper(t, &env, 100) + receiver, key, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(100) + }) + require.NoError(t, err) // transfer nfts to the receiver tx, err := NewTransferTransaction(). @@ -169,7 +175,10 @@ func TestIntegrationTokenRejectTransactionCanExecuteForFTAndNFTAtTheSameTime(t * serials := receipt.SerialNumbers // create receiver account with auto associations - receiver, key := createAccountHelper(t, &env, 100) + receiver, key, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(100) + }) + require.NoError(t, err) // transfer fts to the receiver tx1, err := NewTransferTransaction(). @@ -264,7 +273,10 @@ func TestIntegrationTokenRejectTransactionReceiverSigRequired(t *testing.T) { serials := receipt.SerialNumbers // create receiver account with auto associations - receiver, key := createAccountHelper(t, &env, 100) + receiver, key, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(100) + }) + require.NoError(t, err) // transfer nft to the receiver frozenTransfer, err := NewTransferTransaction(). @@ -358,7 +370,10 @@ func TestIntegrationTokenRejectTransactionTokenFrozen(t *testing.T) { serials := receipt.SerialNumbers // create receiver account with auto associations - receiver, key := createAccountHelper(t, &env, 100) + receiver, key, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(100) + }) + require.NoError(t, err) // transfer nft to the receiver tx, err := NewTransferTransaction(). @@ -438,7 +453,10 @@ func TestIntegrationTokenRejectTransactionTokenPaused(t *testing.T) { serials := receipt.SerialNumbers // create receiver account with auto associations - receiver, key := createAccountHelper(t, &env, 100) + receiver, key, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(100) + }) + require.NoError(t, err) // transfer nft to the receiver tx, err := NewTransferTransaction(). @@ -509,9 +527,15 @@ func TestIntegrationTokenRejectTransactionDoesNotRemoveAllowanceFT(t *testing.T) tokenID, err := createFungibleToken(&env) require.NoError(t, err) // create receiver account with auto associations - receiver, key := createAccountHelper(t, &env, 100) + receiver, key, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(100) + }) + require.NoError(t, err) // create spender account to be approved - spender, spenderKey := createAccountHelper(t, &env, 100) + spender, spenderKey, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(100) + }) + require.NoError(t, err) // transfer ft to the receiver tx, err := NewTransferTransaction(). @@ -595,9 +619,15 @@ func TestIntegrationTokenRejectTransactionDoesNotRemoveAllowanceNFT(t *testing.T env := NewIntegrationTestEnv(t) // create receiver account with auto associations - receiver, key := createAccountHelper(t, &env, 100) + receiver, key, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(100) + }) + require.NoError(t, err) // create spender account to be approved - spender, spenderKey := createAccountHelper(t, &env, 100) + spender, spenderKey, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(100) + }) + require.NoError(t, err) // create nft with treasury nftID, err := createNft(&env) require.NoError(t, err) @@ -702,7 +732,10 @@ func TestIntegrationTokenRejectTransactionFailsWhenRejectingNFTWithTokenID(t *te serials := receipt.SerialNumbers // create receiver account with auto associations - receiver, key := createAccountHelper(t, &env, 100) + receiver, key, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(100) + }) + require.NoError(t, err) // transfer nfts to the receiver tx, err := NewTransferTransaction(). @@ -733,7 +766,10 @@ func TestIntegrationTokenRejectTransactionFailsWithTokenReferenceRepeated(t *tes require.NoError(t, err) // create receiver account with auto associations - receiver, key := createAccountHelper(t, &env, 100) + receiver, key, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(100) + }) + require.NoError(t, err) // transfer ft to the receiver tx, err := NewTransferTransaction(). @@ -790,7 +826,10 @@ func TestIntegrationTokenRejectTransactionFailsWhenOwnerHasNoBalance(t *testing. tokenID, err := createFungibleToken(&env) require.NoError(t, err) // create receiver account with auto associations - receiver, key := createAccountHelper(t, &env, 100) + receiver, key, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(100) + }) + require.NoError(t, err) // skip the transfer // associate the receiver @@ -913,7 +952,10 @@ func TestIntegrationTokenRejectTransactionFailsWithReferenceSizeExceeded(t *test env := NewIntegrationTestEnv(t) // create receiver account with auto associations - receiver, key := createAccountHelper(t, &env, 100) + receiver, key, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(100) + }) + require.NoError(t, err) // create fungible token with treasury tokenID, err := createFungibleToken(&env) @@ -977,7 +1019,10 @@ func TestIntegrationTokenRejectTransactionFailsWithInvalidSignature(t *testing.T require.NoError(t, err) // create receiver account with auto associations - receiver, _ := createAccountHelper(t, &env, 100) + receiver, _, err := createAccount(&env, func(tx *AccountCreateTransaction) { + tx.SetMaxAutomaticTokenAssociations(100) + }) + require.NoError(t, err) // craete helper key otherKey, err := PrivateKeyGenerateEd25519() diff --git a/utilities_for_test.go b/utilities_for_test.go index a73b15d9..76281c17 100644 --- a/utilities_for_test.go +++ b/utilities_for_test.go @@ -323,3 +323,35 @@ func createFungibleToken(env *IntegrationTestEnv, opts ...TokenCreateTransaction } return *receipt.TokenID, err } + +type AccountCreateTransactionCustomizer func(transaction *AccountCreateTransaction) + +func createAccount(env *IntegrationTestEnv, opts ...AccountCreateTransactionCustomizer) (AccountID, PrivateKey, error) { + newKey, err := PrivateKeyGenerateEd25519() + + if err != nil { + return AccountID{}, PrivateKey{}, err + } + + accountCreate := NewAccountCreateTransaction(). + SetKey(newKey). + SetNodeAccountIDs(env.NodeAccountIDs). + SetInitialBalance(NewHbar(1)) + + for _, opt := range opts { + opt(accountCreate) + } + + accountCreateExec, err := accountCreate.Execute(env.Client) + if err != nil { + return AccountID{}, PrivateKey{}, err + } + + receipt, err := accountCreateExec.SetValidateStatus(true).GetReceipt(env.Client) + + if err != nil { + return AccountID{}, PrivateKey{}, err + } + + return *receipt.AccountID, newKey, err +}