Skip to content

Commit

Permalink
build: e2e node npm lint script now exists, uses eslint (dfinity#253)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Benjamin Goering authored Feb 26, 2021
1 parent 7a54d0c commit 7963d1c
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 21 deletions.
2 changes: 2 additions & 0 deletions e2e/node/basic/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
39 changes: 20 additions & 19 deletions e2e/node/basic/identity.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Actor, HttpAgent, IDL, Principal, SignIdentity } from "@dfinity/agent";
import {
DelegationChain,
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -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(
Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions e2e/node/canisters/counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
};
}
Expand Down
6 changes: 6 additions & 0 deletions e2e/node/canisters/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
};
}
Expand Down
1 change: 1 addition & 0 deletions e2e/node/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-env node */
module.exports = {
bail: false,
setupFiles: ["./test-setup"],
Expand Down
10 changes: 8 additions & 2 deletions e2e/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions e2e/node/test-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7963d1c

Please sign in to comment.