Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rwalworth
Copy link
Contributor

Description:
This PR implements the AccountAllowanceDeleteTransaction tests documented in docs/test-specifications/crypto-service/AccountAllowanceDeleteTransaction.md.

Related issue(s):
#315

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

Signed-off-by: Rob Walworth <[email protected]>
@rwalworth rwalworth added the enhancement New feature or request label Dec 30, 2024
@rwalworth rwalworth self-assigned this Dec 30, 2024
@rwalworth rwalworth linked an issue Dec 30, 2024 that may be closed by this pull request
Comment on lines +19 to +180
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");
});
Copy link
Contributor

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.

Comment on lines +193 to +204
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;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
);

@ivaylogarnev-limechain
Copy link
Contributor

ivaylogarnev-limechain commented Jan 16, 2025

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

@ivaylogarnev-limechain
Copy link
Contributor

ivaylogarnev-limechain commented Jan 16, 2025

Tests are passing in JS! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TCK: Implement tests for AccountAllowanceDeleteTransaction
2 participants