From f1585fc3cc4d1a73ad15c9b9551f710193b5b05e Mon Sep 17 00:00:00 2001 From: lenkan Date: Mon, 27 Nov 2023 15:11:58 +0100 Subject: [PATCH 1/2] add witness and randy integration tests add runInBand to avoid concurrency issues add salty, external module tests --- ...ternalModule.ts => externalModule.test.ts} | 6 ++--- .../integration-scripts/modules/bip39_shim.ts | 6 ++--- .../{randy.ts => randy.test.ts} | 17 ++++---------- .../{salty.ts => salty.test.ts} | 8 +++---- .../{witness.ts => witness.test.ts} | 23 +++++++++---------- package.json | 2 +- 6 files changed, 24 insertions(+), 38 deletions(-) rename examples/integration-scripts/{externalModule.ts => externalModule.test.ts} (96%) rename examples/integration-scripts/{randy.ts => randy.test.ts} (87%) rename examples/integration-scripts/{salty.ts => salty.test.ts} (98%) rename examples/integration-scripts/{witness.ts => witness.test.ts} (83%) diff --git a/examples/integration-scripts/externalModule.ts b/examples/integration-scripts/externalModule.test.ts similarity index 96% rename from examples/integration-scripts/externalModule.ts rename to examples/integration-scripts/externalModule.test.ts index 4651137a..85995b48 100644 --- a/examples/integration-scripts/externalModule.ts +++ b/examples/integration-scripts/externalModule.test.ts @@ -5,9 +5,7 @@ import { BIP39Shim } from './modules/bip39_shim'; const url = 'http://127.0.0.1:3901'; const boot_url = 'http://127.0.0.1:3903'; -await run(); - -async function run() { +test('bip39_ship', async () => { await signify.ready(); const bran1 = signify.randomPasscode(); const externalModule: signify.ExternalModule = { @@ -39,4 +37,4 @@ async function run() { }); let op = await icpResult.op(); assert.equal(op['done'], true); -} +}, 30000); diff --git a/examples/integration-scripts/modules/bip39_shim.ts b/examples/integration-scripts/modules/bip39_shim.ts index b9ef7d59..c8a624ff 100644 --- a/examples/integration-scripts/modules/bip39_shim.ts +++ b/examples/integration-scripts/modules/bip39_shim.ts @@ -1,4 +1,4 @@ -import bip39 from 'bip39'; +import { mnemonicToSeedSync, generateMnemonic } from 'bip39'; import { Diger, Signer, MtrDex } from 'signify-ts'; export class BIP39Shim { @@ -36,7 +36,7 @@ export class BIP39Shim { let keys = []; for (let idx = 0; idx < count; idx++) { let keyId = `${this.stem}-${this.pidx}-${kidx + idx}`; - let seed = bip39.mnemonicToSeedSync(this.mnemonics, keyId); + let seed = mnemonicToSeedSync(this.mnemonics, keyId); let signer = new Signer({ raw: new Uint8Array(seed), code: MtrDex.Ed25519_Seed, @@ -141,6 +141,6 @@ export class BIP39Shim { } generateMnemonic(strength: number) { - return bip39.generateMnemonic(strength); + return generateMnemonic(strength); } } diff --git a/examples/integration-scripts/randy.ts b/examples/integration-scripts/randy.test.ts similarity index 87% rename from examples/integration-scripts/randy.ts rename to examples/integration-scripts/randy.test.ts index 5c925e85..8dce2590 100644 --- a/examples/integration-scripts/randy.ts +++ b/examples/integration-scripts/randy.test.ts @@ -4,9 +4,7 @@ import signify from 'signify-ts'; const url = 'http://127.0.0.1:3901'; const boot_url = 'http://127.0.0.1:3903'; -await run(); - -async function run() { +test('randy', async () => { await signify.ready(); // Boot client const bran1 = signify.randomPasscode(); @@ -18,13 +16,7 @@ async function run() { ); await client1.boot(); await client1.connect(); - const state1 = await client1.state(); - console.log( - 'Client 1 connected. Client AID:', - state1.controller.state.i, - 'Agent AID: ', - state1.agent.i - ); + await client1.state(); let icpResult = await client1 .identifiers() @@ -50,7 +42,7 @@ async function run() { let ked = op['response']; let ixn = new signify.Serder(ked); assert.equal(ixn.ked['s'], '1'); - assert.deepEqual(ixn.ked['a'], [icp.pre]); + assert.deepEqual([...ixn.ked['a']], [icp.pre]); aids = await client1.identifiers().list(); assert.equal(aids.aids.length, 1); @@ -77,5 +69,4 @@ async function run() { assert.equal(dig.qb64, icp.digers[0].qb64); log = await events.get(aid['prefix']); assert.equal(log.length, 3); - console.log('Randy test passed'); -} +}, 30000); diff --git a/examples/integration-scripts/salty.ts b/examples/integration-scripts/salty.test.ts similarity index 98% rename from examples/integration-scripts/salty.ts rename to examples/integration-scripts/salty.test.ts index 281881e3..6013a26c 100644 --- a/examples/integration-scripts/salty.ts +++ b/examples/integration-scripts/salty.test.ts @@ -4,9 +4,7 @@ import signify from 'signify-ts'; const url = 'http://127.0.0.1:3901'; const boot_url = 'http://127.0.0.1:3903'; -await run(); - -async function run() { +test('salty', async () => { await signify.ready(); // Boot client const bran1 = signify.randomPasscode(); @@ -145,7 +143,7 @@ async function run() { let ixn = new signify.Serder(ked); assert.equal(ixn.ked['d'], 'ENsmRAg_oM7Hl1S-GTRMA7s4y760lQMjzl0aqOQ2iTce'); assert.equal(ixn.ked['s'], '2'); - assert.deepEqual(ixn.ked['a'], [icp.pre]); + assert.deepEqual([...ixn.ked['a']], [icp.pre]); aid = await client1.identifiers().get('aid1'); const state = aid['state']; @@ -169,4 +167,4 @@ async function run() { assert.equal(serder.pre, ixn.pre); assert.equal(serder.ked['d'], ixn.ked['d']); console.log('Salty test passed'); -} +}, 30000); diff --git a/examples/integration-scripts/witness.ts b/examples/integration-scripts/witness.test.ts similarity index 83% rename from examples/integration-scripts/witness.ts rename to examples/integration-scripts/witness.test.ts index 37a24a79..04c1d930 100644 --- a/examples/integration-scripts/witness.ts +++ b/examples/integration-scripts/witness.test.ts @@ -2,11 +2,12 @@ import { strict as assert } from 'assert'; import signify from 'signify-ts'; +const WITNESS_HOST = process.env.WITNESS_HOST ?? 'witness-demo'; +const WITNESS_AID = 'BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha'; const url = 'http://127.0.0.1:3901'; const boot_url = 'http://127.0.0.1:3903'; -await run(); -async function run() { +test('test witness', async () => { await signify.ready(); // Boot client const bran1 = signify.randomPasscode(); @@ -26,12 +27,10 @@ async function run() { state1.agent.i ); - const witness = 'BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha'; - // Client 1 resolves witness OOBI let op1 = await client1 .oobis() - .resolve('http://127.0.0.1:5642/oobi/' + witness, 'wit'); + .resolve(`http://${WITNESS_HOST}:5642/oobi/` + WITNESS_AID, 'wit'); while (!op1['done']) { op1 = await client1.operations().get(op1.name); await new Promise((resolve) => setTimeout(resolve, 1000)); @@ -41,7 +40,7 @@ async function run() { // Client 1 creates AID with 1 witness let icpResult1 = await client1.identifiers().create('aid1', { toad: 1, - wits: ['BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha'], + wits: [WITNESS_AID], }); op1 = await icpResult1.op(); while (!op1['done']) { @@ -51,7 +50,7 @@ async function run() { let aid1 = await client1.identifiers().get('aid1'); console.log('AID:', aid1.prefix); assert.equal(aid1.state.b.length, 1); - assert.equal(aid1.state.b[0], witness); + assert.equal(aid1.state.b[0], WITNESS_AID); icpResult1 = await client1.identifiers().rotate('aid1'); op1 = await icpResult1.op(); @@ -61,12 +60,12 @@ async function run() { } aid1 = await client1.identifiers().get('aid1'); assert.equal(aid1.state.b.length, 1); - assert.equal(aid1.state.b[0], witness); + assert.equal(aid1.state.b[0], WITNESS_AID); // Remove witness icpResult1 = await client1 .identifiers() - .rotate('aid1', { cuts: [witness] }); + .rotate('aid1', { cuts: [WITNESS_AID] }); op1 = await icpResult1.op(); while (!op1['done']) { @@ -80,7 +79,7 @@ async function run() { icpResult1 = await client1 .identifiers() - .rotate('aid1', { adds: [witness] }); + .rotate('aid1', { adds: [WITNESS_AID] }); op1 = await icpResult1.op(); while (!op1['done']) { @@ -90,5 +89,5 @@ async function run() { aid1 = await client1.identifiers().get('aid1'); assert.equal(aid1.state.b.length, 1); assert.equal(aid1.state.b.length, 1); - assert.equal(aid1.state.b[0], witness); -} + assert.equal(aid1.state.b[0], WITNESS_AID); +}, 30000); diff --git a/package.json b/package.json index e97d8838..a75d79af 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "build:types": "tsc -p tsconfig.build.json", "build": "npm run build:cjs && npm run build:esm && npm run build:types", "test": "jest test/", - "test:integration": "jest examples/integration-scripts/", + "test:integration": "jest examples/integration-scripts/ --runInBand", "lint": "npx eslint src test examples/integration-scripts examples/scripts", "prepare": "npm run build", "generate-docs": "node_modules/.bin/jsdoc --configure .jsdoc.json --verbose", From da2e82d2cc2b36c28364382aca434c80d0f01cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Lenksj=C3=B6?= <5889538+lenkan@users.noreply.github.com> Date: Tue, 28 Nov 2023 09:58:35 +0100 Subject: [PATCH 2/2] Update examples/integration-scripts/externalModule.test.ts Fix spelling error --- examples/integration-scripts/externalModule.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/integration-scripts/externalModule.test.ts b/examples/integration-scripts/externalModule.test.ts index 85995b48..f8048cea 100644 --- a/examples/integration-scripts/externalModule.test.ts +++ b/examples/integration-scripts/externalModule.test.ts @@ -5,7 +5,7 @@ import { BIP39Shim } from './modules/bip39_shim'; const url = 'http://127.0.0.1:3901'; const boot_url = 'http://127.0.0.1:3903'; -test('bip39_ship', async () => { +test('bip39_shim', async () => { await signify.ready(); const bran1 = signify.randomPasscode(); const externalModule: signify.ExternalModule = {