From 7963d1c716f82524fb3d9801b86a3d85ca3a3a1b Mon Sep 17 00:00:00 2001 From: Benjamin Goering Date: Fri, 26 Feb 2021 12:54:50 -0800 Subject: [PATCH] build: e2e node npm lint script now exists, uses eslint (#253) * rm tslint from deps of e2e/node * add eslint to e2e/node * rm pesky AuthenticationResponseIdentities.ts file... * fix typo in jsdoc e2e/node/canisters/identity.ts * don't use shell syntax in package.json lint script --- e2e/node/basic/basic.test.ts | 2 ++ e2e/node/basic/identity.test.ts | 39 +++++++++++++++++---------------- e2e/node/canisters/counter.ts | 6 +++++ e2e/node/canisters/identity.ts | 6 +++++ e2e/node/jest.config.js | 1 + e2e/node/package.json | 10 +++++++-- e2e/node/test-setup.js | 2 ++ 7 files changed, 45 insertions(+), 21 deletions(-) diff --git a/e2e/node/basic/basic.test.ts b/e2e/node/basic/basic.test.ts index d32c9ab9..2b30a1d6 100644 --- a/e2e/node/basic/basic.test.ts +++ b/e2e/node/basic/basic.test.ts @@ -18,11 +18,13 @@ test("read_state", async () => { ); expect(await cert.verify()).toBe(true); expect(cert.lookup([blobFromText("Time")])).toBe(undefined); + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const rawTime = cert.lookup(path)!; const decoded = IDL.decode( [IDL.Nat], Buffer.concat([Buffer.from("DIDL\x00\x01\x7d"), rawTime]) )[0]; + // eslint-disable-next-line @typescript-eslint/no-explicit-any const time = (decoded as any).toNumber() / 1e9; // The diff between decoded time and local time is within 5s expect(Math.abs(time - now) < 5).toBe(true); diff --git a/e2e/node/basic/identity.test.ts b/e2e/node/basic/identity.test.ts index 6c62e624..d75390f8 100644 --- a/e2e/node/basic/identity.test.ts +++ b/e2e/node/basic/identity.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { Actor, HttpAgent, IDL, Principal, SignIdentity } from "@dfinity/agent"; import { DelegationChain, @@ -50,8 +51,8 @@ test("identity: query and call gives same principal", async () => { test("identity: two different Ed25519 keys should have a different principal", async () => { const { canisterId, idl } = await installIdentityCanister(); - let identity1 = createIdentityActor(0, canisterId, idl); - let identity2 = createIdentityActor(1, canisterId, idl); + const identity1 = createIdentityActor(0, canisterId, idl); + const identity2 = createIdentityActor(1, canisterId, idl); const principal1 = await identity1.whoami_query(); const principal2 = await identity2.whoami_query(); @@ -61,20 +62,20 @@ test("identity: two different Ed25519 keys should have a different principal", a test("delegation: principal is the same between delegated keys", async () => { const { canisterId, idl } = await installIdentityCanister(); - let masterKey = createIdentity(0); - let sessionKey = createIdentity(1); + const masterKey = createIdentity(0); + const sessionKey = createIdentity(1); - let delegation = await DelegationChain.create( + const delegation = await DelegationChain.create( masterKey, sessionKey.getPublicKey() ); const id3 = DelegationIdentity.fromDelegation(sessionKey, delegation); - let identityActor1 = Actor.createActor(idl, { + const identityActor1 = Actor.createActor(idl, { canisterId, agent: new HttpAgent({ source: agent, identity: masterKey }), }) as any; - let identityActor2 = Actor.createActor(idl, { + const identityActor2 = Actor.createActor(idl, { canisterId, agent: new HttpAgent({ source: agent, identity: sessionKey }), }) as any; @@ -94,9 +95,9 @@ test("delegation: principal is the same between delegated keys", async () => { test("delegation: works with 3 keys", async () => { const { canisterId, idl } = await installIdentityCanister(); - let rootKey = createIdentity(2); - let middleKey = createIdentity(1); - let bottomKey = createIdentity(0); + const rootKey = createIdentity(2); + const middleKey = createIdentity(1); + const bottomKey = createIdentity(0); const id1D2 = await DelegationChain.create(rootKey, middleKey.getPublicKey()); const idDelegated = DelegationIdentity.fromDelegation( @@ -111,11 +112,11 @@ test("delegation: works with 3 keys", async () => { ) ); - let identityActorBottom = Actor.createActor(idl, { + const identityActorBottom = Actor.createActor(idl, { canisterId, agent: new HttpAgent({ source: agent, identity: bottomKey }), }) as any; - let identityActorMiddle = Actor.createActor(idl, { + const identityActorMiddle = Actor.createActor(idl, { canisterId, agent: new HttpAgent({ source: agent, identity: middleKey }), }) as any; @@ -141,10 +142,10 @@ test("delegation: works with 3 keys", async () => { test("delegation: works with 4 keys", async () => { const { canisterId, idl } = await installIdentityCanister(); - let rootKey = createIdentity(3); - let middleKey = createIdentity(2); - let middle2Key = createIdentity(1); - let bottomKey = createIdentity(0); + const rootKey = createIdentity(3); + const middleKey = createIdentity(2); + const middle2Key = createIdentity(1); + const bottomKey = createIdentity(0); const rootToMiddle = await DelegationChain.create( rootKey, @@ -170,15 +171,15 @@ test("delegation: works with 4 keys", async () => { ) ); - let identityActorBottom = Actor.createActor(idl, { + const identityActorBottom = Actor.createActor(idl, { canisterId, agent: new HttpAgent({ source: agent, identity: bottomKey }), }) as any; - let identityActorMiddle = Actor.createActor(idl, { + const identityActorMiddle = Actor.createActor(idl, { canisterId, agent: new HttpAgent({ source: agent, identity: middleKey }), }) as any; - let identityActorMiddle2 = Actor.createActor(idl, { + const identityActorMiddle2 = Actor.createActor(idl, { canisterId, agent: new HttpAgent({ source: agent, identity: middle2Key }), }) as any; diff --git a/e2e/node/canisters/counter.ts b/e2e/node/canisters/counter.ts index afc88b96..bbc73cdd 100644 --- a/e2e/node/canisters/counter.ts +++ b/e2e/node/canisters/counter.ts @@ -5,11 +5,16 @@ import agent from "../utils/agent"; let cache: { canisterId: Principal; + // eslint-disable-next-line @typescript-eslint/no-explicit-any actor: any; } | null = null; +/** + * Create a counter Actor + canisterId + */ export default async function (): Promise<{ canisterId: Principal; + // eslint-disable-next-line @typescript-eslint/no-explicit-any actor: any; }> { if (!cache) { @@ -28,6 +33,7 @@ export default async function (): Promise<{ cache = { canisterId, + // eslint-disable-next-line @typescript-eslint/no-explicit-any actor: Actor.createActor(idl, { canisterId, agent }) as any, }; } diff --git a/e2e/node/canisters/identity.ts b/e2e/node/canisters/identity.ts index 886cac0f..9f644689 100644 --- a/e2e/node/canisters/identity.ts +++ b/e2e/node/canisters/identity.ts @@ -4,12 +4,17 @@ import path from "path"; import agent from "../utils/agent"; let cache: { + // eslint-disable-next-line @typescript-eslint/no-explicit-any actor: any; canisterId: Principal; idl: IDL.InterfaceFactory; } | null = null; +/** + * Create an Actor that acts as an 'whoami service' (echoes back request.caller Principal) + */ export default async function (): Promise<{ + // eslint-disable-next-line @typescript-eslint/no-explicit-any actor: any; canisterId: Principal; idl: IDL.InterfaceFactory; @@ -29,6 +34,7 @@ export default async function (): Promise<{ cache = { canisterId, idl, + // eslint-disable-next-line @typescript-eslint/no-explicit-any actor: Actor.createActor(idl, { canisterId, agent }) as any, }; } diff --git a/e2e/node/jest.config.js b/e2e/node/jest.config.js index 6c2fd420..f05a6f44 100644 --- a/e2e/node/jest.config.js +++ b/e2e/node/jest.config.js @@ -1,3 +1,4 @@ +/* eslint-env node */ module.exports = { bail: false, setupFiles: ["./test-setup"], diff --git a/e2e/node/package.json b/e2e/node/package.json index d5d7f7a2..9b33b1de 100644 --- a/e2e/node/package.json +++ b/e2e/node/package.json @@ -5,6 +5,9 @@ "scripts": { "ci": "npm run e2e", "e2e": "jest --verbose", + "eslint:fix": "npm run lint -- --fix", + "eslint": "eslint --ext '.js,.jsx,.ts,.tsx' basic canisters utils *.js", + "lint": "npm run eslint", "mitm": "jest -i basic/mitm.test.ts" }, "dependencies": { @@ -14,14 +17,17 @@ "@types/base64-js": "^1.2.5", "@types/jest": "^24.0.18", "@types/node": "^13.7.7", + "@typescript-eslint/eslint-plugin": "^4.14.2", + "@typescript-eslint/parser": "^4.14.2", "buffer": "^5.4.3", - "jest": "^24.9.0", + "eslint-plugin-jsdoc": "^31.6.0", + "eslint": "^7.19.0", "jest-expect-message": "^1.0.2", + "jest": "^24.9.0", "node-fetch": "2.6.1", "prettier": "^1.19.1", "text-encoding": "^0.7.0", "ts-jest": "^24.2.0", - "tslint": "^5.20.0", "typescript": "^3.6.3", "whatwg-fetch": "^3.0.0", "xhr2": "^0.2.0" diff --git a/e2e/node/test-setup.js b/e2e/node/test-setup.js index d20ebced..e064a329 100644 --- a/e2e/node/test-setup.js +++ b/e2e/node/test-setup.js @@ -6,6 +6,8 @@ // // Note that we can use webpack configuration to make some features available to // Node.js in a similar way. +/* eslint-disable @typescript-eslint/no-var-requires */ +/* eslint-env node */ global.crypto = require("@trust/webcrypto"); global.TextEncoder = require("text-encoding").TextEncoder;