-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(accountAllowanceApproveTransaction): Implement AccountAllowanceApproveTransaction
E2E tests: TCK
#314
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Rob Walworth <[email protected]>
Signed-off-by: Rob Walworth <[email protected]>
Signed-off-by: Rob Walworth <[email protected]>
Signed-off-by: Rob Walworth <[email protected]>
|
||
// TODO: Get mirror node interface with OpenAPI | ||
async getNftAllowances(accountId: string): Promise<any> { | ||
const url = `${this.mirrorNodeRestJavaUrl}/api/v1/accounts/${accountId}/allowances/nfts`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add the mirrorNodeRestJavaUrl
value inside the .env examples.
let foundAllowance = false; | ||
for (let i = 0; i < mirrorNodeInfo.allowances.length; i++) { | ||
if ( | ||
mirrorNodeInfo.allowances[i].owner === ownerAccountId && | ||
mirrorNodeInfo.allowances[i].spender === spenderAccountId && | ||
mirrorNodeInfo.allowances[i].amount.toString() === amount | ||
) { | ||
foundAllowance = true; | ||
break; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let foundAllowance = false; | |
for (let i = 0; i < mirrorNodeInfo.allowances.length; i++) { | |
if ( | |
mirrorNodeInfo.allowances[i].owner === ownerAccountId && | |
mirrorNodeInfo.allowances[i].spender === spenderAccountId && | |
mirrorNodeInfo.allowances[i].amount.toString() === amount | |
) { | |
foundAllowance = true; | |
break; | |
} | |
} | |
const foundAllowance = mirrorNodeInfo.allowances.some( | |
allowance => | |
allowance.owner === ownerAccountId && | |
allowance.spender === spenderAccountId && | |
allowance.amount.toString() === amount | |
); |
await JSONRPCRequest(this, "reset"); | ||
}); | ||
|
||
async function verifyHbarAllowance( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please put this function into the helper directory?
let foundAllowance = false; | ||
for (let i = 0; i < mirrorNodeInfo.allowances.length; i++) { | ||
if ( | ||
mirrorNodeInfo.allowances[i].owner === ownerAccountId && | ||
mirrorNodeInfo.allowances[i].spender === spenderAccountId && | ||
mirrorNodeInfo.allowances[i].token_id === tokenId && | ||
mirrorNodeInfo.allowances[i].amount.toString() === amount | ||
) { | ||
foundAllowance = true; | ||
break; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let foundAllowance = false; | |
for (let i = 0; i < mirrorNodeInfo.allowances.length; i++) { | |
if ( | |
mirrorNodeInfo.allowances[i].owner === ownerAccountId && | |
mirrorNodeInfo.allowances[i].spender === spenderAccountId && | |
mirrorNodeInfo.allowances[i].token_id === tokenId && | |
mirrorNodeInfo.allowances[i].amount.toString() === amount | |
) { | |
foundAllowance = true; | |
break; | |
} | |
} | |
const foundAllowance = mirrorNodeInfo.allowances.some( | |
allowance => | |
allowance.owner === ownerAccountId && | |
allowance.spender === spenderAccountId && | |
allowance.tokenId === tokenId && | |
allowance.amount.toString() === amount | |
); |
expect(foundAllowance).to.be.true; | ||
} | ||
|
||
async function verifyTokenAllowance( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please put this function into the helper directory?
expect(foundAllowance).to.be.true; | ||
} | ||
|
||
async function verifyNftAllowance( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please put this function into the helper directory?
expect(foundAllowance).to.equal(allowanceExists); | ||
} | ||
|
||
async function verifyApprovedForAllAllowance( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Could you please put this function into the helper directory?
- Do the same as the previous examples in the loop.
- I think those functions could be arrow.
await JSONRPCRequest(this, "approveAllowance", { | ||
allowances: [ | ||
{ | ||
ownerAccountId, | ||
spenderAccountId, | ||
nft: { | ||
tokenId, | ||
serialNumbers: ["1", "2", "3"], | ||
}, | ||
}, | ||
], | ||
commonTransactionParams: { | ||
signers: [ownerPrivateKey], | ||
}, | ||
}); | ||
|
||
const serialNumbers = ["1", "2", "3"]; | ||
await JSONRPCRequest(this, "approveAllowance", { | ||
allowances: [ | ||
{ | ||
ownerAccountId, | ||
spenderAccountId: accountId, | ||
nft: { | ||
tokenId, | ||
serialNumbers, | ||
}, | ||
}, | ||
], | ||
commonTransactionParams: { | ||
signers: [ownerPrivateKey], | ||
}, | ||
}); | ||
|
||
await retryOnError(async () => { | ||
await verifyNftAllowance( | ||
true, | ||
ownerAccountId, | ||
accountId, | ||
tokenId, | ||
serialNumbers[0], | ||
); | ||
}); | ||
|
||
await retryOnError(async () => { | ||
await verifyNftAllowance( | ||
true, | ||
ownerAccountId, | ||
accountId, | ||
tokenId, | ||
serialNumbers[1], | ||
); | ||
}); | ||
|
||
await retryOnError(async () => { | ||
await verifyNftAllowance( | ||
true, | ||
ownerAccountId, | ||
accountId, | ||
tokenId, | ||
serialNumbers[2], | ||
); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also move some of those helper functions to the helper directory and reuse them throughout the file wherever the same logic appears.
Repeat this logic for also:
(#1) Approves an NFT allowance to a spender account from an owner account
(#11) Approves an NFT allowance to a delegate spender account from a spender account with approved for all privileges from an owner account
await JSONRPCRequest(this, "approveAllowance", { | |
allowances: [ | |
{ | |
ownerAccountId, | |
spenderAccountId, | |
nft: { | |
tokenId, | |
serialNumbers: ["1", "2", "3"], | |
}, | |
}, | |
], | |
commonTransactionParams: { | |
signers: [ownerPrivateKey], | |
}, | |
}); | |
const serialNumbers = ["1", "2", "3"]; | |
await JSONRPCRequest(this, "approveAllowance", { | |
allowances: [ | |
{ | |
ownerAccountId, | |
spenderAccountId: accountId, | |
nft: { | |
tokenId, | |
serialNumbers, | |
}, | |
}, | |
], | |
commonTransactionParams: { | |
signers: [ownerPrivateKey], | |
}, | |
}); | |
await retryOnError(async () => { | |
await verifyNftAllowance( | |
true, | |
ownerAccountId, | |
accountId, | |
tokenId, | |
serialNumbers[0], | |
); | |
}); | |
await retryOnError(async () => { | |
await verifyNftAllowance( | |
true, | |
ownerAccountId, | |
accountId, | |
tokenId, | |
serialNumbers[1], | |
); | |
}); | |
await retryOnError(async () => { | |
await verifyNftAllowance( | |
true, | |
ownerAccountId, | |
accountId, | |
tokenId, | |
serialNumbers[2], | |
); | |
}); | |
const allowances = [ | |
// Owner account allowing spender account. | |
{ | |
ownerAccountId, | |
spenderAccountId, | |
nft: { tokenId, serialNumbers: ["1", "2", "3"] }, | |
}, | |
// Owner account allowing another spender account. | |
{ | |
ownerAccountId, | |
spenderAccountId: accountId, | |
nft: { tokenId, serialNumbers: ["1", "2", "3"] }, | |
}, | |
]; | |
// Approve allowances in bulk | |
for (const allowance of allowances) { | |
await JSONRPCRequest(this, "approveAllowance", { | |
allowances: [allowance], | |
commonTransactionParams: { | |
signers: [ownerPrivateKey], | |
}, | |
}); | |
} | |
// Consolidate verification for serial numbers | |
const verifyAllowance = async (accountId, serialNumbers) => { | |
for (const serialNumber of serialNumbers) { | |
await retryOnError(async () => { | |
await verifyNftAllowance(true, ownerAccountId, accountId, tokenId, serialNumber); | |
}); | |
} | |
}; | |
// Verify NFT allowances for the new account | |
await verifyAllowance(accountId, ["1", "2", "3"]); |
await JSONRPCRequest(this, "deleteAccount", { | ||
deleteAccountId: ownerAccountId, | ||
transferAccountId: process.env.OPERATOR_ACCOUNT_ID as string, | ||
commonTransactionParams: { | ||
signers: [ownerPrivateKey], | ||
}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add this part of logic to a helper function and re-use it, currently its repeated 5 times.
await JSONRPCRequest(this, "approveAllowance", { | ||
allowances: [ | ||
{ | ||
ownerAccountId, | ||
spenderAccountId, | ||
hbar: { | ||
amount, | ||
}, | ||
}, | ||
], | ||
commonTransactionParams: { | ||
signers: [ownerPrivateKey], | ||
}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add this part of logic to a helper function and re-use it, currently its repeated 4 times.
Tests are passing in JS! 🎉 |
Description:
This PR implements the
AccountAllowanceApproveTransaction
tests documented indocs/test-specifications/crypto-service/AccountAllowanceApproveTransaction.md
.Related issue(s):
#313
Checklist