Skip to content

Commit

Permalink
add witness and randy integration tests
Browse files Browse the repository at this point in the history
add runInBand to avoid concurrency issues

add salty, external module tests
  • Loading branch information
lenkan committed Nov 27, 2023
1 parent e5d39b9 commit f1585fc
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -39,4 +37,4 @@ async function run() {
});
let op = await icpResult.op();
assert.equal(op['done'], true);
}
}, 30000);
6 changes: 3 additions & 3 deletions examples/integration-scripts/modules/bip39_shim.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bip39 from 'bip39';
import { mnemonicToSeedSync, generateMnemonic } from 'bip39';
import { Diger, Signer, MtrDex } from 'signify-ts';

export class BIP39Shim {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -141,6 +141,6 @@ export class BIP39Shim {
}

generateMnemonic(strength: number) {
return bip39.generateMnemonic(strength);
return generateMnemonic(strength);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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()
Expand All @@ -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);
Expand All @@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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'];
Expand All @@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
Expand All @@ -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']) {
Expand All @@ -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();
Expand All @@ -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']) {
Expand All @@ -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']) {
Expand All @@ -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);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit f1585fc

Please sign in to comment.