Skip to content

Commit 43eea4c

Browse files
committed
Draft for running integration tests
1 parent 645d665 commit 43eea4c

File tree

9 files changed

+419
-11
lines changed

9 files changed

+419
-11
lines changed

.github/workflows/main.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
runs-on: ${{ matrix.os }}
1717
strategy:
1818
matrix:
19-
os: [ macOS-latest, ubuntu-latest]
19+
os: [macOS-latest, ubuntu-latest]
2020

2121
steps:
2222
- name: Checkout repo
@@ -39,3 +39,22 @@ jobs:
3939
uses: codecov/codecov-action@v3
4040
env:
4141
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
42+
43+
test:
44+
name: Run integration test
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: Checkout repo
48+
uses: actions/checkout@v2
49+
50+
- uses: actions/setup-node@v2
51+
with:
52+
node-version: '18.12.1'
53+
cache: 'npm'
54+
- name: install deps
55+
run: |
56+
npm ci
57+
- name: Start dependencies
58+
run: docker compose up deps
59+
- name: Run integration test
60+
run: npm run test:integration

docker-compose.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
services:
2+
vlei-server:
3+
image: lenkan/vlei
4+
command: ["vLEI-server", "-s", "./schema/acdc", "-c", "./samples/acdc/", "-o", "./samples/oobis/"]
5+
healthcheck:
6+
test: ["CMD", "curl", "-f", "http://localhost:7723/oobi/EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao"]
7+
interval: 2s
8+
timeout: 3s
9+
retries: 5
10+
start_period: 2s
11+
ports:
12+
- 7723:7723
13+
14+
keria:
15+
image: lenkan/keria
16+
environment:
17+
- KERI_AGENT_CORS=1
18+
- KERI_URL=http://keria:3902
19+
volumes:
20+
- ./images/keria/entrypoint.sh:/keria/entrypoint.sh
21+
entrypoint: /keria/entrypoint.sh
22+
healthcheck:
23+
test: ["CMD", "curl", "-f", "http://localhost:3902/spec.yaml"]
24+
interval: 2s
25+
timeout: 3s
26+
retries: 5
27+
start_period: 2s
28+
ports:
29+
- 3901:3901
30+
- 3902:3902
31+
- 3903:3903
32+
33+
witness-demo:
34+
image: lenkan/keri-witness-demo
35+
healthcheck:
36+
test: ["CMD", "curl", "-f", "http://localhost:5642/oobi"]
37+
interval: 2s
38+
timeout: 3s
39+
retries: 5
40+
start_period: 2s
41+
ports:
42+
- 5642:5642
43+
- 5643:5643
44+
- 5644:5644
45+
46+
deps:
47+
image: alpine
48+
command: ["echo", "Dependencies running"]
49+
depends_on:
50+
vlei-server:
51+
condition: service_healthy
52+
keria:
53+
condition: service_healthy
54+
witness-demo:
55+
condition: service_healthy
56+

images/keria/entrypoint.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
keri_url=${KERI_URL:-"http://127.0.0.1:3902"}
4+
timestamp=$(date -In | sed s/,000000000/.000000/g)
5+
config_dir="/keria/config"
6+
config_file="$config_dir/keri/cf/agent.json"
7+
8+
mkdir -p "$config_dir/keri/cf"
9+
10+
cat > "$config_file" <<EOF
11+
{
12+
"keria": {
13+
"dt": "$timestamp",
14+
"curls": ["$keri_url"]
15+
}
16+
}
17+
EOF
18+
19+
cat $config_file
20+
21+
keria start --config-dir "$config_dir" --config-file agent --name agent

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
"start": "npm run build:esm -- --watch",
1919
"build:cjs": "esbuild src/index.ts --bundle --outfile=dist/signify-ts.cjs --platform=neutral --format=cjs --sourcemap --packages=external",
2020
"build:esm": "esbuild src/index.ts --bundle --outfile=dist/signify-ts.mjs --platform=neutral --format=esm --sourcemap --packages=external",
21-
"build:types": "tsc --declaration --outDir dist",
21+
"build:types": "tsc -p tsconfig.build.json",
2222
"build": "npm run build:cjs && npm run build:esm && npm run build:types",
23-
"test": "jest",
24-
"lint": "npx eslint src test examples/integration-scripts examples/scripts",
23+
"test": "jest test/",
24+
"test:integration": "jest test-integration/",
25+
"lint": "npx eslint src test test-integration examples/integration-scripts examples/scripts",
2526
"prepare": "npm run build",
2627
"generate-docs": "node_modules/.bin/jsdoc --configure .jsdoc.json --verbose",
2728
"pretty": "prettier --config .prettierrc 'src/**/*.ts' 'test/**/*.ts' 'examples/**/*.ts' --write"

src/keri/app/coring.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,27 @@ export class Operations {
8888
let res = await this.client.fetch(path, method, data);
8989
return await res.json();
9090
}
91+
92+
async wait(name: string, timeout?: number): Promise<any> {
93+
const now = Date.now();
94+
let op = await this.get(name);
95+
96+
while (!op['done']) {
97+
op = await this.get(name);
98+
if (op['done']) {
99+
return op;
100+
}
101+
102+
const elapsed = Date.now() - now;
103+
if (timeout !== undefined && elapsed > timeout) {
104+
throw new Error(
105+
`Operation '${op.name}' time out after ${elapsed} ms`
106+
);
107+
}
108+
109+
await new Promise((resolve) => setTimeout(resolve, 1000));
110+
}
111+
}
91112
}
92113

93114
/**
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import assert from 'assert';
2+
import signify from '../src/index.ts';
3+
import {
4+
admitCredential,
5+
connect,
6+
createIdentifier,
7+
createRegistry,
8+
getAgentOobi,
9+
issueCredential,
10+
resolveOobi,
11+
wait,
12+
waitForNotification,
13+
} from './test-utils.ts';
14+
15+
const URL = 'http://127.0.0.1:3901';
16+
const BOOT_URL = 'http://127.0.0.1:3903';
17+
const SCHEMA_SAID = 'EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao';
18+
const WITNESS_AIDS: string[] = []; // ['BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha'];
19+
const SCHEMA_OOBI =
20+
'http://vlei-server:7723/oobi/EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao';
21+
22+
test(
23+
'Single issuer holder',
24+
async () => {
25+
await signify.ready();
26+
const issuerClient = await connect(URL, BOOT_URL);
27+
const holderClient = await connect(URL, BOOT_URL);
28+
29+
await issuerClient.state();
30+
await holderClient.state();
31+
32+
// Create two identifiers, one for each client
33+
const issuerPrefix = await createIdentifier(
34+
issuerClient,
35+
'issuer',
36+
WITNESS_AIDS
37+
);
38+
const holderPrefix = await createIdentifier(
39+
holderClient,
40+
'holder',
41+
WITNESS_AIDS
42+
);
43+
44+
// Exchange OOBIs
45+
const issuerOobi = await getAgentOobi(issuerClient, 'issuer');
46+
const holderOobi = await getAgentOobi(holderClient, 'holder');
47+
await resolveOobi(issuerClient, holderOobi, 'holder');
48+
await resolveOobi(issuerClient, SCHEMA_OOBI, 'schema');
49+
await resolveOobi(holderClient, issuerOobi, 'issuer');
50+
await resolveOobi(holderClient, SCHEMA_OOBI, 'schema');
51+
52+
await createRegistry(issuerClient, 'issuer', 'vLEI');
53+
54+
const registires = await issuerClient.registries().list('issuer');
55+
await issueCredential(issuerClient, 'issuer', {
56+
registry: registires[0].regk,
57+
schema: SCHEMA_SAID,
58+
recipient: holderPrefix,
59+
data: {
60+
LEI: '5493001KJTIIGC8Y1R17',
61+
},
62+
});
63+
64+
const grantNotification = await waitForNotification(
65+
holderClient,
66+
'/exn/ipex/grant'
67+
);
68+
69+
await admitCredential(
70+
holderClient,
71+
'holder',
72+
grantNotification.a.d!,
73+
issuerPrefix
74+
);
75+
76+
await holderClient.notifications().mark(grantNotification.i);
77+
78+
await wait(async () => {
79+
const creds = await holderClient.credentials().list();
80+
assert(creds.length >= 1);
81+
});
82+
},
83+
1000 * 60 * 5
84+
);

0 commit comments

Comments
 (0)