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(tokenUnpauseTransaction): Implement TokenUnpauseTransaction E2E tests: TCK #289

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
1 change: 0 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@
"arrowParens": "always",
"endOfLine": "lf"
}

Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ The tests contained in this specification will assume that a valid token has alr

| Test no | Name | Input | Expected response | Implemented (Y/N) |
|---------|-----------------------------------------------------------------------|-----------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------|-------------------|
| 1 | Unpauses a token | tokenId=<CREATED_TOKEN_ID>, commonTransactionParams.signers=[<CREATED_TOKEN_PAUSE_KEY>] | The token unpause succeeds and the token is unpaused. | N |
| 2 | Unpauses a token with no token ID | | The token unpause fails with an INVALID_TOKEN_ID response code from the network. | N |
| 3 | Unpauses a token without signing with the token's pause key | tokenId=<CREATED_TOKEN_ID> | The token unpause fails with an INVALID_SIGNATURE response code from the network. | N |
| 4 | Unpauses a token and sign with the admin key instead of the pause key | tokenId=<CREATED_TOKEN_ID>, commonTransactionParams.signers=[<CREATED_TOKEN_ADMIN_KEY>] | The token unpause fails with an INVALID_SIGNATURE response code from the network. | N |
| 5 | Unpauses a token that doesn't exist | tokenId="123.456.789" | The token unpause fails with an INVALID_TOKEN_ID response code from the network. | N |
| 6 | Unpauses a token that is deleted | tokenId=<DELETED_TOKEN_ID>, commonTransactionParams.signers=[<DELETED_TOKEN_PAUSE_KEY>] | The token unpause fails with an TOKEN_WAS_DELETED response code from the network. | N |
| 7 | Unpauses a token that is empty | tokenId="" | The token unpause fails with an SDK internal error. | N |
| 8 | Unpauses a token that isn't paused | tokenId=<CREATED_TOKEN_ID>, commonTransactionParams.signers=[<CREATED_TOKEN_PAUSE_KEY>] | The token unpause succeeds and the token is unpaused. | N |
| 1 | Unpauses a token | tokenId=<CREATED_TOKEN_ID>, commonTransactionParams.signers=[<CREATED_TOKEN_PAUSE_KEY>] | The token unpause succeeds and the token is unpaused. | Y |
| 2 | Unpauses a token with no token ID | | The token unpause fails with an INVALID_TOKEN_ID response code from the network. | Y |
| 3 | Unpauses a token without signing with the token's pause key | tokenId=<CREATED_TOKEN_ID> | The token unpause fails with an INVALID_SIGNATURE response code from the network. | Y |
| 4 | Unpauses a token and sign with the admin key instead of the pause key | tokenId=<CREATED_TOKEN_ID>, commonTransactionParams.signers=[<CREATED_TOKEN_ADMIN_KEY>] | The token unpause fails with an INVALID_SIGNATURE response code from the network. | Y |
| 5 | Unpauses a token that doesn't exist | tokenId="123.456.789" | The token unpause fails with an INVALID_TOKEN_ID response code from the network. | Y |
| 6 | Unpauses a token that is deleted | tokenId=<DELETED_TOKEN_ID>, commonTransactionParams.signers=[<DELETED_TOKEN_PAUSE_KEY>] | The token unpause fails with an TOKEN_WAS_DELETED response code from the network. | Y |
| 7 | Unpauses a token that is empty | tokenId="" | The token unpause fails with an SDK internal error. | Y |
| 8 | Unpauses a token that isn't paused | tokenId=<CREATED_TOKEN_ID>, commonTransactionParams.signers=[<CREATED_TOKEN_PAUSE_KEY>] | The token unpause succeeds and the token is unpaused. | Y |

#### JSON Request Example

Expand Down
203 changes: 203 additions & 0 deletions src/tests/token-service/test-token-unpause-transaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
import { assert, expect } from "chai";

import { JSONRPCRequest } from "@services/Client";
import mirrorNodeClient from "@services/MirrorNodeClient";
import consensusInfoClient from "@services/ConsensusInfoClient";

import { setOperator } from "@helpers/setup-tests";
import { retryOnError } from "@helpers/retry-on-error";

/**
* Tests for TokenUnpauseTransaction
*/
describe("TokenUnpauseTransaction", function () {
// Tests should not take longer than 30 seconds to fully execute.
this.timeout(30000);

// All tests required a token to be created and paused.
let tokenId: string, tokenAdminKey: string, tokenPauseKey: string;
beforeEach(async function () {
await setOperator(
this,
process.env.OPERATOR_ACCOUNT_ID as string,
process.env.OPERATOR_ACCOUNT_PRIVATE_KEY as string,
);

tokenPauseKey = (
await JSONRPCRequest(this, "generateKey", {
type: "ed25519PrivateKey",
})
).key;

tokenAdminKey = (
await JSONRPCRequest(this, "generateKey", {
type: "ecdsaSecp256k1PrivateKey",
})
).key;

tokenId = (
await JSONRPCRequest(this, "createToken", {
name: "testname",
symbol: "testsymbol",
treasuryAccountId: process.env.OPERATOR_ACCOUNT_ID,
adminKey: tokenAdminKey,
tokenType: "ft",
pauseKey: tokenPauseKey,
commonTransactionParams: {
signers: [tokenAdminKey],
},
})
).tokenId;

await JSONRPCRequest(this, "pauseToken", {
tokenId,
commonTransactionParams: {
signers: [tokenPauseKey],
},
});
});
afterEach(async function () {
await JSONRPCRequest(this, "reset");
});

async function verifyTokenUnpaused(tokenId: string) {
expect((await consensusInfoClient.getTokenInfo(tokenId)).pauseStatus).to.be
rwalworth marked this conversation as resolved.
Show resolved Hide resolved
.false;
expect(
(await mirrorNodeClient.getTokenData(tokenId)).pause_status,
).to.equal("UNPAUSED");
}

describe("Token ID", function () {
it("(#1) Unpauses a token", async function () {
await JSONRPCRequest(this, "unpauseToken", {
tokenId,
commonTransactionParams: {
signers: [tokenPauseKey],
},
});

await retryOnError(async function () {
await verifyTokenUnpaused(tokenId);
});
});

it("(#2) Unpauses a token with no token ID", async function () {
try {
await JSONRPCRequest(this, "unpauseToken", {});
} catch (err: any) {
assert.equal(err.data.status, "INVALID_TOKEN_ID");
return;
}

assert.fail("Should throw an error");
});

it("(#3) Unpauses a token without signing with the token's pause key", async function () {
try {
await JSONRPCRequest(this, "unpauseToken", {
tokenId,
});
} catch (err: any) {
assert.equal(err.data.status, "INVALID_SIGNATURE");
return;
}

assert.fail("Should throw an error");
});

it("(#4) Unpauses a token and sign with the admin key instead of the pause key", async function () {
try {
await JSONRPCRequest(this, "unpauseToken", {
tokenId,
commonTransactionParams: {
signers: [tokenAdminKey],
},
});
} catch (err: any) {
assert.equal(err.data.status, "INVALID_SIGNATURE");
return;
}

assert.fail("Should throw an error");
});

it("(#5) Unpauses a token that doesn't exist", async function () {
try {
await JSONRPCRequest(this, "unpauseToken", {
tokenId: "123.456.789",
});
} catch (err: any) {
assert.equal(err.data.status, "INVALID_TOKEN_ID");
return;
}

assert.fail("Should throw an error");
});

it.skip("(#6) Unpauses a token that is deleted", async function () {
await JSONRPCRequest(this, "unpauseToken", {
tokenId,
commonTransactionParams: {
signers: [tokenPauseKey],
},
});

await JSONRPCRequest(this, "deleteToken", {
tokenId,
commonTransactionParams: {
signers: [tokenAdminKey],
},
});

try {
await JSONRPCRequest(this, "unpauseToken", {
tokenId,
commonTransactionParams: {
signers: [tokenPauseKey],
},
});
} catch (err: any) {
assert.equal(err.data.status, "TOKEN_WAS_DELETED");
return;
}

assert.fail("Should throw an error");
});

it("(#7) Unpauses a token that is empty", async function () {
try {
await JSONRPCRequest(this, "unpauseToken", {
tokenId: "",
});
} catch (err: any) {
assert.equal(err.code, -32603, "Internal error");
rwalworth marked this conversation as resolved.
Show resolved Hide resolved
return;
}

assert.fail("Should throw an error");
});

it("(#8) Unpauses a token that isn't paused", async function () {
await JSONRPCRequest(this, "unpauseToken", {
tokenId,
commonTransactionParams: {
signers: [tokenPauseKey],
},
});

await JSONRPCRequest(this, "unpauseToken", {
tokenId,
commonTransactionParams: {
signers: [tokenPauseKey],
},
});

await retryOnError(async function () {
await verifyTokenUnpaused(tokenId);
});
});
});

return Promise.resolve();
});