Skip to content

Commit

Permalink
make delegation-multisig.test faster
Browse files Browse the repository at this point in the history
  • Loading branch information
lenkan authored and m00sey committed Dec 15, 2023
1 parent eacf6bb commit 2a95620
Showing 1 changed file with 30 additions and 63 deletions.
93 changes: 30 additions & 63 deletions examples/integration-scripts/delegation-multisig.test.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,42 @@
import { strict as assert } from 'assert';
import signify from 'signify-ts';
import { resolveEnvironment } from './utils/resolve-env';
import { waitForNotifications, waitOperation } from './utils/test-util';

const { url, bootUrl } = resolveEnvironment();
import {
resolveOobi,
waitForNotifications,
waitOperation,
} from './utils/test-util';
import { getOrCreateClient } from './utils/test-setup';

test('delegation-multisig', async () => {
await signify.ready();
// Boot three clients
const client0 = await bootClient();
const client1 = await bootClient();
const client2 = await bootClient();
const [client0, client1, client2] = await Promise.all([
getOrCreateClient(),
getOrCreateClient(),
getOrCreateClient(),
]);

// Create four identifiers, one for each client
const aid0 = await createAID(client0, 'delegator');
const aid1 = await createAID(client1, 'member1');
const aid2 = await createAID(client2, 'member2');
const [aid0, aid1, aid2] = await Promise.all([
createAID(client0, 'delegator'),
createAID(client1, 'member1'),
createAID(client2, 'member2'),
]);

// Exchange OOBIs
console.log('Resolving OOBIs');
const oobi0 = await client0.oobis().get('delegator', 'agent');
const oobi1 = await client1.oobis().get('member1', 'agent');
const oobi2 = await client2.oobis().get('member2', 'agent');

let op1 = await client1.oobis().resolve(oobi0.oobis[0], 'delegator');
op1 = await waitOperation(client1, op1);
op1 = await client1.oobis().resolve(oobi2.oobis[0], 'member2');
op1 = await waitOperation(client1, op1);
console.log('Member1 resolved 2 OOBIs');

let op2 = await client2.oobis().resolve(oobi0.oobis[0], 'delegator');
op2 = await waitOperation(client2, op2);
op2 = await client2.oobis().resolve(oobi1.oobis[0], 'member1');
op2 = await waitOperation(client2, op2);
console.log('Member2 resolved 2 OOBIs');

// First member challenge the other members with a random list of words
// List of words should be passed to the other members out of band
// The other members should do the same challenge/response flow, not shown here for brevity
const words = (await client1.challenges().generate(128)).words;
console.log('Member1 generated challenge words:', words);

await client2.challenges().respond('member2', aid1.prefix, words);
console.log('Member2 responded challenge with signed words');

op1 = await client1.challenges().verify('member1', aid2.prefix, words);
op1 = await waitOperation(client1, op1);
console.log('Member1 verified challenge response from member2');
const exnwords = new signify.Serder(op1.response.exn);
op1 = await client1
.challenges()
.responded('member1', aid2.prefix, exnwords.ked.d);
console.log('Member1 marked challenge response as accepted');
await Promise.all([
resolveOobi(client1, oobi0.oobis[0], 'delegator'),
resolveOobi(client1, oobi2.oobis[0], 'member2'),
resolveOobi(client2, oobi0.oobis[0], 'delegator'),
resolveOobi(client2, oobi1.oobis[0], 'member1'),
]);

console.log('Member1 and Member2 resolved 2 OOBIs');

// First member start the creation of a multisig identifier
const rstates = [aid1['state'], aid2['state']];
Expand All @@ -71,7 +56,7 @@ test('delegation-multisig', async () => {
rstates: rstates,
delpre: aid0.prefix,
});
op1 = await icpResult1.op();
const op1 = await icpResult1.op();
let serder = icpResult1.serder;

let sigs = icpResult1.sigs;
Expand Down Expand Up @@ -122,7 +107,7 @@ test('delegation-multisig', async () => {
rstates: rstates,
delpre: aid0.prefix,
});
op2 = await icpResult2.op();
const op2 = await icpResult2.op();
serder = icpResult2.serder;
sigs = icpResult2.sigs;
sigers = sigs.map((sig) => new signify.Siger({ qb64: sig }));
Expand Down Expand Up @@ -164,34 +149,16 @@ test('delegation-multisig', async () => {
console.log('Delegator approved delegation');

// Check for completion
op1 = await waitOperation(client1, op1);
op2 = await waitOperation(client2, op2);
await Promise.all([
waitOperation(client1, op1),
waitOperation(client2, op2),
]);
console.log('Delegated multisig created!');

const aid_delegate = await client1.identifiers().get('multisig');
assert.equal(aid_delegate.prefix, delegatePrefix);
}, 30000);

async function bootClient(): Promise<signify.SignifyClient> {
const bran = signify.randomPasscode();
const client = new signify.SignifyClient(
url,
bran,
signify.Tier.low,
bootUrl
);
await client.boot();
await client.connect();
const state = await client.state();
console.log(
'Client AID:',
state.controller.state.i,
'Agent AID: ',
state.agent.i
);
return client;
}

async function createAID(client: signify.SignifyClient, name: string) {
const icpResult1 = await client.identifiers().create(name, {
toad: 3,
Expand Down

0 comments on commit 2a95620

Please sign in to comment.