Skip to content

Commit 2d3443f

Browse files
authored
Merge pull request #146 from lenkan/witness-test
add witness, salty, randy and external module integration tests
2 parents e5d39b9 + da2e82d commit 2d3443f

File tree

6 files changed

+24
-38
lines changed

6 files changed

+24
-38
lines changed

examples/integration-scripts/externalModule.ts renamed to examples/integration-scripts/externalModule.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import { BIP39Shim } from './modules/bip39_shim';
55
const url = 'http://127.0.0.1:3901';
66
const boot_url = 'http://127.0.0.1:3903';
77

8-
await run();
9-
10-
async function run() {
8+
test('bip39_shim', async () => {
119
await signify.ready();
1210
const bran1 = signify.randomPasscode();
1311
const externalModule: signify.ExternalModule = {
@@ -39,4 +37,4 @@ async function run() {
3937
});
4038
let op = await icpResult.op();
4139
assert.equal(op['done'], true);
42-
}
40+
}, 30000);

examples/integration-scripts/modules/bip39_shim.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import bip39 from 'bip39';
1+
import { mnemonicToSeedSync, generateMnemonic } from 'bip39';
22
import { Diger, Signer, MtrDex } from 'signify-ts';
33

44
export class BIP39Shim {
@@ -36,7 +36,7 @@ export class BIP39Shim {
3636
let keys = [];
3737
for (let idx = 0; idx < count; idx++) {
3838
let keyId = `${this.stem}-${this.pidx}-${kidx + idx}`;
39-
let seed = bip39.mnemonicToSeedSync(this.mnemonics, keyId);
39+
let seed = mnemonicToSeedSync(this.mnemonics, keyId);
4040
let signer = new Signer({
4141
raw: new Uint8Array(seed),
4242
code: MtrDex.Ed25519_Seed,
@@ -141,6 +141,6 @@ export class BIP39Shim {
141141
}
142142

143143
generateMnemonic(strength: number) {
144-
return bip39.generateMnemonic(strength);
144+
return generateMnemonic(strength);
145145
}
146146
}

examples/integration-scripts/randy.ts renamed to examples/integration-scripts/randy.test.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import signify from 'signify-ts';
44
const url = 'http://127.0.0.1:3901';
55
const boot_url = 'http://127.0.0.1:3903';
66

7-
await run();
8-
9-
async function run() {
7+
test('randy', async () => {
108
await signify.ready();
119
// Boot client
1210
const bran1 = signify.randomPasscode();
@@ -18,13 +16,7 @@ async function run() {
1816
);
1917
await client1.boot();
2018
await client1.connect();
21-
const state1 = await client1.state();
22-
console.log(
23-
'Client 1 connected. Client AID:',
24-
state1.controller.state.i,
25-
'Agent AID: ',
26-
state1.agent.i
27-
);
19+
await client1.state();
2820

2921
let icpResult = await client1
3022
.identifiers()
@@ -50,7 +42,7 @@ async function run() {
5042
let ked = op['response'];
5143
let ixn = new signify.Serder(ked);
5244
assert.equal(ixn.ked['s'], '1');
53-
assert.deepEqual(ixn.ked['a'], [icp.pre]);
45+
assert.deepEqual([...ixn.ked['a']], [icp.pre]);
5446

5547
aids = await client1.identifiers().list();
5648
assert.equal(aids.aids.length, 1);
@@ -77,5 +69,4 @@ async function run() {
7769
assert.equal(dig.qb64, icp.digers[0].qb64);
7870
log = await events.get(aid['prefix']);
7971
assert.equal(log.length, 3);
80-
console.log('Randy test passed');
81-
}
72+
}, 30000);

examples/integration-scripts/salty.ts renamed to examples/integration-scripts/salty.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import signify from 'signify-ts';
44
const url = 'http://127.0.0.1:3901';
55
const boot_url = 'http://127.0.0.1:3903';
66

7-
await run();
8-
9-
async function run() {
7+
test('salty', async () => {
108
await signify.ready();
119
// Boot client
1210
const bran1 = signify.randomPasscode();
@@ -145,7 +143,7 @@ async function run() {
145143
let ixn = new signify.Serder(ked);
146144
assert.equal(ixn.ked['d'], 'ENsmRAg_oM7Hl1S-GTRMA7s4y760lQMjzl0aqOQ2iTce');
147145
assert.equal(ixn.ked['s'], '2');
148-
assert.deepEqual(ixn.ked['a'], [icp.pre]);
146+
assert.deepEqual([...ixn.ked['a']], [icp.pre]);
149147

150148
aid = await client1.identifiers().get('aid1');
151149
const state = aid['state'];
@@ -169,4 +167,4 @@ async function run() {
169167
assert.equal(serder.pre, ixn.pre);
170168
assert.equal(serder.ked['d'], ixn.ked['d']);
171169
console.log('Salty test passed');
172-
}
170+
}, 30000);

examples/integration-scripts/witness.ts renamed to examples/integration-scripts/witness.test.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
import { strict as assert } from 'assert';
33
import signify from 'signify-ts';
44

5+
const WITNESS_HOST = process.env.WITNESS_HOST ?? 'witness-demo';
6+
const WITNESS_AID = 'BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha';
57
const url = 'http://127.0.0.1:3901';
68
const boot_url = 'http://127.0.0.1:3903';
79

8-
await run();
9-
async function run() {
10+
test('test witness', async () => {
1011
await signify.ready();
1112
// Boot client
1213
const bran1 = signify.randomPasscode();
@@ -26,12 +27,10 @@ async function run() {
2627
state1.agent.i
2728
);
2829

29-
const witness = 'BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha';
30-
3130
// Client 1 resolves witness OOBI
3231
let op1 = await client1
3332
.oobis()
34-
.resolve('http://127.0.0.1:5642/oobi/' + witness, 'wit');
33+
.resolve(`http://${WITNESS_HOST}:5642/oobi/` + WITNESS_AID, 'wit');
3534
while (!op1['done']) {
3635
op1 = await client1.operations().get(op1.name);
3736
await new Promise((resolve) => setTimeout(resolve, 1000));
@@ -41,7 +40,7 @@ async function run() {
4140
// Client 1 creates AID with 1 witness
4241
let icpResult1 = await client1.identifiers().create('aid1', {
4342
toad: 1,
44-
wits: ['BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha'],
43+
wits: [WITNESS_AID],
4544
});
4645
op1 = await icpResult1.op();
4746
while (!op1['done']) {
@@ -51,7 +50,7 @@ async function run() {
5150
let aid1 = await client1.identifiers().get('aid1');
5251
console.log('AID:', aid1.prefix);
5352
assert.equal(aid1.state.b.length, 1);
54-
assert.equal(aid1.state.b[0], witness);
53+
assert.equal(aid1.state.b[0], WITNESS_AID);
5554

5655
icpResult1 = await client1.identifiers().rotate('aid1');
5756
op1 = await icpResult1.op();
@@ -61,12 +60,12 @@ async function run() {
6160
}
6261
aid1 = await client1.identifiers().get('aid1');
6362
assert.equal(aid1.state.b.length, 1);
64-
assert.equal(aid1.state.b[0], witness);
63+
assert.equal(aid1.state.b[0], WITNESS_AID);
6564

6665
// Remove witness
6766
icpResult1 = await client1
6867
.identifiers()
69-
.rotate('aid1', { cuts: [witness] });
68+
.rotate('aid1', { cuts: [WITNESS_AID] });
7069

7170
op1 = await icpResult1.op();
7271
while (!op1['done']) {
@@ -80,7 +79,7 @@ async function run() {
8079

8180
icpResult1 = await client1
8281
.identifiers()
83-
.rotate('aid1', { adds: [witness] });
82+
.rotate('aid1', { adds: [WITNESS_AID] });
8483

8584
op1 = await icpResult1.op();
8685
while (!op1['done']) {
@@ -90,5 +89,5 @@ async function run() {
9089
aid1 = await client1.identifiers().get('aid1');
9190
assert.equal(aid1.state.b.length, 1);
9291
assert.equal(aid1.state.b.length, 1);
93-
assert.equal(aid1.state.b[0], witness);
94-
}
92+
assert.equal(aid1.state.b[0], WITNESS_AID);
93+
}, 30000);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"build:types": "tsc -p tsconfig.build.json",
2222
"build": "npm run build:cjs && npm run build:esm && npm run build:types",
2323
"test": "jest test/",
24-
"test:integration": "jest examples/integration-scripts/",
24+
"test:integration": "jest examples/integration-scripts/ --runInBand",
2525
"lint": "npx eslint src test examples/integration-scripts examples/scripts",
2626
"prepare": "npm run build",
2727
"generate-docs": "node_modules/.bin/jsdoc --configure .jsdoc.json --verbose",

0 commit comments

Comments
 (0)