Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky integration tests by waiting for operations #210

Merged
Merged
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 @@
client1,
await icpResult1.op()
);
await client1
let rpyResult1 = await client1

Check warning on line 66 in examples/integration-scripts/challenge.test.ts

View workflow job for this annotation

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

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

Check warning on line 66 in examples/integration-scripts/challenge.test.ts

View workflow job for this annotation

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

'rpyResult1' is never reassigned. Use 'const' instead
.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 @@
client2,
await icpResult2.op()
);
await client2.identifiers().addEndRole('bob', 'agent', client2!.agent!.pre);
let rpyResult2 = await client2

Check warning on line 84 in examples/integration-scripts/challenge.test.ts

View workflow job for this annotation

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

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

Check warning on line 84 in examples/integration-scripts/challenge.test.ts

View workflow job for this annotation

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

'rpyResult2' is never reassigned. Use 'const' instead
.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 @@
(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 { 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 @@
]);
});

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 @@
datetime: dt,
});

await issuerClient
let op = await issuerClient

Check warning on line 232 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

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

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

Check warning on line 232 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

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

'op' is never reassigned. Use 'const' instead
.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 @@
grantNotification.a.d!,
createTimestamp()
);
await holderClient
let op = await holderClient

Check warning on line 255 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

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

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

Check warning on line 255 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

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

'op' is never reassigned. Use 'const' instead
.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 @@
issAttachment: holderCredential.issAtc,
datetime: createTimestamp(),
});
await holderClient
.exchanges()
.sendFromEvents(
holderAid.name,
'presentation',
grant2,
gsigs2,
gend2,
[verifierAid.prefix]
);

let op = await holderClient

Check warning on line 302 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

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

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

Check warning on line 302 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

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

'op' is never reassigned. Use 'const' instead
.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 @@
createTimestamp()
);

await verifierClient
let op = await verifierClient

Check warning on line 327 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

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

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

Check warning on line 327 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

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

'op' is never reassigned. Use 'const' instead
.ipex()
.submitAdmit(verifierAid.name, admit3, sigs3, aend3, [
holderAid.prefix,
]);
waitOperation(verifierClient, op);
lenkan marked this conversation as resolved.
Show resolved Hide resolved

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 @@
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 @@
datetime: dt,
});

await holderClient
let op = await holderClient

Check warning on line 425 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

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

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

Check warning on line 425 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

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

'op' is never reassigned. Use 'const' instead
.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 @@
createTimestamp()
);

await legalEntityClient
let op = await legalEntityClient

Check warning on line 449 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

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

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

Check warning on line 449 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

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

'op' is never reassigned. Use 'const' instead
.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 @@

// 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,10 +150,11 @@
s: '0',
d: delegatePrefix,
};
await client0.identifiers().interact('delegator', anchor);
let ixnResult = await client0.identifiers().interact('delegator', anchor);

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

View workflow job for this annotation

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

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

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

View workflow job for this annotation

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

'ixnResult' is never reassigned. Use 'const' instead
await waitOperation(client0, await ixnResult.op());
console.log('Delegator approved delegation');

let op3 = await client1.keyStates().query(aid0.prefix, '1');

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

View workflow job for this annotation

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

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

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

View workflow job for this annotation

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

'op3' is never reassigned. Use 'const' instead
let op4 = await client2.keyStates().query(aid0.prefix, '1');

// Check for completion
Expand All @@ -162,20 +168,14 @@

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
Loading