From 60dbbb0abfc64db7c2f415a3af98363d19a5daba Mon Sep 17 00:00:00 2001 From: Rob Walworth Date: Wed, 4 Dec 2024 17:17:20 -0500 Subject: [PATCH 1/2] feat: add grantTokenKyc tests Signed-off-by: Rob Walworth --- mirrorNodeClient.js | 5 + .../test_tokenGrantKycTransaction.js | 430 ++++++++++++++++++ 2 files changed, 435 insertions(+) create mode 100644 test/token-service/test_tokenGrantKycTransaction.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_tokenGrantKycTransaction.js b/test/token-service/test_tokenGrantKycTransaction.js new file mode 100644 index 0000000..2b0ab83 --- /dev/null +++ b/test/token-service/test_tokenGrantKycTransaction.js @@ -0,0 +1,430 @@ +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 TokenGrantKycTransaction + */ +describe("TokenGrantKycTransaction", 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 and to have the two be associated. + 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], + }, + }); + }); + afterEach(async function () { + await JSONRPCRequest(this, "reset"); + }); + + async function verifyTokenKyc(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("GRANTED"); + foundToken = true; + break; + } + } + + if (!foundToken) { + assert.fail("Token ID not found"); + } + } + + describe("Token ID", function () { + it("(#1) Grants KYC of a token to an account", async function () { + await JSONRPCRequest(this, "grantTokenKyc", { + tokenId, + accountId, + commonTransactionParams: { + signers: [tokenKycKey], + }, + }); + + await retryOnError(async () => verifyTokenKyc(accountId, tokenId)); + }); + + it("(#2) Grants KYC of a token that doesn't exist to an account", async function () { + try { + await JSONRPCRequest(this, "grantTokenKyc", { + tokenId: "123.456.789", + accountId, + }); + } catch (err) { + assert.equal(err.data.status, "INVALID_TOKEN_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#3) Grants KYC of a token with an empty token ID to an account", async function () { + try { + await JSONRPCRequest(this, "grantTokenKyc", { + tokenId: "", + accountId, + }); + } catch (err) { + assert.equal(err.code, -32603, "Internal error"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#4) Grants KYC of a token with no token ID to an account", async function () { + try { + await JSONRPCRequest(this, "grantTokenKyc", { + accountId, + }); + } catch (err) { + assert.equal(err.data.status, "INVALID_TOKEN_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#5) Grants KYC of a deleted token to an account", async function () { + await JSONRPCRequest(this, "deleteToken", { + tokenId, + commonTransactionParams: { + signers: [tokenAdminKey], + }, + }); + + try { + await JSONRPCRequest(this, "grantTokenKyc", { + tokenId, + accountId, + commonTransactionParams: { + signers: [tokenKycKey], + }, + }); + } catch (err) { + assert.equal(err.data.status, "TOKEN_WAS_DELETED"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#6) Grants KYC of a token to an account without signing with the token's KYC key", async function () { + try { + await JSONRPCRequest(this, "grantTokenKyc", { + tokenId, + accountId, + }); + } catch (err) { + assert.equal(err.data.status, "INVALID_SIGNATURE"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#7) Grants KYC of a token to an account but signs with the the token's admin key", async function () { + try { + await JSONRPCRequest(this, "grantTokenKyc", { + tokenId, + accountId, + commonTransactionParams: { + signers: [tokenAdminKey], + }, + }); + } catch (err) { + assert.equal(err.data.status, "INVALID_SIGNATURE"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#8) Grants 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, "grantTokenKyc", { + tokenId, + accountId, + commonTransactionParams: { + signers: [key], + }, + }); + } catch (err) { + assert.equal(err.data.status, "INVALID_SIGNATURE"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#9) Grants 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, "grantTokenKyc", { + tokenId: tokenIdNoKyc, + accountId, + }); + } catch (err) { + assert.equal(err.data.status, "TOKEN_HAS_NO_KYC_KEY"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#10) Grants KYC of a token to an account that already has KYC", async function () { + await JSONRPCRequest(this, "grantTokenKyc", { + tokenId, + accountId, + commonTransactionParams: { + signers: [tokenKycKey], + }, + }); + + await JSONRPCRequest(this, "grantTokenKyc", { + tokenId, + accountId, + commonTransactionParams: { + signers: [tokenKycKey], + }, + }); + + await retryOnError(async () => verifyTokenKyc(accountId, tokenId)); + }); + + it("(#11) Grants 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, "grantTokenKyc", { + 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) Grants KYC of a paused token to an account", async function () { + await JSONRPCRequest(this, "pauseToken", { + tokenId, + commonTransactionParams: { + signers: [tokenPauseKey], + }, + }); + + try { + await JSONRPCRequest(this, "grantTokenKyc", { + tokenId, + accountId, + commonTransactionParams: { + signers: [tokenKycKey], + }, + }); + } catch (err) { + assert.equal(err.data.status, "TOKEN_IS_PAUSED"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#13) Grants KYC of a token to a frozen account", async function () { + await JSONRPCRequest(this, "freezeToken", { + tokenId, + accountId, + commonTransactionParams: { + signers: [tokenFreezeKey], + }, + }); + + try { + await JSONRPCRequest(this, "grantTokenKyc", { + 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) Grants KYC of a token to an account that doesn't exist", async function () { + try { + await JSONRPCRequest(this, "grantTokenKyc", { + 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) Grants KYC of a token to an empty account ID", async function () { + try { + await JSONRPCRequest(this, "grantTokenKyc", { + tokenId, + accountId: "", + commonTransactionParams: { + signers: [tokenKycKey], + }, + }); + } catch (err) { + assert.equal(err.code, -32603, "Internal error"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#3) Grants KYC of a token to an account with no account ID", async function () { + try { + await JSONRPCRequest(this, "grantTokenKyc", { + tokenId, + commonTransactionParams: { + signers: [tokenKycKey], + }, + }); + } catch (err) { + assert.equal(err.data.status, "INVALID_ACCOUNT_ID"); + return; + } + + assert.fail("Should throw an error"); + }); + + it("(#4) Grants 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, "grantTokenKyc", { + 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 59c09fa2cc9d7b9d5869fe7fd7e11884273677c3 Mon Sep 17 00:00:00 2001 From: Rob Walworth Date: Fri, 13 Dec 2024 19:51:20 -0500 Subject: [PATCH 2/2] refactor: style and mark tests implemented Signed-off-by: Rob Walworth --- ...ansaction.md => TokenFreezeTransaction.md} | 0 .../token-service/TokenGrantKycTransaction.md | 38 +++--- ...saction.md => TokenUnfreezeTransaction.md} | 0 .../test-token-grant-kyc-transaction.ts | 123 ++++++++++-------- 4 files changed, 86 insertions(+), 75 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/TokenGrantKycTransaction.md b/docs/test-specifications/token-service/TokenGrantKycTransaction.md index 2e62866..013a3ab 100644 --- a/docs/test-specifications/token-service/TokenGrantKycTransaction.md +++ b/docs/test-specifications/token-service/TokenGrantKycTransaction.md @@ -54,19 +54,19 @@ The tests contained in this specification will assume that a valid account and a | Test no | Name | Input | Expected response | Implemented (Y/N) | |---------|------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------|-------------------| -| 1 | Grants KYC of a token to an account | tokenId=, accountId=, commonTransactionParams.signers=[] | The token grants KYC to the account. | N | -| 2 | Grants KYC of a token that doesn't exist to an account | tokenId="123.456.789", accountId= | The token KYC grant fails with an INVALID_TOKEN_ID response code from the network. | N | -| 3 | Grants KYC of a token with an empty token ID to an account | tokenId="", accountId= | The token KYC grant fails with an SDK internal error. | N | -| 4 | Grants KYC of a token with no token ID to an account | accountId= | The token KYC grant fails with an INVALID_TOKEN_ID response code from the network. | N | -| 5 | Grants KYC of a deleted token to an account | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC grant fails with an TOKEN_WAS_DELETED response code from the network. | N | -| 6 | Grants KYC of a token to an account without signing with the token's KYC key | tokenId=, accountId= | The token KYC grant fails with an INVALID_SIGNATURE response code from the network. | N | -| 7 | Grants KYC of a token to an account but signs with the the token's admin key | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC grant fails with an INVALID_SIGNATURE response code from the network. | N | -| 8 | Grants KYC of a token to an account but signs with an incorrect private key | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC grant fails with an INVALID_SIGNATURE response code from the network. | N | -| 9 | Grants KYC of a token with no KYC key to an account | tokenId=, accountId= | The token KYC grant fails with an TOKEN_HAS_NO_KYC_KEY response code from the network. | N | -| 10 | Grants KYC of a token to an account that already has KYC | tokenId=, accountId=, commonTransactionParams.signers=[] | The token grants KYC to the account. | N | -| 11 | Grants KYC of a token to an account that is not associated with the token | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC grant fails with an TOKEN_NOT_ASSOCIATED_TO_ACCOUNT response code from the network. | N | -| 12 | Grants KYC of a paused token to an account | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC grant fails with an TOKEN_IS_PAUSED response code from the network. | N | -| 13 | Grants KYC of a token to a frozen account | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC grant fails with an ACCOUNT_FROZEN_FOR_TOKEN response code from the network. | N | +| 1 | Grants KYC of a token to an account | tokenId=, accountId=, commonTransactionParams.signers=[] | The token grants KYC to the account. | Y | +| 2 | Grants KYC of a token that doesn't exist to an account | tokenId="123.456.789", accountId= | The token KYC grant fails with an INVALID_TOKEN_ID response code from the network. | Y | +| 3 | Grants KYC of a token with an empty token ID to an account | tokenId="", accountId= | The token KYC grant fails with an SDK internal error. | Y | +| 4 | Grants KYC of a token with no token ID to an account | accountId= | The token KYC grant fails with an INVALID_TOKEN_ID response code from the network. | Y | +| 5 | Grants KYC of a deleted token to an account | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC grant fails with an TOKEN_WAS_DELETED response code from the network. | Y | +| 6 | Grants KYC of a token to an account without signing with the token's KYC key | tokenId=, accountId= | The token KYC grant fails with an INVALID_SIGNATURE response code from the network. | Y | +| 7 | Grants KYC of a token to an account but signs with the the token's admin key | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC grant fails with an INVALID_SIGNATURE response code from the network. | Y | +| 8 | Grants KYC of a token to an account but signs with an incorrect private key | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC grant fails with an INVALID_SIGNATURE response code from the network. | Y | +| 9 | Grants KYC of a token with no KYC key to an account | tokenId=, accountId= | The token KYC grant fails with an TOKEN_HAS_NO_KYC_KEY response code from the network. | Y | +| 10 | Grants KYC of a token to an account that already has KYC | tokenId=, accountId=, commonTransactionParams.signers=[] | The token grants KYC to the account. | Y | +| 11 | Grants KYC of a token to an account that is not associated with the token | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC grant fails with an TOKEN_NOT_ASSOCIATED_TO_ACCOUNT response code from the network. | Y | +| 12 | Grants KYC of a paused token to an account | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC grant fails with an TOKEN_IS_PAUSED response code from the network. | Y | +| 13 | Grants KYC of a token to a frozen account | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC grant 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 and a - The ID of the account to which to grant KYC. -| Test no | Name | Input | Expected response | Implemented (Y/N) | -|---------|--------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------|-------------------| -| 1 | Grants KYC of a token to an account that doesn't exist | tokenId=, accountId="123.456.789", commonTransactionParams.signers=[] | The token KYC grant fails with an INVALID_ACCOUNT_ID response code from the network. | N | -| 2 | Grants KYC of a token to an empty account ID | tokenId=, accountId="", commonTransactionParams.signers=[] | The token KYC grant fails with an SDK internal error. | N | -| 3 | Grants KYC of a token to an account with no account ID | tokenId=, commonTransactionParams.signers=[] | The token KYC grant fails with an INVALID_ACCOUNT_ID response code from the network. | N | -| 4 | Grants KYC of a token to a deleted account | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC grant fails with an ACCOUNT_WAS_DELETED response code from the network. | N | +| Test no | Name | Input | Expected response | Implemented (Y/N) | +|---------|--------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------|-------------------| +| 1 | Grants KYC of a token to an account that doesn't exist | tokenId=, accountId="123.456.789", commonTransactionParams.signers=[] | The token KYC grant fails with an INVALID_ACCOUNT_ID response code from the network. | Y | +| 2 | Grants KYC of a token to an empty account ID | tokenId=, accountId="", commonTransactionParams.signers=[] | The token KYC grant fails with an SDK internal error. | Y | +| 3 | Grants KYC of a token to an account with no account ID | tokenId=, commonTransactionParams.signers=[] | The token KYC grant fails with an INVALID_ACCOUNT_ID response code from the network. | Y | +| 4 | Grants KYC of a token to a deleted account | tokenId=, accountId=, commonTransactionParams.signers=[] | The token KYC grant 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-grant-kyc-transaction.ts b/src/tests/token-service/test-token-grant-kyc-transaction.ts index b3df30f..db32386 100644 --- a/src/tests/token-service/test-token-grant-kyc-transaction.ts +++ b/src/tests/token-service/test-token-grant-kyc-transaction.ts @@ -28,49 +28,56 @@ describe("TokenGrantKycTransaction", 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, @@ -113,7 +120,9 @@ describe("TokenGrantKycTransaction", function () { }, }); - await retryOnError(async () => verifyTokenKyc(accountId, tokenId)); + await retryOnError(async function () { + await verifyTokenKyc(accountId, tokenId); + }); }); it("(#2) Grants KYC of a token that doesn't exist to an account", async function () { @@ -213,17 +222,18 @@ describe("TokenGrantKycTransaction", function () { }); it("(#8) Grants 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, "grantTokenKyc", { tokenId, accountId, commonTransactionParams: { - signers: [key], + signers: [ + ( + await JSONRPCRequest(this, "generateKey", { + type: "ed25519PrivateKey", + }) + ).key, + ], }, }); } catch (err: any) { @@ -235,16 +245,15 @@ describe("TokenGrantKycTransaction", function () { }); it("(#9) Grants 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, "grantTokenKyc", { - tokenId: tokenIdNoKyc, + tokenId: ( + await JSONRPCRequest(this, "createToken", { + name: "testname", + symbol: "testsymbol", + treasuryAccountId: process.env.OPERATOR_ACCOUNT_ID, + }) + ).tokenId, accountId, }); } catch (err: any) { @@ -272,7 +281,9 @@ describe("TokenGrantKycTransaction", function () { }, }); - await retryOnError(async () => verifyTokenKyc(accountId, tokenId)); + await retryOnError(async function () { + await verifyTokenKyc(accountId, tokenId); + }); }); it("(#11) Grants KYC of a token to an account that is not associated with the token", async function () {