Skip to content

Commit a2859c2

Browse files
committed
move test into integration-scripts directory
1 parent f00503e commit a2859c2

File tree

5 files changed

+96
-108
lines changed

5 files changed

+96
-108
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ jobs:
5252
node-version: '18.12.1'
5353
cache: 'npm'
5454
- name: install deps
55-
run: |
56-
npm ci
55+
run: npm ci
56+
- name: Build
57+
run: npm run build
5758
- name: Start dependencies
5859
run: docker compose up deps
5960
- name: Run integration test

test-integration/test-utils.ts renamed to examples/integration-scripts/single-issuer-holder.test.ts

Lines changed: 85 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@ import signify, {
55
messagize,
66
d,
77
Siger,
8-
} from '../src/index.ts';
8+
} from 'signify-ts';
99

10-
export function createTimestamp() {
10+
const URL = 'http://127.0.0.1:3901';
11+
const BOOT_URL = 'http://127.0.0.1:3903';
12+
const SCHEMA_SAID = 'EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao';
13+
const WITNESS_AIDS: string[] = []; // ['BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha'];
14+
const SCHEMA_OOBI =
15+
'http://vlei-server:7723/oobi/EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao';
16+
17+
function createTimestamp() {
1118
const dt = new Date().toISOString().replace('Z', '000+00:00');
1219
return dt;
1320
}
1421

15-
export async function connect(url: string, bootUrl: string) {
22+
async function connect(url: string, bootUrl: string) {
1623
const client = new signify.SignifyClient(
1724
url,
1825
signify.randomPasscode(),
@@ -26,7 +33,7 @@ export async function connect(url: string, bootUrl: string) {
2633
return client;
2734
}
2835

29-
export async function createIdentifier(
36+
async function createIdentifier(
3037
client: signify.SignifyClient,
3138
name: string,
3239
witnesses: string[]
@@ -48,15 +55,15 @@ export async function createIdentifier(
4855
return aid.prefix;
4956
}
5057

51-
export async function getAgentOobi(
52-
client: SignifyClient,
58+
async function getAgentOobi(
59+
client: signify.SignifyClient,
5360
name: string
5461
): Promise<string> {
5562
const result = await client.oobis().get(name, 'agent');
5663
return result.oobis[0];
5764
}
5865

59-
export async function resolveOobi(
66+
async function resolveOobi(
6067
client: SignifyClient,
6168
oobi: string,
6269
alias: string
@@ -66,7 +73,7 @@ export async function resolveOobi(
6673
await waitOperation(client, op.name, 5000);
6774
}
6875

69-
export async function createRegistry(
76+
async function createRegistry(
7077
client: SignifyClient,
7178
name: string,
7279
registryName: string
@@ -82,7 +89,7 @@ export async function createRegistry(
8289
return registries[0];
8390
}
8491

85-
export async function issueCredential(
92+
async function issueCredential(
8693
client: SignifyClient,
8794
name: string,
8895
args: { registry: string; schema: string; recipient: string; data: unknown }
@@ -142,7 +149,7 @@ interface Notification {
142149
a: { r: string; d?: string; m?: string };
143150
}
144151

145-
export async function waitForNotification(
152+
async function waitForNotification(
146153
client: SignifyClient,
147154
route: string
148155
): Promise<Notification> {
@@ -159,7 +166,7 @@ export async function waitForNotification(
159166
}
160167
}
161168

162-
export async function admitCredential(
169+
async function admitCredential(
163170
client: SignifyClient,
164171
name: string,
165172
said: string,
@@ -172,7 +179,7 @@ export async function admitCredential(
172179
await client.ipex().submitAdmit(name, admit, sigs, end, [recipient]);
173180
}
174181

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

191-
export async function waitOperation(
198+
async function waitOperation(
192199
client: SignifyClient,
193200
name: string,
194201
timeout?: number
@@ -213,11 +220,75 @@ export async function waitOperation(
213220
}
214221
}
215222

216-
export class RetryError extends Error {
223+
class RetryError extends Error {
217224
constructor(
218225
message: string,
219226
public errors: Error[]
220227
) {
221228
super(message);
222229
}
223230
}
231+
232+
test(
233+
'Single issuer holder',
234+
async () => {
235+
await signify.ready();
236+
const issuerClient = await connect(URL, BOOT_URL);
237+
const holderClient = await connect(URL, BOOT_URL);
238+
239+
await issuerClient.state();
240+
await holderClient.state();
241+
242+
// Create two identifiers, one for each client
243+
const issuerPrefix = await createIdentifier(
244+
issuerClient,
245+
'issuer',
246+
WITNESS_AIDS
247+
);
248+
const holderPrefix = await createIdentifier(
249+
holderClient,
250+
'holder',
251+
WITNESS_AIDS
252+
);
253+
254+
// Exchange OOBIs
255+
const issuerOobi = await getAgentOobi(issuerClient, 'issuer');
256+
const holderOobi = await getAgentOobi(holderClient, 'holder');
257+
await resolveOobi(issuerClient, holderOobi, 'holder');
258+
await resolveOobi(issuerClient, SCHEMA_OOBI, 'schema');
259+
await resolveOobi(holderClient, issuerOobi, 'issuer');
260+
await resolveOobi(holderClient, SCHEMA_OOBI, 'schema');
261+
262+
await createRegistry(issuerClient, 'issuer', 'vLEI');
263+
264+
const registires = await issuerClient.registries().list('issuer');
265+
await issueCredential(issuerClient, 'issuer', {
266+
registry: registires[0].regk,
267+
schema: SCHEMA_SAID,
268+
recipient: holderPrefix,
269+
data: {
270+
LEI: '5493001KJTIIGC8Y1R17',
271+
},
272+
});
273+
274+
const grantNotification = await waitForNotification(
275+
holderClient,
276+
'/exn/ipex/grant'
277+
);
278+
279+
await admitCredential(
280+
holderClient,
281+
'holder',
282+
grantNotification.a.d!,
283+
issuerPrefix
284+
);
285+
286+
await holderClient.notifications().mark(grantNotification.i);
287+
288+
await wait(async () => {
289+
const creds = await holderClient.credentials().list();
290+
assert(creds.length >= 1);
291+
});
292+
},
293+
1000 * 60 * 5
294+
);

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"build:types": "tsc -p tsconfig.build.json",
2222
"build": "npm run build:cjs && npm run build:esm && npm run build:types",
2323
"test": "jest test/",
24-
"test:integration": "jest test-integration/",
25-
"lint": "npx eslint src test test-integration examples/integration-scripts examples/scripts",
24+
"test:integration": "jest examples/integration-scripts/",
25+
"lint": "npx eslint src test examples/integration-scripts examples/scripts",
2626
"prepare": "npm run build",
2727
"generate-docs": "node_modules/.bin/jsdoc --configure .jsdoc.json --verbose",
2828
"pretty": "prettier --config .prettierrc 'src/**/*.ts' 'test/**/*.ts' 'examples/**/*.ts' --write"

test-integration/single-issuer-holder.test.ts

Lines changed: 0 additions & 84 deletions
This file was deleted.

tsconfig.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"include": ["src", "types", "test", "test-integration"],
3-
"extends": "./tsconfig.node.json",
4-
"compilerOptions": {
5-
"noEmit": true,
6-
"allowImportingTsExtensions": true
7-
}
2+
"include": ["src", "types", "test", "examples/integration-scripts"],
3+
"extends": "./tsconfig.node.json",
4+
"compilerOptions": {
5+
"noEmit": true,
6+
"allowImportingTsExtensions": true
7+
}
88
}

0 commit comments

Comments
 (0)