Skip to content

Commit

Permalink
Merge pull request #153 from lenkan/update-workflow
Browse files Browse the repository at this point in the history
add npm ci, linting, format check to workflow
  • Loading branch information
pfeairheller authored Dec 1, 2023
2 parents c8c7c24 + 15c8259 commit f790e63
Show file tree
Hide file tree
Showing 22 changed files with 269 additions and 116 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions examples/integration-scripts/credentials.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
42 changes: 28 additions & 14 deletions examples/integration-scripts/singlesig-ixn.test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand All @@ -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
Expand Down
42 changes: 28 additions & 14 deletions examples/integration-scripts/singlesig-rot.test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,22 +14,22 @@ 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;
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);
Expand All @@ -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);
Expand All @@ -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
Expand Down
24 changes: 14 additions & 10 deletions examples/integration-scripts/test-setup-clients.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
62 changes: 41 additions & 21 deletions examples/integration-scripts/test-setup-single-client.test.ts
Original file line number Diff line number Diff line change
@@ -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;
}
});
Expand Down
6 changes: 3 additions & 3 deletions examples/integration-scripts/utils/resolve-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit f790e63

Please sign in to comment.