Skip to content

Commit

Permalink
move test into integration-scripts directory
Browse files Browse the repository at this point in the history
  • Loading branch information
lenkan committed Nov 21, 2023
1 parent f00503e commit a2859c2
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 108 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ jobs:
node-version: '18.12.1'
cache: 'npm'
- name: install deps
run: |
npm ci
run: npm ci
- name: Build
run: npm run build
- name: Start dependencies
run: docker compose up deps
- name: Run integration test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ import signify, {
messagize,
d,
Siger,
} from '../src/index.ts';
} from 'signify-ts';

export function createTimestamp() {
const URL = 'http://127.0.0.1:3901';
const BOOT_URL = 'http://127.0.0.1:3903';
const SCHEMA_SAID = 'EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao';
const WITNESS_AIDS: string[] = []; // ['BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha'];
const SCHEMA_OOBI =
'http://vlei-server:7723/oobi/EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao';

function createTimestamp() {
const dt = new Date().toISOString().replace('Z', '000+00:00');
return dt;
}

export async function connect(url: string, bootUrl: string) {
async function connect(url: string, bootUrl: string) {
const client = new signify.SignifyClient(
url,
signify.randomPasscode(),
Expand All @@ -26,7 +33,7 @@ export async function connect(url: string, bootUrl: string) {
return client;
}

export async function createIdentifier(
async function createIdentifier(
client: signify.SignifyClient,
name: string,
witnesses: string[]
Expand All @@ -48,15 +55,15 @@ export async function createIdentifier(
return aid.prefix;
}

export async function getAgentOobi(
client: SignifyClient,
async function getAgentOobi(
client: signify.SignifyClient,
name: string
): Promise<string> {
const result = await client.oobis().get(name, 'agent');
return result.oobis[0];
}

export async function resolveOobi(
async function resolveOobi(
client: SignifyClient,
oobi: string,
alias: string
Expand All @@ -66,7 +73,7 @@ export async function resolveOobi(
await waitOperation(client, op.name, 5000);
}

export async function createRegistry(
async function createRegistry(
client: SignifyClient,
name: string,
registryName: string
Expand All @@ -82,7 +89,7 @@ export async function createRegistry(
return registries[0];
}

export async function issueCredential(
async function issueCredential(
client: SignifyClient,
name: string,
args: { registry: string; schema: string; recipient: string; data: unknown }
Expand Down Expand Up @@ -142,7 +149,7 @@ interface Notification {
a: { r: string; d?: string; m?: string };
}

export async function waitForNotification(
async function waitForNotification(
client: SignifyClient,
route: string
): Promise<Notification> {
Expand All @@ -159,7 +166,7 @@ export async function waitForNotification(
}
}

export async function admitCredential(
async function admitCredential(
client: SignifyClient,
name: string,
said: string,
Expand All @@ -172,7 +179,7 @@ export async function admitCredential(
await client.ipex().submitAdmit(name, admit, sigs, end, [recipient]);
}

export async function wait<T>(fn: () => Promise<T>, timeout: number = 10000) {
async function wait<T>(fn: () => Promise<T>, timeout: number = 10000) {
const start = Date.now();
const errors: Error[] = [];
while (Date.now() - start < timeout) {
Expand All @@ -188,7 +195,7 @@ export async function wait<T>(fn: () => Promise<T>, timeout: number = 10000) {
throw new RetryError(`Retry failed after ${Date.now() - start} ms`, errors);
}

export async function waitOperation(
async function waitOperation(
client: SignifyClient,
name: string,
timeout?: number
Expand All @@ -213,11 +220,75 @@ export async function waitOperation(
}
}

export class RetryError extends Error {
class RetryError extends Error {
constructor(
message: string,
public errors: Error[]
) {
super(message);
}
}

test(
'Single issuer holder',
async () => {
await signify.ready();
const issuerClient = await connect(URL, BOOT_URL);
const holderClient = await connect(URL, BOOT_URL);

await issuerClient.state();
await holderClient.state();

// Create two identifiers, one for each client
const issuerPrefix = await createIdentifier(
issuerClient,
'issuer',
WITNESS_AIDS
);
const holderPrefix = await createIdentifier(
holderClient,
'holder',
WITNESS_AIDS
);

// Exchange OOBIs
const issuerOobi = await getAgentOobi(issuerClient, 'issuer');
const holderOobi = await getAgentOobi(holderClient, 'holder');
await resolveOobi(issuerClient, holderOobi, 'holder');
await resolveOobi(issuerClient, SCHEMA_OOBI, 'schema');
await resolveOobi(holderClient, issuerOobi, 'issuer');
await resolveOobi(holderClient, SCHEMA_OOBI, 'schema');

await createRegistry(issuerClient, 'issuer', 'vLEI');

const registires = await issuerClient.registries().list('issuer');
await issueCredential(issuerClient, 'issuer', {
registry: registires[0].regk,
schema: SCHEMA_SAID,
recipient: holderPrefix,
data: {
LEI: '5493001KJTIIGC8Y1R17',
},
});

const grantNotification = await waitForNotification(
holderClient,
'/exn/ipex/grant'
);

await admitCredential(
holderClient,
'holder',
grantNotification.a.d!,
issuerPrefix
);

await holderClient.notifications().mark(grantNotification.i);

await wait(async () => {
const creds = await holderClient.credentials().list();
assert(creds.length >= 1);
});
},
1000 * 60 * 5
);
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"build:types": "tsc -p tsconfig.build.json",
"build": "npm run build:cjs && npm run build:esm && npm run build:types",
"test": "jest test/",
"test:integration": "jest test-integration/",
"lint": "npx eslint src test test-integration examples/integration-scripts examples/scripts",
"test:integration": "jest examples/integration-scripts/",
"lint": "npx eslint src test examples/integration-scripts examples/scripts",
"prepare": "npm run build",
"generate-docs": "node_modules/.bin/jsdoc --configure .jsdoc.json --verbose",
"pretty": "prettier --config .prettierrc 'src/**/*.ts' 'test/**/*.ts' 'examples/**/*.ts' --write"
Expand Down
84 changes: 0 additions & 84 deletions test-integration/single-issuer-holder.test.ts

This file was deleted.

12 changes: 6 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"include": ["src", "types", "test", "test-integration"],
"extends": "./tsconfig.node.json",
"compilerOptions": {
"noEmit": true,
"allowImportingTsExtensions": true
}
"include": ["src", "types", "test", "examples/integration-scripts"],
"extends": "./tsconfig.node.json",
"compilerOptions": {
"noEmit": true,
"allowImportingTsExtensions": true
}
}

0 comments on commit a2859c2

Please sign in to comment.