Skip to content

Commit

Permalink
Merge pull request #161 from lenkan/move-remaining-integration-tests
Browse files Browse the repository at this point in the history
convert remaining integration-scripts to tests
  • Loading branch information
lenkan authored Dec 6, 2023
2 parents acfa4c6 + 85e0f5c commit 3039ace
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 183 deletions.
17 changes: 0 additions & 17 deletions examples/integration-scripts/README.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import { strict as assert } from 'assert';
import signify, { Serder } from 'signify-ts';
import { resolveEnvironment } from './utils/resolve-env';
import { resolveOobi, waitOperation } from './utils/test-util';

const url = 'http://127.0.0.1:3901';
const boot_url = 'http://127.0.0.1:3903';
const { url, bootUrl } = resolveEnvironment();

await run();

async function run() {
test('challenge', async () => {
await signify.ready();
// Boot two clients
const bran1 = signify.randomPasscode();
const bran2 = signify.randomPasscode();
const client1 = new signify.SignifyClient(
url,
bran1,
signify.Tier.low,
boot_url
bootUrl
);
const client2 = new signify.SignifyClient(
url,
bran2,
signify.Tier.low,
boot_url
bootUrl
);
await client1.boot();
await client2.boot();
Expand Down Expand Up @@ -57,12 +55,10 @@ async function run() {
'BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX',
],
});
let op1 = await icpResult1.op();
while (!op1['done']) {
op1 = await client1.operations().get(op1.name);
await new Promise((resolve) => setTimeout(resolve, 1000));
}
const aid1 = op1['response'];
const { response: aid1 } = await waitOperation<{ i: string }>(
client1,
await icpResult1.op()
);
await client1
.identifiers()
.addEndRole('alice', 'agent', client1!.agent!.pre);
Expand All @@ -89,43 +85,39 @@ async function run() {
const oobi1 = await client1.oobis().get('alice', 'agent');
const oobi2 = await client2.oobis().get('bob', 'agent');

op1 = await client1.oobis().resolve(oobi2.oobis[0], 'bob');
while (!op1['done']) {
op1 = await client1.operations().get(op1.name);
await new Promise((resolve) => setTimeout(resolve, 1000));
}
await resolveOobi(client1, oobi2.oobis[0], 'bob');
console.log("Client 1 resolved Bob's OOBI");
op2 = await client2.oobis().resolve(oobi1.oobis[0], 'alice');
while (!op2['done']) {
op2 = await client2.operations().get(op2.name);
await new Promise((resolve) => setTimeout(resolve, 1000));
}
await resolveOobi(client2, oobi1.oobis[0], 'alice');
console.log("Client 2 resolved Alice's OOBI");

// List Client 1 contacts
let contacts1 = await client1.contacts().list();
assert.equal(contacts1[3].alias, 'bob');
expect(contacts1[0].alias).toEqual('bob');
expect(contacts1[0].challenges).toHaveLength(0);

// Bob responds to Alice challenge
await client2.challenges().respond('bob', aid1.i, challenge1_small.words);
console.log('Bob responded to Alice challenge with signed words');

// Alice verifies Bob's response
op1 = await client1
.challenges()
.verify('alice', aid2.i, challenge1_small.words);
while (!op1['done']) {
op1 = await client1.operations().get(op1.name);
await new Promise((resolve) => setTimeout(resolve, 1000));
}
const verifyOperation = await waitOperation(
client1,
await client1
.challenges()
.verify('alice', aid2.i, challenge1_small.words)
);
console.log('Alice verified challenge response');

//Alice mark response as accepted
const exn = new Serder(op1.response.exn);
op1 = await client1.challenges().responded('alice', aid2.i, exn.ked.d);
const verifyResponse = verifyOperation.response as {
exn: Record<string, unknown>;
};
const exn = new Serder(verifyResponse.exn);

await client1.challenges().responded('alice', aid2.i, exn.ked.d);
console.log('Alice marked challenge response as accepted');

// Check Bob's challenge in conctats
contacts1 = await client1.contacts().list();
console.log('Challenge authenticated');
}
expect(contacts1[0].challenges[0].authenticated).toEqual(true);
}, 30000);
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { strict as assert } from 'assert';
import signify from 'signify-ts';
import { resolveEnvironment } from './utils/resolve-env';
import { resolveOobi, waitOperation } from './utils/test-util';

const url = 'http://127.0.0.1:3901';
const boot_url = 'http://127.0.0.1:3903';
const { url, bootUrl } = resolveEnvironment();

await run();

async function run() {
test('delegation', async () => {
await signify.ready();
// Boot two clients
const bran1 = signify.randomPasscode();
Expand All @@ -15,13 +14,13 @@ async function run() {
url,
bran1,
signify.Tier.low,
boot_url
bootUrl
);
const client2 = new signify.SignifyClient(
url,
bran2,
signify.Tier.low,
boot_url
bootUrl
);
await client1.boot();
await client2.boot();
Expand Down Expand Up @@ -52,10 +51,7 @@ async function run() {
],
});
let op1 = await icpResult1.op();
while (!op1['done']) {
op1 = await client1.operations().get(op1.name);
await new Promise((resolve) => setTimeout(resolve, 1000));
}
await waitOperation(client1, op1);
const aid1 = await client1.identifiers().get('delegator');
await client1
.identifiers()
Expand All @@ -65,18 +61,14 @@ async function run() {
// Client 2 resolves delegator OOBI
console.log('Client 2 resolving delegator OOBI');
const oobi1 = await client1.oobis().get('delegator', 'agent');
let op2 = await client2.oobis().resolve(oobi1.oobis[0], 'delegator');
while (!op2['done']) {
op2 = await client2.operations().get(op2.name);
await new Promise((resolve) => setTimeout(resolve, 1000));
}
await resolveOobi(client2, oobi1.oobis[0], 'delegator');
console.log('OOBI resolved');

// Client 2 creates delegate AID
const icpResult2 = await client2
.identifiers()
.create('delegate', { delpre: aid1.prefix });
op2 = await icpResult2.op();
let op2 = await icpResult2.op();

Check warning on line 71 in examples/integration-scripts/delegation.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18.12.1 and macOS-latest

'op2' is never reassigned. Use 'const' instead

Check warning on line 71 in examples/integration-scripts/delegation.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18.12.1 and ubuntu-latest

'op2' is never reassigned. Use 'const' instead
const delegatePrefix = op2.name.split('.')[1];
console.log("Delegate's prefix:", delegatePrefix);
console.log('Delegate waiting for approval...');
Expand All @@ -91,11 +83,8 @@ async function run() {
console.log('Delegator approved delegation');

// Client 2 check approval
while (!op2['done']) {
op2 = await client2.operations().get(op2.name);
await new Promise((resolve) => setTimeout(resolve, 1000));
}
await waitOperation(client2, op2);
const aid2 = await client2.identifiers().get('delegate');
assert.equal(aid2.prefix, delegatePrefix);
console.log('Delegation approved for aid:', aid2.prefix);
}
}, 60000);
Loading

0 comments on commit 3039ace

Please sign in to comment.