-
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(accountAllowanceDeleteTransaction): Implement AccountAllowanceDeleteTransaction
E2E tests: TCK
#316
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Rob Walworth <[email protected]>
await JSONRPCRequest(this, "createToken", { | ||
name: "testname", | ||
symbol: "testsymbol", | ||
treasuryAccountId: ownerAccountId, | ||
supplyKey, | ||
tokenType: "nft", | ||
commonTransactionParams: { | ||
signers: [ownerPrivateKey], | ||
}, | ||
}) | ||
).tokenId; | ||
|
||
tokenId3 = ( | ||
await JSONRPCRequest(this, "createToken", { | ||
name: "testname", | ||
symbol: "testsymbol", | ||
treasuryAccountId: ownerAccountId, | ||
supplyKey, | ||
tokenType: "nft", | ||
commonTransactionParams: { | ||
signers: [ownerPrivateKey], | ||
}, | ||
}) | ||
).tokenId; | ||
|
||
const metadata = ["1234"]; | ||
|
||
tokenId1SerialNumber = ( | ||
await JSONRPCRequest(this, "mintToken", { | ||
tokenId: tokenId1, | ||
metadata, | ||
commonTransactionParams: { | ||
signers: [supplyKey], | ||
}, | ||
}) | ||
).serialNumbers[0]; | ||
|
||
tokenId2SerialNumber = ( | ||
await JSONRPCRequest(this, "mintToken", { | ||
tokenId: tokenId2, | ||
metadata, | ||
commonTransactionParams: { | ||
signers: [supplyKey], | ||
}, | ||
}) | ||
).serialNumbers[0]; | ||
|
||
tokenId3SerialNumber = ( | ||
await JSONRPCRequest(this, "mintToken", { | ||
tokenId: tokenId3, | ||
metadata, | ||
commonTransactionParams: { | ||
signers: [supplyKey], | ||
}, | ||
}) | ||
).serialNumbers[0]; | ||
|
||
await JSONRPCRequest(this, "associateToken", { | ||
accountId: spenderAccountId, | ||
tokenIds: [tokenId1, tokenId2, tokenId3], | ||
commonTransactionParams: { | ||
signers: [spenderPrivateKey], | ||
}, | ||
}); | ||
|
||
await JSONRPCRequest(this, "approveAllowance", { | ||
allowances: [ | ||
{ | ||
ownerAccountId, | ||
spenderAccountId, | ||
nft: { | ||
tokenId: tokenId1, | ||
serialNumbers: [tokenId1SerialNumber], | ||
}, | ||
}, | ||
{ | ||
ownerAccountId, | ||
spenderAccountId, | ||
nft: { | ||
tokenId: tokenId2, | ||
serialNumbers: [tokenId2SerialNumber], | ||
}, | ||
}, | ||
{ | ||
ownerAccountId, | ||
spenderAccountId, | ||
nft: { | ||
tokenId: tokenId3, | ||
serialNumbers: [tokenId3SerialNumber], | ||
}, | ||
}, | ||
], | ||
commonTransactionParams: { | ||
signers: [ownerPrivateKey], | ||
}, | ||
}); | ||
}); | ||
afterEach(async function () { | ||
await JSONRPCRequest(this, "reset"); | ||
}); |
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.
We can optimize the code by creating helper functions for repetitive tasks, such as generating keys, creating accounts, creating tokens, minting tokens, and approving allowances. This will reduces redundancy and makes the code more concise.
let foundAllowance = false; | ||
for (let i = 0; i < mirrorNodeInfo.nfts.length; i++) { | ||
if ( | ||
mirrorNodeInfo.nfts[i].account_id === ownerAccountId && | ||
mirrorNodeInfo.nfts[i].spender === spenderAccountId && | ||
mirrorNodeInfo.nfts[i].token_id === tokenId && | ||
mirrorNodeInfo.nfts[i].serial_number.toString() === serialNumber | ||
) { | ||
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.nfts.length; i++) { | |
if ( | |
mirrorNodeInfo.nfts[i].account_id === ownerAccountId && | |
mirrorNodeInfo.nfts[i].spender === spenderAccountId && | |
mirrorNodeInfo.nfts[i].token_id === tokenId && | |
mirrorNodeInfo.nfts[i].serial_number.toString() === serialNumber | |
) { | |
foundAllowance = true; | |
break; | |
} | |
} | |
const foundAllowance = mirrorNodeInfo.allowances.some( | |
allowance => | |
allowance.owner === ownerAccountId && | |
allowance.spender === spenderAccountId && | |
allowance.tokenId === tokenId && | |
allowance.amount.toString() === amount | |
); |
The comments I’ve written here, along with the ones I could write, are quite similar to those in the AccountAllowanceApprove PR, so I decided not to repeat them. They follow the same structure and approach, so you’ll notice many of the same points in both |
Tests are passing in JS! 🎉 |
Description:
This PR implements the
AccountAllowanceDeleteTransaction
tests documented indocs/test-specifications/crypto-service/AccountAllowanceDeleteTransaction.md
.Related issue(s):
#315
Checklist