From 7ca6d3a0f0bd143614966fb1f4dc33d4b614ef1b Mon Sep 17 00:00:00 2001 From: Rob Walworth Date: Wed, 4 Dec 2024 17:36:07 -0500 Subject: [PATCH 1/4] feat: add revokeTokenKyc tests Signed-off-by: Rob Walworth --- mirrorNodeClient.js | 5 + .../test_tokenRevokeKycTransaction.js | 438 ++++++++++++++++++ 2 files changed, 443 insertions(+) create mode 100644 test/token-service/test_tokenRevokeKycTransaction.js diff --git a/mirrorNodeClient.js b/mirrorNodeClient.js index f0f8767..b34619b 100644 --- a/mirrorNodeClient.js +++ b/mirrorNodeClient.js @@ -20,6 +20,11 @@ class MirrorNodeClient { const url = `${this.mirrorNodeRestUrl}/api/v1/tokens/${tokenId}`; return this.retryUntilData(url); } + + async getTokenRelationships(accountId) { + const url = `${this.mirrorNodeRestUrl}/api/v1/accounts/${accountId}/tokens`; + return this.retryUntilData(url); + } async retryUntilData(url) { const maxRetries = Math.floor(this.NODE_TIMEOUT / 1000); // retry once per second diff --git a/test/token-service/test_tokenRevokeKycTransaction.js b/test/token-service/test_tokenRevokeKycTransaction.js new file mode 100644 index 0000000..3a2b850 --- /dev/null +++ b/test/token-service/test_tokenRevokeKycTransaction.js @@ -0,0 +1,438 @@ +import { assert, expect } from "chai"; + +import { JSONRPCRequest } from "../../client.js"; +import { setOperator } from "../../setup_Tests.js"; +import mirrorNodeClient from "../../mirrorNodeClient.js"; + +import { retryOnError } from "../../utils/helpers/retry-on-error.js"; + +/** + * Tests for TokenRevokeKycTransaction + */ +describe("TokenRevokeKycTransaction", function () { + // Tests should not take longer than 30 seconds to fully execute. + this.timeout(30000); + + // All tests require an account and a token to be created, have the two be associated, and KYC granted. + let tokenId, + tokenFreezeKey, + tokenAdminKey, + tokenPauseKey, + tokenKycKey, + accountId, + accountPrivateKey; + beforeEach(async function () { + await setOperator( + process.env.OPERATOR_ACCOUNT_ID, + process.env.OPERATOR_ACCOUNT_PRIVATE_KEY, + ); + + let response = await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }); + tokenFreezeKey = response.key; + + response = await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }); + tokenAdminKey = response.key; + + response = await JSONRPCRequest(this, "generateKey", { + type: "ecdsaSecp256k1PrivateKey", + }); + tokenPauseKey = response.key; + + response = await JSONRPCRequest(this, "generateKey", { + type: "ecdsaSecp256k1PrivateKey", + }); + tokenKycKey = response.key; + + response = await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: process.env.OPERATOR_ACCOUNT_ID, + adminKey: tokenAdminKey, + kycKey: tokenKycKey, + freezeKey: tokenFreezeKey, + pauseKey: tokenPauseKey, + commonTransactionParams: { + signers: [tokenAdminKey], + }, + }); + tokenId = response.tokenId; + + response = await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }); + accountPrivateKey = response.key; + + response = await JSONRPCRequest(this, "createAccount", { + key: accountPrivateKey, + }); + accountId = response.accountId; + + await JSONRPCRequest(this, "associateToken", { + accountId, + tokenIds: [tokenId], + commonTransactionParams: { + signers: [accountPrivateKey], + }, + }); + + await JSONRPCRequest(this, "grantTokenKyc", { + tokenId, + accountId, + commonTransactionParams: { + signers: [tokenKycKey] + }, + }); + }); + afterEach(async function () { + await JSONRPCRequest(this, "reset"); + }); + + async function verifyTokenNoKyc(accountId, tokenId) { + // No way to get token associations via consensus node, so just query mirror node. + const mirrorNodeInfo = + await mirrorNodeClient.getTokenRelationships(accountId); + + let foundToken = false; + for (let i = 0; i < mirrorNodeInfo.tokens.length; i++) { + if (mirrorNodeInfo.tokens[i].token_id === tokenId) { + expect(mirrorNodeInfo.tokens[i].kyc_status).to.equal("UNGRANTED"); + foundToken = true; + break; + } + } + + if (!foundToken) { + assert.fail("Token ID not found"); + } + } + + describe("Token ID", function () { + it("(#1) Revokes KYC of a token to an account", async function () { + await JSONRPCRequest(this, "revokeTokenKyc", { + tokenId, + accountId, + commonTransactionParams: { + signers: [tokenKycKey], + }, + }); + + await retryOnError(async () => verifyTokenNoKyc(accountId, tokenId)); + }); + + it("(#2) Revokes KYC of a token that doesn't exist to an account", async function () { + try { + await JSONRPCRequest(this, "revokeTokenKyc", { + tokenId: "123.456.789", + accountId, + }); + } catch (err) { + assert.equal(err.data.status, "INVALID_TOKEN_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#3) Revokes KYC of a token with an empty token ID to an account", async function () { + try { + await JSONRPCRequest(this, "revokeTokenKyc", { + tokenId: "", + accountId, + }); + } catch (err) { + assert.equal(err.code, -32603, "Internal error"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#4) Revokes KYC of a token with no token ID to an account", async function () { + try { + await JSONRPCRequest(this, "revokeTokenKyc", { + accountId, + }); + } catch (err) { + assert.equal(err.data.status, "INVALID_TOKEN_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#5) Revokes KYC of a deleted token to an account", async function () { + await JSONRPCRequest(this, "deleteToken", { + tokenId, + commonTransactionParams: { + signers: [tokenAdminKey], + }, + }); + + try { + await JSONRPCRequest(this, "revokeTokenKyc", { + tokenId, + accountId, + commonTransactionParams: { + signers: [tokenKycKey], + }, + }); + } catch (err) { + assert.equal(err.data.status, "TOKEN_WAS_DELETED"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#6) Revokes KYC of a token to an account without signing with the token's KYC key", async function () { + try { + await JSONRPCRequest(this, "revokeTokenKyc", { + tokenId, + accountId, + }); + } catch (err) { + assert.equal(err.data.status, "INVALID_SIGNATURE"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#7) Revokes KYC of a token to an account but signs with the the token's admin key", async function () { + try { + await JSONRPCRequest(this, "revokeTokenKyc", { + tokenId, + accountId, + commonTransactionParams: { + signers: [tokenAdminKey], + }, + }); + } catch (err) { + assert.equal(err.data.status, "INVALID_SIGNATURE"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#8) Revokes KYC of a token to an account but signs with an incorrect private key", async function () { + const response = await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }); + const key = response.key; + + try { + await JSONRPCRequest(this, "revokeTokenKyc", { + tokenId, + accountId, + commonTransactionParams: { + signers: [key], + }, + }); + } catch (err) { + assert.equal(err.data.status, "INVALID_SIGNATURE"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#9) Revokes KYC of a token with no KYC key to an account", async function () { + const response = await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: process.env.OPERATOR_ACCOUNT_ID, + }); + const tokenIdNoKyc = response.tokenId; + + try { + await JSONRPCRequest(this, "revokeTokenKyc", { + tokenId: tokenIdNoKyc, + accountId, + }); + } catch (err) { + assert.equal(err.data.status, "TOKEN_HAS_NO_KYC_KEY"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#10) Revokes KYC of a token to an account that doesn't have KYC", async function () { + await JSONRPCRequest(this, "revokeTokenKyc", { + tokenId, + accountId, + commonTransactionParams: { + signers: [tokenKycKey], + }, + }); + + await JSONRPCRequest(this, "revokeTokenKyc", { + tokenId, + accountId, + commonTransactionParams: { + signers: [tokenKycKey], + }, + }); + + await retryOnError(async () => verifyTokenNoKyc(accountId, tokenId)); + }); + + it("(#11) Revokes KYC of a token to an account that is not associated with the token", async function () { + await JSONRPCRequest(this, "dissociateToken", { + accountId, + tokenIds: [tokenId], + commonTransactionParams: { + signers: [accountPrivateKey], + }, + }); + + try { + await JSONRPCRequest(this, "revokeTokenKyc", { + tokenId, + accountId, + commonTransactionParams: { + signers: [tokenKycKey], + }, + }); + } catch (err) { + assert.equal(err.data.status, "TOKEN_NOT_ASSOCIATED_TO_ACCOUNT"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#12) Revokes KYC of a paused token to an account", async function () { + await JSONRPCRequest(this, "pauseToken", { + tokenId, + commonTransactionParams: { + signers: [tokenPauseKey], + }, + }); + + try { + await JSONRPCRequest(this, "revokeTokenKyc", { + tokenId, + accountId, + commonTransactionParams: { + signers: [tokenKycKey], + }, + }); + } catch (err) { + assert.equal(err.data.status, "TOKEN_IS_PAUSED"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#13) Revokes KYC of a token to a frozen account", async function () { + await JSONRPCRequest(this, "freezeToken", { + tokenId, + accountId, + commonTransactionParams: { + signers: [tokenFreezeKey], + }, + }); + + try { + await JSONRPCRequest(this, "revokeTokenKyc", { + tokenId, + accountId, + commonTransactionParams: { + signers: [tokenKycKey], + }, + }); + } catch (err) { + assert.equal(err.data.status, "ACCOUNT_FROZEN_FOR_TOKEN"); + return; + } + + assert.fail("Should throw an error"); + }); + }); + + describe("Account ID", function () { + it("(#1) Revokes KYC of a token to an account that doesn't exist", async function () { + try { + await JSONRPCRequest(this, "revokeTokenKyc", { + tokenId, + accountId: "123.456.789", + commonTransactionParams: { + signers: [tokenKycKey], + }, + }); + } catch (err) { + assert.equal(err.data.status, "INVALID_ACCOUNT_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#2) Revokes KYC of a token to an empty account ID", async function () { + try { + await JSONRPCRequest(this, "revokeTokenKyc", { + tokenId, + accountId: "", + commonTransactionParams: { + signers: [tokenKycKey], + }, + }); + } catch (err) { + assert.equal(err.code, -32603, "Internal error"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#3) Revokes KYC of a token to an account with no account ID", async function () { + try { + await JSONRPCRequest(this, "revokeTokenKyc", { + tokenId, + commonTransactionParams: { + signers: [tokenKycKey], + }, + }); + } catch (err) { + assert.equal(err.data.status, "INVALID_ACCOUNT_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#4) Revokes KYC of a token to a deleted account", async function () { + await JSONRPCRequest(this, "deleteAccount", { + deleteAccountId: accountId, + transferAccountId: process.env.OPERATOR_ACCOUNT_ID, + commonTransactionParams: { + signers: [accountPrivateKey], + }, + }); + + try { + await JSONRPCRequest(this, "revokeTokenKyc", { + tokenId, + accountId, + commonTransactionParams: { + signers: [tokenKycKey], + }, + }); + } catch (err) { + assert.equal(err.data.status, "ACCOUNT_DELETED"); + return; + } + + assert.fail("Should throw an error"); + }); + }); + + return Promise.resolve(); +}); \ No newline at end of file From 5eae752f9a809fdd847c3a86af28bfb55978eecd Mon Sep 17 00:00:00 2001 From: Rob Walworth Date: Wed, 4 Dec 2024 17:48:23 -0500 Subject: [PATCH 2/4] feat: add revokeTokenKyc tests Signed-off-by: Rob Walworth --- test/token-service/test_tokenRevokeKycTransaction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/token-service/test_tokenRevokeKycTransaction.js b/test/token-service/test_tokenRevokeKycTransaction.js index 3a2b850..67cbee3 100644 --- a/test/token-service/test_tokenRevokeKycTransaction.js +++ b/test/token-service/test_tokenRevokeKycTransaction.js @@ -99,7 +99,7 @@ describe("TokenRevokeKycTransaction", function () { let foundToken = false; for (let i = 0; i < mirrorNodeInfo.tokens.length; i++) { if (mirrorNodeInfo.tokens[i].token_id === tokenId) { - expect(mirrorNodeInfo.tokens[i].kyc_status).to.equal("UNGRANTED"); + expect(mirrorNodeInfo.tokens[i].kyc_status).to.equal("REVOKED"); foundToken = true; break; } From cf17cc1cba30114e4c9c7110f48e4fa24cdf05fc Mon Sep 17 00:00:00 2001 From: Rob Walworth Date: Fri, 13 Dec 2024 20:06:32 -0500 Subject: [PATCH 3/4] refactor: style and mark tests implemented Signed-off-by: Rob Walworth --- ...ansaction.md => TokenFreezeTransaction.md} | 0 .../TokenRevokeKycTransaction.md | 40 +++--- ...saction.md => TokenUnfreezeTransaction.md} | 0 .../test-token-revoke-kyc-transaction.ts | 123 ++++++++++-------- 4 files changed, 87 insertions(+), 76 deletions(-) rename docs/test-specifications/token-service/{tokenFreezeTransaction.md => TokenFreezeTransaction.md} (100%) rename docs/test-specifications/token-service/{tokenUnfreezeTransaction.md => TokenUnfreezeTransaction.md} (100%) diff --git a/docs/test-specifications/token-service/tokenFreezeTransaction.md b/docs/test-specifications/token-service/TokenFreezeTransaction.md similarity index 100% rename from docs/test-specifications/token-service/tokenFreezeTransaction.md rename to docs/test-specifications/token-service/TokenFreezeTransaction.md diff --git a/docs/test-specifications/token-service/TokenRevokeKycTransaction.md b/docs/test-specifications/token-service/TokenRevokeKycTransaction.md index 1de9990..333c53d 100644 --- a/docs/test-specifications/token-service/TokenRevokeKycTransaction.md +++ b/docs/test-specifications/token-service/TokenRevokeKycTransaction.md @@ -10,7 +10,7 @@ Each test within the test specification is linked to one of the properties withi https://docs.hedera.com/hedera/sdks-and-apis/sdks/token-service/disable-kyc-account-flag -**TokenGrantKyc protobufs:** +**TokenRevokeKyc protobufs:** https://github.com/hashgraph/hedera-protobufs/blob/main/services/token_revoke_kyc.proto @@ -54,19 +54,19 @@ The tests contained in this specification will assume that a valid account has b | Test no | Name | Input | Expected response | Implemented (Y/N) | |---------|-------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|-------------------| -| 1 | Revokes KYC of a token to an account | tokenId=, accountId=, commonTransactionParams.signers=[] | The token revokes KYC to the account. | N | -| 2 | Revokes KYC of a token that doesn't exist to an account | tokenId="123.456.789", accountId= | The token KYC revoke fails with an INVALID_TOKEN_ID response code from the network. | N | -| 3 | Revokes KYC of a token with an empty token ID to an account | tokenId="", accountId= | The token KYC revoke fails with an SDK internal error. | N | -| 4 | Revokes KYC of a token with no token ID to an account | accountId= | The token KYC revoke fails with an INVALID_TOKEN_ID response code from the network. | N | -| 5 | Revokes KYC of a deleted token to an account | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC revoke fails with an TOKEN_WAS_DELETED response code from the network. | N | -| 6 | Revokes KYC of a token to an account without signing with the token's KYC key | tokenId=, accountId= | The token KYC revoke fails with an INVALID_SIGNATURE response code from the network. | N | -| 7 | Revokes KYC of a token to an account but signs with the the token's admin key | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC revoke fails with an INVALID_SIGNATURE response code from the network. | N | -| 8 | Revokes KYC of a token to an account but signs with an incorrect private key | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC revoke fails with an INVALID_SIGNATURE response code from the network. | N | -| 9 | Revokes KYC of a token with no KYC key to an account | tokenId=, accountId= | The token KYC revoke fails with an TOKEN_HAS_NO_KYC_KEY response code from the network. | N | -| 10 | Revokes KYC of a token to an account that doesn't have KYC | tokenId=, accountId=, commonTransactionParams.signers=[] | The token revokes KYC to the account. | N | -| 11 | Revokes KYC of a token to an account that is not associated with the token | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC revoke fails with an TOKEN_NOT_ASSOCIATED_TO_ACCOUNT response code from the network. | N | -| 12 | Revokes KYC of a paused token to an account | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC revoke fails with an TOKEN_IS_PAUSED response code from the network. | N | -| 13 | Revokes KYC of a token to a frozen account | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC revoke fails with an ACCOUNT_FROZEN_FOR_TOKEN response code from the network. | N | +| 1 | Revokes KYC of a token to an account | tokenId=, accountId=, commonTransactionParams.signers=[] | The token revokes KYC to the account. | Y | +| 2 | Revokes KYC of a token that doesn't exist to an account | tokenId="123.456.789", accountId= | The token KYC revoke fails with an INVALID_TOKEN_ID response code from the network. | Y | +| 3 | Revokes KYC of a token with an empty token ID to an account | tokenId="", accountId= | The token KYC revoke fails with an SDK internal error. | Y | +| 4 | Revokes KYC of a token with no token ID to an account | accountId= | The token KYC revoke fails with an INVALID_TOKEN_ID response code from the network. | Y | +| 5 | Revokes KYC of a deleted token to an account | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC revoke fails with an TOKEN_WAS_DELETED response code from the network. | Y | +| 6 | Revokes KYC of a token to an account without signing with the token's KYC key | tokenId=, accountId= | The token KYC revoke fails with an INVALID_SIGNATURE response code from the network. | Y | +| 7 | Revokes KYC of a token to an account but signs with the the token's admin key | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC revoke fails with an INVALID_SIGNATURE response code from the network. | Y | +| 8 | Revokes KYC of a token to an account but signs with an incorrect private key | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC revoke fails with an INVALID_SIGNATURE response code from the network. | Y | +| 9 | Revokes KYC of a token with no KYC key to an account | tokenId=, accountId= | The token KYC revoke fails with an TOKEN_HAS_NO_KYC_KEY response code from the network. | Y | +| 10 | Revokes KYC of a token to an account that doesn't have KYC | tokenId=, accountId=, commonTransactionParams.signers=[] | The token revokes KYC to the account. | Y | +| 11 | Revokes KYC of a token to an account that is not associated with the token | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC revoke fails with an TOKEN_NOT_ASSOCIATED_TO_ACCOUNT response code from the network. | Y | +| 12 | Revokes KYC of a paused token to an account | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC revoke fails with an TOKEN_IS_PAUSED response code from the network. | Y | +| 13 | Revokes KYC of a token to a frozen account | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC revoke fails with an ACCOUNT_FROZEN_FOR_TOKEN response code from the network. | Y | #### JSON Request Example @@ -103,12 +103,12 @@ The tests contained in this specification will assume that a valid account has b - The ID of the account to which to revoke KYC. -| Test no | Name | Input | Expected response | Implemented (Y/N) | -|---------|---------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------|-------------------| -| 1 | Revokes KYC of a token to an account that doesn't exist | tokenId=, accountId="123.456.789", commonTransactionParams.signers=[] | The token KYC revoke fails with an INVALID_ACCOUNT_ID response code from the network. | N | -| 2 | Revokes KYC of a token to an empty account ID | tokenId=, accountId="", commonTransactionParams.signers=[] | The token KYC revoke fails with an SDK internal error. | N | -| 3 | Revokes KYC of a token to an account with no account ID | tokenId=, commonTransactionParams.signers=[] | The token KYC revoke fails with an INVALID_TOKEN_ID response code from the network. | N | -| 4 | Revokes KYC of a token to a deleted account | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC revoke fails with an ACCOUNT_WAS_DELETED response code from the network. | N | +| Test no | Name | Input | Expected response | Implemented (Y/N) | +|---------|---------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------|-------------------| +| 1 | Revokes KYC of a token to an account that doesn't exist | tokenId=, accountId="123.456.789", commonTransactionParams.signers=[] | The token KYC revoke fails with an INVALID_ACCOUNT_ID response code from the network. | Y | +| 2 | Revokes KYC of a token to an empty account ID | tokenId=, accountId="", commonTransactionParams.signers=[] | The token KYC revoke fails with an SDK internal error. | Y | +| 3 | Revokes KYC of a token to an account with no account ID | tokenId=, commonTransactionParams.signers=[] | The token KYC revoke fails with an INVALID_ACCOUNT_ID response code from the network. | Y | +| 4 | Revokes KYC of a token to a deleted account | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC revoke fails with an ACCOUNT_DELETED response code from the network. | Y | #### JSON Request Example diff --git a/docs/test-specifications/token-service/tokenUnfreezeTransaction.md b/docs/test-specifications/token-service/TokenUnfreezeTransaction.md similarity index 100% rename from docs/test-specifications/token-service/tokenUnfreezeTransaction.md rename to docs/test-specifications/token-service/TokenUnfreezeTransaction.md diff --git a/src/tests/token-service/test-token-revoke-kyc-transaction.ts b/src/tests/token-service/test-token-revoke-kyc-transaction.ts index 9d0c7fc..d557b91 100644 --- a/src/tests/token-service/test-token-revoke-kyc-transaction.ts +++ b/src/tests/token-service/test-token-revoke-kyc-transaction.ts @@ -28,49 +28,56 @@ describe("TokenRevokeKycTransaction", function () { process.env.OPERATOR_ACCOUNT_PRIVATE_KEY as string, ); - let response = await JSONRPCRequest(this, "generateKey", { - type: "ed25519PrivateKey", - }); - tokenFreezeKey = response.key; - - response = await JSONRPCRequest(this, "generateKey", { - type: "ed25519PrivateKey", - }); - tokenAdminKey = response.key; - - response = await JSONRPCRequest(this, "generateKey", { - type: "ecdsaSecp256k1PrivateKey", - }); - tokenPauseKey = response.key; + tokenFreezeKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }) + ).key; - response = await JSONRPCRequest(this, "generateKey", { - type: "ecdsaSecp256k1PrivateKey", - }); - tokenKycKey = response.key; - - response = await JSONRPCRequest(this, "createToken", { - name: "testname", - symbol: "testsymbol", - treasuryAccountId: process.env.OPERATOR_ACCOUNT_ID, - adminKey: tokenAdminKey, - kycKey: tokenKycKey, - freezeKey: tokenFreezeKey, - pauseKey: tokenPauseKey, - commonTransactionParams: { - signers: [tokenAdminKey], - }, - }); - tokenId = response.tokenId; + tokenAdminKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }) + ).key; + + tokenPauseKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ecdsaSecp256k1PrivateKey", + }) + ).key; + + tokenKycKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ecdsaSecp256k1PrivateKey", + }) + ).key; + + tokenId = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: process.env.OPERATOR_ACCOUNT_ID, + adminKey: tokenAdminKey, + kycKey: tokenKycKey, + freezeKey: tokenFreezeKey, + pauseKey: tokenPauseKey, + commonTransactionParams: { + signers: [tokenAdminKey], + }, + }) + ).tokenId; - response = await JSONRPCRequest(this, "generateKey", { - type: "ed25519PrivateKey", - }); - accountPrivateKey = response.key; + accountPrivateKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }) + ).key; - response = await JSONRPCRequest(this, "createAccount", { - key: accountPrivateKey, - }); - accountId = response.accountId; + accountId = ( + await JSONRPCRequest(this, "createAccount", { + key: accountPrivateKey, + }) + ).accountId; await JSONRPCRequest(this, "associateToken", { accountId, @@ -121,7 +128,9 @@ describe("TokenRevokeKycTransaction", function () { }, }); - await retryOnError(async () => verifyTokenNoKyc(accountId, tokenId)); + await retryOnError(async function () { + await verifyTokenNoKyc(accountId, tokenId); + }); }); it("(#2) Revokes KYC of a token that doesn't exist to an account", async function () { @@ -221,17 +230,18 @@ describe("TokenRevokeKycTransaction", function () { }); it("(#8) Revokes KYC of a token to an account but signs with an incorrect private key", async function () { - const response = await JSONRPCRequest(this, "generateKey", { - type: "ed25519PrivateKey", - }); - const key = response.key; - try { await JSONRPCRequest(this, "revokeTokenKyc", { tokenId, accountId, commonTransactionParams: { - signers: [key], + signers: [ + ( + await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }) + ).key, + ], }, }); } catch (err: any) { @@ -243,16 +253,15 @@ describe("TokenRevokeKycTransaction", function () { }); it("(#9) Revokes KYC of a token with no KYC key to an account", async function () { - const response = await JSONRPCRequest(this, "createToken", { - name: "testname", - symbol: "testsymbol", - treasuryAccountId: process.env.OPERATOR_ACCOUNT_ID, - }); - const tokenIdNoKyc = response.tokenId; - try { await JSONRPCRequest(this, "revokeTokenKyc", { - tokenId: tokenIdNoKyc, + tokenId: ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: process.env.OPERATOR_ACCOUNT_ID, + }) + ).tokenId, accountId, }); } catch (err: any) { @@ -280,7 +289,9 @@ describe("TokenRevokeKycTransaction", function () { }, }); - await retryOnError(async () => verifyTokenNoKyc(accountId, tokenId)); + await retryOnError(async function () { + await verifyTokenNoKyc(accountId, tokenId); + }); }); it("(#11) Revokes KYC of a token to an account that is not associated with the token", async function () { From d6bd4a12c4f1029da2f22ed6cb48c4351d276e83 Mon Sep 17 00:00:00 2001 From: Rob Walworth Date: Tue, 17 Dec 2024 14:58:15 -0500 Subject: [PATCH 4/4] refactor: address PR comments Signed-off-by: Rob Walworth --- .../test-token-revoke-kyc-transaction.ts | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/src/tests/token-service/test-token-revoke-kyc-transaction.ts b/src/tests/token-service/test-token-revoke-kyc-transaction.ts index d557b91..2bfeaf4 100644 --- a/src/tests/token-service/test-token-revoke-kyc-transaction.ts +++ b/src/tests/token-service/test-token-revoke-kyc-transaction.ts @@ -5,6 +5,7 @@ import mirrorNodeClient from "@services/MirrorNodeClient"; import { setOperator } from "@helpers/setup-tests"; import { retryOnError } from "@helpers/retry-on-error"; +import { ErrorStatusCodes } from "@enums/error-status-codes"; /** * Tests for TokenRevokeKycTransaction @@ -128,7 +129,7 @@ describe("TokenRevokeKycTransaction", function () { }, }); - await retryOnError(async function () { + await retryOnError(async () => { await verifyTokenNoKyc(accountId, tokenId); }); }); @@ -154,7 +155,11 @@ describe("TokenRevokeKycTransaction", function () { accountId, }); } catch (err: any) { - assert.equal(err.code, -32603, "Internal error"); + assert.equal( + err.code, + ErrorStatusCodes.INTERNAL_ERROR, + "Internal error", + ); return; } @@ -230,18 +235,18 @@ describe("TokenRevokeKycTransaction", function () { }); it("(#8) Revokes KYC of a token to an account but signs with an incorrect private key", async function () { + const incorrectPrivateKey = ( + await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }) + ).key; + try { await JSONRPCRequest(this, "revokeTokenKyc", { tokenId, accountId, commonTransactionParams: { - signers: [ - ( - await JSONRPCRequest(this, "generateKey", { - type: "ed25519PrivateKey", - }) - ).key, - ], + signers: [incorrectPrivateKey], }, }); } catch (err: any) { @@ -253,15 +258,17 @@ describe("TokenRevokeKycTransaction", function () { }); it("(#9) Revokes KYC of a token with no KYC key to an account", async function () { + const tokenIdNoKycKey = ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: process.env.OPERATOR_ACCOUNT_ID, + }) + ).tokenId; + try { await JSONRPCRequest(this, "revokeTokenKyc", { - tokenId: ( - await JSONRPCRequest(this, "createToken", { - name: "testname", - symbol: "testsymbol", - treasuryAccountId: process.env.OPERATOR_ACCOUNT_ID, - }) - ).tokenId, + tokenId: tokenIdNoKycKey, accountId, }); } catch (err: any) { @@ -289,7 +296,7 @@ describe("TokenRevokeKycTransaction", function () { }, }); - await retryOnError(async function () { + await retryOnError(async () => { await verifyTokenNoKyc(accountId, tokenId); }); }); @@ -397,7 +404,11 @@ describe("TokenRevokeKycTransaction", function () { }, }); } catch (err: any) { - assert.equal(err.code, -32603, "Internal error"); + assert.equal( + err.code, + ErrorStatusCodes.INTERNAL_ERROR, + "Internal error", + ); return; }