Skip to content

Commit

Permalink
feat: create new account helper function (#1097)
Browse files Browse the repository at this point in the history
* feat: create new account helper function

Signed-off-by: Muhideen Mujeeb Adeoye <[email protected]>

* feat: remove old account helper function

Signed-off-by: Muhideen Mujeeb Adeoye <[email protected]>

* chore: replace old account helper function with new one

Signed-off-by: Muhideen Mujeeb Adeoye <[email protected]>

* fix: update createAccount function

Signed-off-by: Muhideen Mujeeb Adeoye <[email protected]>

* refactor: simplify account creation in test files

Signed-off-by: Muhideen Mujeeb Adeoye <[email protected]>

* fix: update createAccount helper to return proper value on error

Signed-off-by: Muhideen Mujeeb Adeoye <[email protected]>

* chore: remove space and replace with private key struct

Signed-off-by: Muhideen Mujeeb Adeoye <[email protected]>

* fix: address all issue with build error

Signed-off-by: Muhideen Mujeeb Adeoye <[email protected]>

---------

Signed-off-by: Muhideen Mujeeb Adeoye <[email protected]>
Co-authored-by: Ivan Ivanov <[email protected]>
  • Loading branch information
Mujhtech and 0xivanov authored Oct 11, 2024
1 parent c3b73b2 commit e7d0371
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 105 deletions.
3 changes: 2 additions & 1 deletion account_delete_transaction_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down
98 changes: 63 additions & 35 deletions max_auto_associations_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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().
Expand Down Expand Up @@ -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().
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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().
Expand Down Expand Up @@ -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().
Expand Down Expand Up @@ -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().
Expand All @@ -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)
Expand All @@ -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().
Expand Down Expand Up @@ -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().
Expand Down Expand Up @@ -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)
Expand All @@ -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().
Expand Down Expand Up @@ -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().
Expand Down
47 changes: 36 additions & 11 deletions token_airdrop_transaction_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down Expand Up @@ -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().
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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().
Expand Down Expand Up @@ -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().
Expand Down Expand Up @@ -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().
Expand Down Expand Up @@ -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")

Expand Down
Loading

0 comments on commit e7d0371

Please sign in to comment.