Skip to content

Commit

Permalink
chore: fix approve + transferFrom func
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Ivanov <ivanivanov.ii726@gmail.com>
  • Loading branch information
0xivanov committed Jul 9, 2024
1 parent cfa15cc commit f71d392
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions max_auto_associations_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func createAccountHelper(t *testing.T, env *IntegrationTestEnv, maxAutoAssociati
accountCreate1, err := NewAccountCreateTransaction().
SetKey(newKey).
SetNodeAccountIDs(env.NodeAccountIDs).
SetInitialBalance(NewHbar(0)).
SetInitialBalance(NewHbar(3)).
SetMaxAutomaticTokenAssociations(maxAutoAssociations).
Execute(env.Client)
require.NoError(t, err)
Expand Down Expand Up @@ -217,7 +217,7 @@ func TestLimitedMaxAutoAssociationsNFTsManualAssociate(t *testing.T) {

serials := receipt.SerialNumbers

// account create with 1 max auto associations
// account create with 0 max auto associations
receiver, key := createAccountHelper(t, &env, 0)

frozenAssociateTxn, err := NewTokenAssociateTransaction().SetAccountID(receiver).AddTokenID(nftID1).FreezeWith(env.Client)
Expand Down Expand Up @@ -387,19 +387,23 @@ func TestUnlimitedMaxAutoAssociationsAllowsToTransferFromFungibleTokens(t *testi
require.NoError(t, err)

// transferFrom some token1 and token2 tokens
env.Client.SetOperator(spender, spenderKey)
tokenTransferTransactionFrozen, err := NewTransferTransaction().
AddTokenTransfer(tokenID1, env.Client.GetOperatorAccountID(), -1000).
AddApprovedTokenTransfer(tokenID1, env.OperatorID, -1000, true).
AddTokenTransfer(tokenID1, accountID, 1000).
AddTokenTransfer(tokenID2, env.Client.GetOperatorAccountID(), -1000).
AddApprovedTokenTransfer(tokenID2, env.OperatorID, -1000, true).
AddTokenTransfer(tokenID2, accountID, 1000).
FreezeWith(env.Client)
require.NoError(t, err)

tokenTransferTransaction, err := tokenTransferTransactionFrozen.Sign(spenderKey).Execute(env.Client)
require.NoError(t, err)

_, err = tokenTransferTransaction.SetValidateStatus(true).GetReceipt(env.Client)
require.NoError(t, err)

env.Client.SetOperator(env.OperatorID, env.OperatorKey)

// verify the balance of the receiver is 1000
tokenBalance, err := NewAccountBalanceQuery().SetAccountID(accountID).Execute(env.Client)
require.NoError(t, err)
Expand Down Expand Up @@ -512,19 +516,20 @@ func TestUnlimitedMaxAutoAssociationsAllowsToTransferFromNFTs(t *testing.T) {
// approve the spender
approve, err := NewAccountAllowanceApproveTransaction().
AddAllTokenNftApproval(nftID1, spender).
AddAllTokenNftApproval(nftID1, spender).
AddAllTokenNftApproval(nftID2, spender).
Execute(env.Client)
require.NoError(t, err)

_, err = approve.SetValidateStatus(true).GetReceipt(env.Client)
require.NoError(t, err)

// transferFrom some nft1 nfts
env.Client.SetOperator(spender, spenderKey)
tokenTransferTransactionFrozen, err := NewTransferTransaction().
AddNftTransfer(nftID1.Nft(serials[0]), env.OperatorID, accountID).
AddNftTransfer(nftID1.Nft(serials[1]), env.OperatorID, accountID).
AddNftTransfer(nftID2.Nft(serials[0]), env.OperatorID, accountID).
AddNftTransfer(nftID2.Nft(serials[1]), env.OperatorID, accountID).
AddApprovedNftTransfer(nftID1.Nft(serials[0]), env.OperatorID, accountID, true).
AddApprovedNftTransfer(nftID1.Nft(serials[1]), env.OperatorID, accountID, true).
AddApprovedNftTransfer(nftID2.Nft(serials[0]), env.OperatorID, accountID, true).
AddApprovedNftTransfer(nftID2.Nft(serials[1]), env.OperatorID, accountID, true).
FreezeWith(env.Client)
require.NoError(t, err)

Expand All @@ -533,6 +538,8 @@ func TestUnlimitedMaxAutoAssociationsAllowsToTransferFromNFTs(t *testing.T) {
_, err = tokenTransferTransaction.SetValidateStatus(true).GetReceipt(env.Client)
require.NoError(t, err)

env.Client.SetOperator(env.OperatorID, env.OperatorKey)

// verify the balance of the receiver is 2
tokenBalance, err := NewAccountBalanceQuery().SetAccountID(accountID).Execute(env.Client)
require.NoError(t, err)
Expand Down

0 comments on commit f71d392

Please sign in to comment.