Skip to content

Commit

Permalink
Fix flaky integration tests by waiting for operations (WebOfTrust#210)
Browse files Browse the repository at this point in the history
* fix addEndRole return type

* update Operation type, add list and delete methods to Operations

* fix Notifications.delete

* make waitOperation check dependent operations

client side fix for WebOfTrust/keria#147
add markNotification and markAndRemoveNotification

* use waitOperation and markAndRemoveNotification where needed

* rename to assertOperations

* rename to assertNotifications

* cleanup

* simplify with toHaveLength(0)

* adds warnNotifications

* uses warnNotifications

* fixed to handle all notifications

* npm run pretty

* unit tests for operations.list and .delete

* add missing await
  • Loading branch information
psteniusubi authored Feb 11, 2024
1 parent 2082760 commit 5292b24
Show file tree
Hide file tree
Showing 21 changed files with 404 additions and 111 deletions.
16 changes: 13 additions & 3 deletions examples/integration-scripts/challenge.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
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';
import {
assertOperations,
resolveOobi,
waitOperation,
} from './utils/test-util';

const { url, bootUrl } = resolveEnvironment();

Expand Down Expand Up @@ -59,9 +63,10 @@ test('challenge', async () => {
client1,
await icpResult1.op()
);
await client1
let rpyResult1 = await client1
.identifiers()
.addEndRole('alice', 'agent', client1!.agent!.pre);
await waitOperation(client1, await rpyResult1.op());
console.log("Alice's AID:", aid1.i);

const icpResult2 = await client2.identifiers().create('bob', {
Expand All @@ -76,7 +81,10 @@ test('challenge', async () => {
client2,
await icpResult2.op()
);
await client2.identifiers().addEndRole('bob', 'agent', client2!.agent!.pre);
let rpyResult2 = await client2
.identifiers()
.addEndRole('bob', 'agent', client2!.agent!.pre);
await waitOperation(client2, await rpyResult2.op());

// Exchenge OOBIs
const oobi1 = await client1.oobis().get('alice', 'agent');
Expand Down Expand Up @@ -121,4 +129,6 @@ test('challenge', async () => {
(contact: { alias: string }) => contact.alias === 'bob'
);
expect(bobContact.challenges[0].authenticated).toEqual(true);

await assertOperations(client1, client2);
}, 30000);
80 changes: 62 additions & 18 deletions examples/integration-scripts/credentials.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { strict as assert } from 'assert';
import { Saider, Serder, SignifyClient } from 'signify-ts';
import { resolveEnvironment } from './utils/resolve-env';
import {
assertNotifications,
assertOperations,
markAndRemoveNotification,
resolveOobi,
waitForNotifications,
waitOperation,
Expand Down Expand Up @@ -75,6 +78,21 @@ beforeAll(async () => {
]);
});

afterAll(async () => {
await assertOperations(
issuerClient,
holderClient,
verifierClient,
legalEntityClient
);
await assertNotifications(
issuerClient,
holderClient,
verifierClient,
legalEntityClient
);
});

test('single signature credentials', async () => {
await step('Resolve schema oobis', async () => {
await Promise.all([
Expand Down Expand Up @@ -211,11 +229,12 @@ test('single signature credentials', async () => {
datetime: dt,
});

await issuerClient
let op = await issuerClient
.ipex()
.submitGrant(issuerAid.name, grant, gsigs, gend, [
holderAid.prefix,
]);
await waitOperation(issuerClient, op);
});

await step('holder IPEX admit', async () => {
Expand All @@ -233,11 +252,20 @@ test('single signature credentials', async () => {
grantNotification.a.d!,
createTimestamp()
);
await holderClient
let op = await holderClient
.ipex()
.submitAdmit(holderAid.name, admit, sigs, aend, [issuerAid.prefix]);
await waitOperation(holderClient, op);

await holderClient.notifications().mark(grantNotification.i);
await markAndRemoveNotification(holderClient, grantNotification);
});

await step('issuer IPEX grant response', async () => {
const issuerNotifications = await waitForNotifications(
issuerClient,
'/exn/ipex/admit'
);
await markAndRemoveNotification(issuerClient, issuerNotifications[0]);
});

await step('holder has credential', async () => {
Expand Down Expand Up @@ -270,16 +298,13 @@ test('single signature credentials', async () => {
issAttachment: holderCredential.issAtc,
datetime: createTimestamp(),
});
await holderClient
.exchanges()
.sendFromEvents(
holderAid.name,
'presentation',
grant2,
gsigs2,
gend2,
[verifierAid.prefix]
);

let op = await holderClient
.ipex()
.submitGrant(holderAid.name, grant2, gsigs2, gend2, [
verifierAid.prefix,
]);
await waitOperation(holderClient, op);
});

await step('verifier receives IPEX grant', async () => {
Expand All @@ -299,13 +324,14 @@ test('single signature credentials', async () => {
createTimestamp()
);

await verifierClient
let op = await verifierClient
.ipex()
.submitAdmit(verifierAid.name, admit3, sigs3, aend3, [
holderAid.prefix,
]);
await waitOperation(verifierClient, op);

await verifierClient.notifications().mark(verifierGrantNote.i);
await markAndRemoveNotification(verifierClient, verifierGrantNote);

const verifierCredential = await retry(async () =>
verifierClient.credentials().get(qviCredentialId)
Expand All @@ -316,6 +342,14 @@ test('single signature credentials', async () => {
assert.equal(verifierCredential.status.s, '0'); // 0 = issued
});

await step('holder IPEX present response', async () => {
const holderNotifications = await waitForNotifications(
holderClient,
'/exn/ipex/admit'
);
await markAndRemoveNotification(holderClient, holderNotifications[0]);
});

const holderRegistry: { regk: string } = await step(
'holder create registry for LE credential',
async () => {
Expand Down Expand Up @@ -388,11 +422,12 @@ test('single signature credentials', async () => {
datetime: dt,
});

await holderClient
let op = await holderClient
.ipex()
.submitGrant(holderAid.name, grant, gsigs, gend, [
legalEntityAid.prefix,
]);
await waitOperation(holderClient, op);
});

await step('Legal Entity IPEX admit', async () => {
Expand All @@ -411,13 +446,22 @@ test('single signature credentials', async () => {
createTimestamp()
);

await legalEntityClient
let op = await legalEntityClient
.ipex()
.submitAdmit(legalEntityAid.name, admit, sigs, aend, [
holderAid.prefix,
]);
await waitOperation(legalEntityClient, op);

await legalEntityClient.notifications().mark(grantNotification.i);
await markAndRemoveNotification(legalEntityClient, grantNotification);
});

await step('LE credential IPEX grant response', async () => {
const notifications = await waitForNotifications(
holderClient,
'/exn/ipex/admit'
);
await markAndRemoveNotification(holderClient, notifications[0]);
});

await step('Legal Entity has chained credential', async () => {
Expand Down
30 changes: 15 additions & 15 deletions examples/integration-scripts/delegation-multisig.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { strict as assert } from 'assert';
import signify from 'signify-ts';
import {
assertOperations,
markAndRemoveNotification,
resolveOobi,
waitForNotifications,
waitOperation,
warnNotifications,
} from './utils/test-util';
import { getOrCreateClient } from './utils/test-setup';
import { getOrCreateClient, getOrCreateIdentifier } from './utils/test-setup';

test('delegation-multisig', async () => {
await signify.ready();
Expand Down Expand Up @@ -85,14 +88,16 @@ test('delegation-multisig', async () => {

// Second member check notifications and join the multisig
const notifications = await waitForNotifications(client2, '/multisig/icp');
await Promise.all(
notifications.map((note) => client2.notifications().mark(note.i))
);
const msgSaid = notifications[notifications.length - 1].a.d;
assert(msgSaid !== undefined);
console.log('Member2 received exchange message to join multisig');

const res = await client2.groups().getRequest(msgSaid);

await Promise.all(
notifications.map((note) => markAndRemoveNotification(client2, note))
);

const exn = res[0].exn;
const icp = exn.e.icp;

Expand Down Expand Up @@ -145,7 +150,8 @@ test('delegation-multisig', async () => {
s: '0',
d: delegatePrefix,
};
await client0.identifiers().interact('delegator', anchor);
let ixnResult = await client0.identifiers().interact('delegator', anchor);
await waitOperation(client0, await ixnResult.op());
console.log('Delegator approved delegation');

let op3 = await client1.keyStates().query(aid0.prefix, '1');
Expand All @@ -162,20 +168,14 @@ test('delegation-multisig', async () => {

const aid_delegate = await client1.identifiers().get('multisig');
assert.equal(aid_delegate.prefix, delegatePrefix);

await assertOperations(client0, client1, client2);
await warnNotifications(client0, client1, client2);
}, 30000);

async function createAID(client: signify.SignifyClient, name: string) {
const icpResult1 = await client.identifiers().create(name, {
toad: 3,
wits: [
'BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha',
'BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM',
'BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX',
],
});
await waitOperation(client, await icpResult1.op());
await getOrCreateIdentifier(client, name);
const aid = await client.identifiers().get(name);
await client.identifiers().addEndRole(name, 'agent', client!.agent!.pre);
console.log(name, 'AID:', aid.prefix);
return aid;
}
16 changes: 13 additions & 3 deletions examples/integration-scripts/delegation.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +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';
import {
assertOperations,
resolveOobi,
waitOperation,
} from './utils/test-util';

const { url, bootUrl } = resolveEnvironment();

Expand Down Expand Up @@ -52,9 +56,10 @@ test('delegation', async () => {
});
await waitOperation(client1, await icpResult1.op());
const aid1 = await client1.identifiers().get('delegator');
await client1
const rpyResult1 = await client1
.identifiers()
.addEndRole('delegator', 'agent', client1!.agent!.pre);
await waitOperation(client1, await rpyResult1.op());
console.log("Delegator's AID:", aid1.prefix);

// Client 2 resolves delegator OOBI
Expand All @@ -78,7 +83,10 @@ test('delegation', async () => {
s: '0',
d: delegatePrefix,
};
await client1.identifiers().interact('delegator', anchor);
const ixnResult1 = await client1
.identifiers()
.interact('delegator', anchor);
await waitOperation(client1, await ixnResult1.op());
console.log('Delegator approved delegation');

let op3 = await client2.keyStates().query(aid1.prefix, '1');
Expand All @@ -89,4 +97,6 @@ test('delegation', async () => {
const aid2 = await client2.identifiers().get('delegate');
assert.equal(aid2.prefix, delegatePrefix);
console.log('Delegation approved for aid:', aid2.prefix);

await assertOperations(client1, client2);
}, 60000);
5 changes: 4 additions & 1 deletion examples/integration-scripts/externalModule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { strict as assert } from 'assert';
import signify from 'signify-ts';
import { BIP39Shim } from './modules/bip39_shim';
import { resolveEnvironment } from './utils/resolve-env';
import { assertOperations, waitOperation } from './utils/test-util';

const { url, bootUrl } = resolveEnvironment();

Expand Down Expand Up @@ -35,6 +36,8 @@ test('bip39_shim', async () => {
extern_type: 'bip39_shim',
extern: { mnemonics: words },
});
const op = await icpResult.op();
const op = await waitOperation(client1, await icpResult.op());
assert.equal(op['done'], true);

await assertOperations(client1);
}, 30000);
Loading

0 comments on commit 5292b24

Please sign in to comment.