Skip to content

Commit 5292b24

Browse files
authored
Fix flaky integration tests by waiting for operations (#210)
* 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
1 parent 2082760 commit 5292b24

21 files changed

+404
-111
lines changed

examples/integration-scripts/challenge.test.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { strict as assert } from 'assert';
22
import signify, { Serder } from 'signify-ts';
33
import { resolveEnvironment } from './utils/resolve-env';
4-
import { resolveOobi, waitOperation } from './utils/test-util';
4+
import {
5+
assertOperations,
6+
resolveOobi,
7+
waitOperation,
8+
} from './utils/test-util';
59

610
const { url, bootUrl } = resolveEnvironment();
711

@@ -59,9 +63,10 @@ test('challenge', async () => {
5963
client1,
6064
await icpResult1.op()
6165
);
62-
await client1
66+
let rpyResult1 = await client1
6367
.identifiers()
6468
.addEndRole('alice', 'agent', client1!.agent!.pre);
69+
await waitOperation(client1, await rpyResult1.op());
6570
console.log("Alice's AID:", aid1.i);
6671

6772
const icpResult2 = await client2.identifiers().create('bob', {
@@ -76,7 +81,10 @@ test('challenge', async () => {
7681
client2,
7782
await icpResult2.op()
7883
);
79-
await client2.identifiers().addEndRole('bob', 'agent', client2!.agent!.pre);
84+
let rpyResult2 = await client2
85+
.identifiers()
86+
.addEndRole('bob', 'agent', client2!.agent!.pre);
87+
await waitOperation(client2, await rpyResult2.op());
8088

8189
// Exchenge OOBIs
8290
const oobi1 = await client1.oobis().get('alice', 'agent');
@@ -121,4 +129,6 @@ test('challenge', async () => {
121129
(contact: { alias: string }) => contact.alias === 'bob'
122130
);
123131
expect(bobContact.challenges[0].authenticated).toEqual(true);
132+
133+
await assertOperations(client1, client2);
124134
}, 30000);

examples/integration-scripts/credentials.test.ts

+62-18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { strict as assert } from 'assert';
22
import { Saider, Serder, SignifyClient } from 'signify-ts';
33
import { resolveEnvironment } from './utils/resolve-env';
44
import {
5+
assertNotifications,
6+
assertOperations,
7+
markAndRemoveNotification,
58
resolveOobi,
69
waitForNotifications,
710
waitOperation,
@@ -75,6 +78,21 @@ beforeAll(async () => {
7578
]);
7679
});
7780

81+
afterAll(async () => {
82+
await assertOperations(
83+
issuerClient,
84+
holderClient,
85+
verifierClient,
86+
legalEntityClient
87+
);
88+
await assertNotifications(
89+
issuerClient,
90+
holderClient,
91+
verifierClient,
92+
legalEntityClient
93+
);
94+
});
95+
7896
test('single signature credentials', async () => {
7997
await step('Resolve schema oobis', async () => {
8098
await Promise.all([
@@ -211,11 +229,12 @@ test('single signature credentials', async () => {
211229
datetime: dt,
212230
});
213231

214-
await issuerClient
232+
let op = await issuerClient
215233
.ipex()
216234
.submitGrant(issuerAid.name, grant, gsigs, gend, [
217235
holderAid.prefix,
218236
]);
237+
await waitOperation(issuerClient, op);
219238
});
220239

221240
await step('holder IPEX admit', async () => {
@@ -233,11 +252,20 @@ test('single signature credentials', async () => {
233252
grantNotification.a.d!,
234253
createTimestamp()
235254
);
236-
await holderClient
255+
let op = await holderClient
237256
.ipex()
238257
.submitAdmit(holderAid.name, admit, sigs, aend, [issuerAid.prefix]);
258+
await waitOperation(holderClient, op);
239259

240-
await holderClient.notifications().mark(grantNotification.i);
260+
await markAndRemoveNotification(holderClient, grantNotification);
261+
});
262+
263+
await step('issuer IPEX grant response', async () => {
264+
const issuerNotifications = await waitForNotifications(
265+
issuerClient,
266+
'/exn/ipex/admit'
267+
);
268+
await markAndRemoveNotification(issuerClient, issuerNotifications[0]);
241269
});
242270

243271
await step('holder has credential', async () => {
@@ -270,16 +298,13 @@ test('single signature credentials', async () => {
270298
issAttachment: holderCredential.issAtc,
271299
datetime: createTimestamp(),
272300
});
273-
await holderClient
274-
.exchanges()
275-
.sendFromEvents(
276-
holderAid.name,
277-
'presentation',
278-
grant2,
279-
gsigs2,
280-
gend2,
281-
[verifierAid.prefix]
282-
);
301+
302+
let op = await holderClient
303+
.ipex()
304+
.submitGrant(holderAid.name, grant2, gsigs2, gend2, [
305+
verifierAid.prefix,
306+
]);
307+
await waitOperation(holderClient, op);
283308
});
284309

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

302-
await verifierClient
327+
let op = await verifierClient
303328
.ipex()
304329
.submitAdmit(verifierAid.name, admit3, sigs3, aend3, [
305330
holderAid.prefix,
306331
]);
332+
await waitOperation(verifierClient, op);
307333

308-
await verifierClient.notifications().mark(verifierGrantNote.i);
334+
await markAndRemoveNotification(verifierClient, verifierGrantNote);
309335

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

345+
await step('holder IPEX present response', async () => {
346+
const holderNotifications = await waitForNotifications(
347+
holderClient,
348+
'/exn/ipex/admit'
349+
);
350+
await markAndRemoveNotification(holderClient, holderNotifications[0]);
351+
});
352+
319353
const holderRegistry: { regk: string } = await step(
320354
'holder create registry for LE credential',
321355
async () => {
@@ -388,11 +422,12 @@ test('single signature credentials', async () => {
388422
datetime: dt,
389423
});
390424

391-
await holderClient
425+
let op = await holderClient
392426
.ipex()
393427
.submitGrant(holderAid.name, grant, gsigs, gend, [
394428
legalEntityAid.prefix,
395429
]);
430+
await waitOperation(holderClient, op);
396431
});
397432

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

414-
await legalEntityClient
449+
let op = await legalEntityClient
415450
.ipex()
416451
.submitAdmit(legalEntityAid.name, admit, sigs, aend, [
417452
holderAid.prefix,
418453
]);
454+
await waitOperation(legalEntityClient, op);
419455

420-
await legalEntityClient.notifications().mark(grantNotification.i);
456+
await markAndRemoveNotification(legalEntityClient, grantNotification);
457+
});
458+
459+
await step('LE credential IPEX grant response', async () => {
460+
const notifications = await waitForNotifications(
461+
holderClient,
462+
'/exn/ipex/admit'
463+
);
464+
await markAndRemoveNotification(holderClient, notifications[0]);
421465
});
422466

423467
await step('Legal Entity has chained credential', async () => {

examples/integration-scripts/delegation-multisig.test.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { strict as assert } from 'assert';
22
import signify from 'signify-ts';
33
import {
4+
assertOperations,
5+
markAndRemoveNotification,
46
resolveOobi,
57
waitForNotifications,
68
waitOperation,
9+
warnNotifications,
710
} from './utils/test-util';
8-
import { getOrCreateClient } from './utils/test-setup';
11+
import { getOrCreateClient, getOrCreateIdentifier } from './utils/test-setup';
912

1013
test('delegation-multisig', async () => {
1114
await signify.ready();
@@ -85,14 +88,16 @@ test('delegation-multisig', async () => {
8588

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

9595
const res = await client2.groups().getRequest(msgSaid);
96+
97+
await Promise.all(
98+
notifications.map((note) => markAndRemoveNotification(client2, note))
99+
);
100+
96101
const exn = res[0].exn;
97102
const icp = exn.e.icp;
98103

@@ -145,7 +150,8 @@ test('delegation-multisig', async () => {
145150
s: '0',
146151
d: delegatePrefix,
147152
};
148-
await client0.identifiers().interact('delegator', anchor);
153+
let ixnResult = await client0.identifiers().interact('delegator', anchor);
154+
await waitOperation(client0, await ixnResult.op());
149155
console.log('Delegator approved delegation');
150156

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

163169
const aid_delegate = await client1.identifiers().get('multisig');
164170
assert.equal(aid_delegate.prefix, delegatePrefix);
171+
172+
await assertOperations(client0, client1, client2);
173+
await warnNotifications(client0, client1, client2);
165174
}, 30000);
166175

167176
async function createAID(client: signify.SignifyClient, name: string) {
168-
const icpResult1 = await client.identifiers().create(name, {
169-
toad: 3,
170-
wits: [
171-
'BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha',
172-
'BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM',
173-
'BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX',
174-
],
175-
});
176-
await waitOperation(client, await icpResult1.op());
177+
await getOrCreateIdentifier(client, name);
177178
const aid = await client.identifiers().get(name);
178-
await client.identifiers().addEndRole(name, 'agent', client!.agent!.pre);
179179
console.log(name, 'AID:', aid.prefix);
180180
return aid;
181181
}

examples/integration-scripts/delegation.test.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { strict as assert } from 'assert';
22
import signify from 'signify-ts';
33
import { resolveEnvironment } from './utils/resolve-env';
4-
import { resolveOobi, waitOperation } from './utils/test-util';
4+
import {
5+
assertOperations,
6+
resolveOobi,
7+
waitOperation,
8+
} from './utils/test-util';
59

610
const { url, bootUrl } = resolveEnvironment();
711

@@ -52,9 +56,10 @@ test('delegation', async () => {
5256
});
5357
await waitOperation(client1, await icpResult1.op());
5458
const aid1 = await client1.identifiers().get('delegator');
55-
await client1
59+
const rpyResult1 = await client1
5660
.identifiers()
5761
.addEndRole('delegator', 'agent', client1!.agent!.pre);
62+
await waitOperation(client1, await rpyResult1.op());
5863
console.log("Delegator's AID:", aid1.prefix);
5964

6065
// Client 2 resolves delegator OOBI
@@ -78,7 +83,10 @@ test('delegation', async () => {
7883
s: '0',
7984
d: delegatePrefix,
8085
};
81-
await client1.identifiers().interact('delegator', anchor);
86+
const ixnResult1 = await client1
87+
.identifiers()
88+
.interact('delegator', anchor);
89+
await waitOperation(client1, await ixnResult1.op());
8290
console.log('Delegator approved delegation');
8391

8492
let op3 = await client2.keyStates().query(aid1.prefix, '1');
@@ -89,4 +97,6 @@ test('delegation', async () => {
8997
const aid2 = await client2.identifiers().get('delegate');
9098
assert.equal(aid2.prefix, delegatePrefix);
9199
console.log('Delegation approved for aid:', aid2.prefix);
100+
101+
await assertOperations(client1, client2);
92102
}, 60000);

examples/integration-scripts/externalModule.test.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { strict as assert } from 'assert';
22
import signify from 'signify-ts';
33
import { BIP39Shim } from './modules/bip39_shim';
44
import { resolveEnvironment } from './utils/resolve-env';
5+
import { assertOperations, waitOperation } from './utils/test-util';
56

67
const { url, bootUrl } = resolveEnvironment();
78

@@ -35,6 +36,8 @@ test('bip39_shim', async () => {
3536
extern_type: 'bip39_shim',
3637
extern: { mnemonics: words },
3738
});
38-
const op = await icpResult.op();
39+
const op = await waitOperation(client1, await icpResult.op());
3940
assert.equal(op['done'], true);
41+
42+
await assertOperations(client1);
4043
}, 30000);

0 commit comments

Comments
 (0)