diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ff4ff131..d0f11fe5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,13 +27,23 @@ jobs: node-version: '18.12.1' cache: 'npm' - - name: build + - name: Install dependencies run: | npm cache clean --force npm set registry https://registry.npmjs.org/ - npm i - npm test -- --coverage=true - npm run build + npm ci + + - name: Check formatting + run: npm run pretty:check + + - name: Lint + run: npm run lint + + - name: Test + run: npm test -- --coverage=true + + - name: Build + run: npm run build - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 diff --git a/examples/integration-scripts/credentials.test.ts b/examples/integration-scripts/credentials.test.ts index d49db9ae..d9712ce4 100644 --- a/examples/integration-scripts/credentials.test.ts +++ b/examples/integration-scripts/credentials.test.ts @@ -115,10 +115,12 @@ test('credentials', async () => { const verifierAidName = 'verifier'; // Create two identifiers, one for each client - const issuerIcpRes = await issuerClient.identifiers().create(issuerAidName, { - toad: 3, - wits: [...KLI_WITNESS_DEMO_PREFIXES], - }); + const issuerIcpRes = await issuerClient + .identifiers() + .create(issuerAidName, { + toad: 3, + wits: [...KLI_WITNESS_DEMO_PREFIXES], + }); let issOp = await issuerIcpRes.op(); while (!issOp['done']) { issOp = await issuerClient.operations().get(issOp.name); @@ -131,10 +133,12 @@ test('credentials', async () => { .addEndRole(issuerAidName, 'agent', issuerClient!.agent!.pre); console.log("Issuer's AID:", issuerAID); - const holderIcpRes = await holderClient.identifiers().create(holderAidName, { - toad: 3, - wits: [...KLI_WITNESS_DEMO_PREFIXES], - }); + const holderIcpRes = await holderClient + .identifiers() + .create(holderAidName, { + toad: 3, + wits: [...KLI_WITNESS_DEMO_PREFIXES], + }); let hldOp = await holderIcpRes.op(); while (!hldOp['done']) { hldOp = await holderClient.operations().get(hldOp.name); diff --git a/examples/integration-scripts/singlesig-ixn.test.ts b/examples/integration-scripts/singlesig-ixn.test.ts index 20df9484..1986ba6a 100644 --- a/examples/integration-scripts/singlesig-ixn.test.ts +++ b/examples/integration-scripts/singlesig-ixn.test.ts @@ -1,6 +1,10 @@ -import { EventResult, SignifyClient } from "signify-ts"; -import { getOrCreateClients, getOrCreateContact, getOrCreateIdentifier } from "./utils/test-setup"; -import { waitOperation } from "./utils/test-util"; +import { EventResult, SignifyClient } from 'signify-ts'; +import { + getOrCreateClients, + getOrCreateContact, + getOrCreateIdentifier, +} from './utils/test-setup'; +import { waitOperation } from './utils/test-util'; let client1: SignifyClient, client2: SignifyClient; let name1_id: string, name1_oobi: string; @@ -10,20 +14,20 @@ beforeAll(async () => { [client1, client2] = await getOrCreateClients(2); }); beforeAll(async () => { - [name1_id, name1_oobi] = await getOrCreateIdentifier(client1, "name1"); + [name1_id, name1_oobi] = await getOrCreateIdentifier(client1, 'name1'); }); beforeAll(async () => { - contact1_id = await getOrCreateContact(client2, "contact1", name1_oobi); + contact1_id = await getOrCreateContact(client2, 'contact1', name1_oobi); }); interface KeyState { i: string; s: string; - [property: string]: any + [property: string]: any; } -describe("singlesig-ixn", () => { - test("step1", async () => { +describe('singlesig-ixn', () => { + test('step1', async () => { expect(name1_id).toEqual(contact1_id); const keystate1 = await client1.keyStates().get(name1_id); @@ -35,28 +39,38 @@ describe("singlesig-ixn", () => { // local and remote keystate sequence match expect(keystate1[0].s).toEqual(keystate2[0].s); }); - test("ixn1", async () => { + test('ixn1', async () => { // local keystate before ixn - const keystate0: KeyState = (await client1.keyStates().get(name1_id)).at(0); + const keystate0: KeyState = ( + await client1.keyStates().get(name1_id) + ).at(0); expect(keystate0).not.toBeNull(); // ixn - const result: EventResult = await client1.identifiers().interact("name1", {}); + const result: EventResult = await client1 + .identifiers() + .interact('name1', {}); await waitOperation(client1, await result.op()); // local keystate after ixn - const keystate1: KeyState = (await client1.keyStates().get(name1_id)).at(0); + const keystate1: KeyState = ( + await client1.keyStates().get(name1_id) + ).at(0); expect(parseInt(keystate1.s)).toBeGreaterThan(0); // sequence has incremented expect(parseInt(keystate1.s)).toEqual(parseInt(keystate0.s) + 1); // remote keystate after ixn - const keystate2: KeyState = (await client2.keyStates().get(contact1_id)).at(0); + const keystate2: KeyState = ( + await client2.keyStates().get(contact1_id) + ).at(0); // remote keystate is one behind expect(parseInt(keystate2.s)).toEqual(parseInt(keystate1.s) - 1); // refresh remote keystate - let op = await client2.keyStates().query(contact1_id, parseInt(keystate1.s), undefined); + let op = await client2 + .keyStates() + .query(contact1_id, parseInt(keystate1.s), undefined); op = await waitOperation(client2, op); const keystate3: KeyState = op.response; // local and remote keystate match diff --git a/examples/integration-scripts/singlesig-rot.test.ts b/examples/integration-scripts/singlesig-rot.test.ts index 3f88fb92..d5a7af91 100644 --- a/examples/integration-scripts/singlesig-rot.test.ts +++ b/examples/integration-scripts/singlesig-rot.test.ts @@ -1,6 +1,10 @@ -import { EventResult, RotateIdentifierArgs, SignifyClient } from "signify-ts"; -import { getOrCreateClients, getOrCreateContact, getOrCreateIdentifier } from "./utils/test-setup"; -import { waitOperation } from "./utils/test-util"; +import { EventResult, RotateIdentifierArgs, SignifyClient } from 'signify-ts'; +import { + getOrCreateClients, + getOrCreateContact, + getOrCreateIdentifier, +} from './utils/test-setup'; +import { waitOperation } from './utils/test-util'; let client1: SignifyClient, client2: SignifyClient; let name1_id: string, name1_oobi: string; @@ -10,10 +14,10 @@ beforeAll(async () => { [client1, client2] = await getOrCreateClients(2); }); beforeAll(async () => { - [name1_id, name1_oobi] = await getOrCreateIdentifier(client1, "name1"); + [name1_id, name1_oobi] = await getOrCreateIdentifier(client1, 'name1'); }); beforeAll(async () => { - contact1_id = await getOrCreateContact(client2, "contact1", name1_oobi); + contact1_id = await getOrCreateContact(client2, 'contact1', name1_oobi); }); interface KeyState { @@ -21,11 +25,11 @@ interface KeyState { s: string; k: string[]; n: string[]; - [property: string]: any + [property: string]: any; } -describe("singlesig-rot", () => { - test("step1", async () => { +describe('singlesig-rot', () => { + test('step1', async () => { expect(name1_id).toEqual(contact1_id); const keystate1 = await client1.keyStates().get(name1_id); @@ -37,20 +41,26 @@ describe("singlesig-rot", () => { // local and remote keystate sequence match expect(keystate1[0].s).toEqual(keystate2[0].s); }); - test("rot1", async () => { + test('rot1', async () => { // local keystate before rot - const keystate0: KeyState = (await client1.keyStates().get(name1_id)).at(0); + const keystate0: KeyState = ( + await client1.keyStates().get(name1_id) + ).at(0); expect(keystate0).not.toBeNull(); expect(keystate0.k).toHaveLength(1); expect(keystate0.n).toHaveLength(1); // rot const args: RotateIdentifierArgs = {}; - const result: EventResult = await client1.identifiers().rotate("name1", args); + const result: EventResult = await client1 + .identifiers() + .rotate('name1', args); await waitOperation(client1, await result.op()); // local keystate after rot - const keystate1: KeyState = (await client1.keyStates().get(name1_id)).at(0); + const keystate1: KeyState = ( + await client1.keyStates().get(name1_id) + ).at(0); expect(parseInt(keystate1.s)).toBeGreaterThan(0); // sequence has incremented expect(parseInt(keystate1.s)).toEqual(parseInt(keystate0.s) + 1); @@ -60,12 +70,16 @@ describe("singlesig-rot", () => { expect(keystate1.n[0]).not.toEqual(keystate0.n[0]); // remote keystate after rot - const keystate2: KeyState = (await client2.keyStates().get(contact1_id)).at(0); + const keystate2: KeyState = ( + await client2.keyStates().get(contact1_id) + ).at(0); // remote keystate is one behind expect(parseInt(keystate2.s)).toEqual(parseInt(keystate1.s) - 1); // refresh remote keystate - let op = await client2.keyStates().query(contact1_id, parseInt(keystate1.s), undefined); + let op = await client2 + .keyStates() + .query(contact1_id, parseInt(keystate1.s), undefined); op = await waitOperation(client2, op); const keystate3: KeyState = op.response; // local and remote keystate match diff --git a/examples/integration-scripts/test-setup-clients.test.ts b/examples/integration-scripts/test-setup-clients.test.ts index 29540239..906f8528 100644 --- a/examples/integration-scripts/test-setup-clients.test.ts +++ b/examples/integration-scripts/test-setup-clients.test.ts @@ -1,29 +1,33 @@ -import { SignifyClient } from "signify-ts"; -import { getOrCreateClients, getOrCreateContact, getOrCreateIdentifier } from "./utils/test-setup"; +import { SignifyClient } from 'signify-ts'; +import { + getOrCreateClients, + getOrCreateContact, + getOrCreateIdentifier, +} from './utils/test-setup'; let client1: SignifyClient, client2: SignifyClient; let name1_id: string, name1_oobi: string; let name2_id: string, name2_oobi: string; -let contact1_id: string, contact2_id: string;; +let contact1_id: string, contact2_id: string; beforeAll(async () => { // create two clients with random secrets [client1, client2] = await getOrCreateClients(2); }); beforeAll(async () => { - [name1_id, name1_oobi] = await getOrCreateIdentifier(client1, "name1"); - [name2_id, name2_oobi] = await getOrCreateIdentifier(client2, "name2"); + [name1_id, name1_oobi] = await getOrCreateIdentifier(client1, 'name1'); + [name2_id, name2_oobi] = await getOrCreateIdentifier(client2, 'name2'); }); beforeAll(async () => { - contact1_id = await getOrCreateContact(client2, "contact1", name1_oobi); - contact2_id = await getOrCreateContact(client1, "contact2", name2_oobi); + contact1_id = await getOrCreateContact(client2, 'contact1', name1_oobi); + contact2_id = await getOrCreateContact(client1, 'contact2', name2_oobi); }); -describe("test-setup-clients", () => { - test("step1", async () => { +describe('test-setup-clients', () => { + test('step1', async () => { expect(name1_id).toEqual(contact1_id); }); - test("step2", async () => { + test('step2', async () => { expect(name2_id).toEqual(contact2_id); }); }); diff --git a/examples/integration-scripts/test-setup-single-client.test.ts b/examples/integration-scripts/test-setup-single-client.test.ts index f8be928f..32bb084b 100644 --- a/examples/integration-scripts/test-setup-single-client.test.ts +++ b/examples/integration-scripts/test-setup-single-client.test.ts @@ -1,39 +1,59 @@ -import { SignifyClient } from "signify-ts"; -import { getOrCreateClients, getOrCreateIdentifier } from "./utils/test-setup"; -import { resolveEnvironment } from "./utils/resolve-env"; +import { SignifyClient } from 'signify-ts'; +import { getOrCreateClients, getOrCreateIdentifier } from './utils/test-setup'; +import { resolveEnvironment } from './utils/resolve-env'; let client: SignifyClient; let name1_id: string, name1_oobi: string; beforeAll(async () => { // Create client with pre-defined secret. Allows working with known identifiers - [client] = await getOrCreateClients(1, ["0ADF2TpptgqcDE5IQUF1HeTp"]); + [client] = await getOrCreateClients(1, ['0ADF2TpptgqcDE5IQUF1HeTp']); }); beforeAll(async () => { - [name1_id, name1_oobi] = await getOrCreateIdentifier(client, "name1"); + [name1_id, name1_oobi] = await getOrCreateIdentifier(client, 'name1'); }); -describe("test-setup-single-client", () => { - test("step1", async () => { - expect(client.agent?.pre).toEqual("EC60ue9GOpQGrLBlS9T0dO6JkBTbv3V05Y4O730QBBoc"); - expect(client.controller?.pre).toEqual("EB3UGWwIMq7ppzcQ697ImQIuXlBG5jzh-baSx-YG3-tY"); +describe('test-setup-single-client', () => { + test('step1', async () => { + expect(client.agent?.pre).toEqual( + 'EC60ue9GOpQGrLBlS9T0dO6JkBTbv3V05Y4O730QBBoc' + ); + expect(client.controller?.pre).toEqual( + 'EB3UGWwIMq7ppzcQ697ImQIuXlBG5jzh-baSx-YG3-tY' + ); }); - test("step2", async () => { + test('step2', async () => { const env = resolveEnvironment(); - const oobi = await client.oobis().get("name1", "witness"); + const oobi = await client.oobis().get('name1', 'witness'); expect(oobi.oobis).toHaveLength(3); switch (env.preset) { - case "local": - expect(name1_oobi).toEqual(`http://localhost:3902/oobi/${name1_id}/agent/EC60ue9GOpQGrLBlS9T0dO6JkBTbv3V05Y4O730QBBoc`); - expect(oobi.oobis[0]).toEqual(`http://localhost:5642/oobi/${name1_id}/witness/BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha`); - expect(oobi.oobis[1]).toEqual(`http://localhost:5643/oobi/${name1_id}/witness/BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM`); - expect(oobi.oobis[2]).toEqual(`http://localhost:5644/oobi/${name1_id}/witness/BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX`); + case 'local': + expect(name1_oobi).toEqual( + `http://localhost:3902/oobi/${name1_id}/agent/EC60ue9GOpQGrLBlS9T0dO6JkBTbv3V05Y4O730QBBoc` + ); + expect(oobi.oobis[0]).toEqual( + `http://localhost:5642/oobi/${name1_id}/witness/BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha` + ); + expect(oobi.oobis[1]).toEqual( + `http://localhost:5643/oobi/${name1_id}/witness/BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM` + ); + expect(oobi.oobis[2]).toEqual( + `http://localhost:5644/oobi/${name1_id}/witness/BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX` + ); break; - case "docker": - expect(name1_oobi).toEqual(`http://keria:3902/oobi/${name1_id}/agent/EC60ue9GOpQGrLBlS9T0dO6JkBTbv3V05Y4O730QBBoc`); - expect(oobi.oobis[0]).toEqual(`http://witness-demo:5642/oobi/${name1_id}/witness/BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha`); - expect(oobi.oobis[1]).toEqual(`http://witness-demo:5643/oobi/${name1_id}/witness/BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM`); - expect(oobi.oobis[2]).toEqual(`http://witness-demo:5644/oobi/${name1_id}/witness/BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX`); + case 'docker': + expect(name1_oobi).toEqual( + `http://keria:3902/oobi/${name1_id}/agent/EC60ue9GOpQGrLBlS9T0dO6JkBTbv3V05Y4O730QBBoc` + ); + expect(oobi.oobis[0]).toEqual( + `http://witness-demo:5642/oobi/${name1_id}/witness/BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha` + ); + expect(oobi.oobis[1]).toEqual( + `http://witness-demo:5643/oobi/${name1_id}/witness/BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM` + ); + expect(oobi.oobis[2]).toEqual( + `http://witness-demo:5644/oobi/${name1_id}/witness/BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX` + ); break; } }); diff --git a/examples/integration-scripts/utils/resolve-env.ts b/examples/integration-scripts/utils/resolve-env.ts index 9cb1cf79..d41ce4d1 100644 --- a/examples/integration-scripts/utils/resolve-env.ts +++ b/examples/integration-scripts/utils/resolve-env.ts @@ -9,9 +9,9 @@ export interface TestEnvironment { witnessIds: string[]; } -const WAN = "BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha"; -const WIL = "BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM"; -const WES = "BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX"; +const WAN = 'BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha'; +const WIL = 'BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM'; +const WES = 'BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX'; export function resolveEnvironment( input?: TestEnvironmentPreset diff --git a/examples/integration-scripts/utils/test-setup.ts b/examples/integration-scripts/utils/test-setup.ts index 0dc253f6..ea9760f1 100644 --- a/examples/integration-scripts/utils/test-setup.ts +++ b/examples/integration-scripts/utils/test-setup.ts @@ -1,6 +1,13 @@ -import { CreateIdentiferArgs, EventResult, SignifyClient, Tier, randomPasscode, ready } from "signify-ts"; -import { resolveEnvironment } from "./resolve-env"; -import { waitOperation } from "./test-util"; +import { + CreateIdentiferArgs, + EventResult, + SignifyClient, + Tier, + randomPasscode, + ready, +} from 'signify-ts'; +import { resolveEnvironment } from './resolve-env'; +import { waitOperation } from './test-util'; /** * Connect or boot a number of SignifyClient instances @@ -14,25 +21,32 @@ import { waitOperation } from "./test-util"; *