Skip to content

Commit

Permalink
Merge pull request #197 from pfeairheller/feat-delegate-rot
Browse files Browse the repository at this point in the history
Fixing delegation integration tests
  • Loading branch information
pfeairheller authored Jan 18, 2024
2 parents c64e006 + 6aa421a commit 5be1819
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 30 deletions.
7 changes: 6 additions & 1 deletion examples/integration-scripts/delegation-multisig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ test('delegation-multisig', async () => {
mhab: aid1,
isith: 2,
nsith: 2,
toad: 3,
toad: 2,
wits: [
'BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha',
'BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM',
Expand Down Expand Up @@ -148,10 +148,15 @@ test('delegation-multisig', async () => {
await client0.identifiers().interact('delegator', anchor);
console.log('Delegator approved delegation');

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

Check warning on line 151 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 151 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 warning on line 152 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

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

Check warning on line 152 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

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

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

Expand Down
3 changes: 3 additions & 0 deletions examples/integration-scripts/delegation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ test('delegation', async () => {
await client1.identifiers().interact('delegator', anchor);
console.log('Delegator approved delegation');

let op3 = await client2.keyStates().query(aid1.prefix, '1');

Check warning on line 84 in examples/integration-scripts/delegation.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 84 in examples/integration-scripts/delegation.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
await waitOperation(client2, op3);

// Client 2 check approval
await waitOperation(client2, op2);
const aid2 = await client2.identifiers().get('delegate');
Expand Down
61 changes: 33 additions & 28 deletions examples/integration-scripts/singlesig-dip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,54 +31,59 @@ describe('singlesig-dip', () => {
let op = await result.op();
let delegate1 = await client2.identifiers().get('delegate1');
expect(op.name).toEqual(`delegation.${delegate1.prefix}`);
});
test('delegator1', async () => {
// delegator approves delegate
let delegate1 = await client2.identifiers().get('delegate1');

delegate1 = await client2.identifiers().get('delegate1');
let seal = {
i: delegate1.prefix,
s: '0',
d: delegate1.prefix,
};
let result = await client1.identifiers().interact('name1', seal);
let op = waitOperation(client1, await result.op());
});
test('delegate1b', async () => {
// delegate waits for completion
let delegate1 = await client2.identifiers().get('delegate1');
let op: any = { name: `delegation.${delegate1.prefix}` };
op = await waitOperation(client2, op);
result = await client1.identifiers().interact('name1', seal);
let op1 = await result.op();

let op2 = await client2.keyStates().query(name1_id, '1');

await Promise.all([
(op = await waitOperation(client2, op)),
waitOperation(client1, op1),
waitOperation(client2, op2),
]);

delegate1 = await client2.identifiers().get('delegate1');
expect(delegate1.prefix).toEqual(op.response.i);
});
test('delegate2a', async () => {

// delegate creates identifier with default witness config
let env = resolveEnvironment();
let kargs: CreateIdentiferArgs = {
kargs = {
delpre: name1_id,
toad: env.witnessIds.length,
wits: env.witnessIds,
};
let result = await client2.identifiers().create('delegate2', kargs);
let op = await result.op();
result = await client2.identifiers().create('delegate2', kargs);
op = await result.op();
let delegate2 = await client2.identifiers().get('delegate2');
expect(op.name).toEqual(`delegation.${delegate2.prefix}`);
});
test('delegator2', async () => {

// delegator approves delegate
let delegate2 = await client2.identifiers().get('delegate2');
let seal = {
delegate2 = await client2.identifiers().get('delegate2');
seal = {
i: delegate2.prefix,
s: '0',
d: delegate2.prefix,
};
let result = await client1.identifiers().interact('name1', seal);
let op = waitOperation(client1, await result.op());
});
test('delegate2b', async () => {
result = await client1.identifiers().interact('name1', seal);
op1 = await result.op();

op2 = await client2.keyStates().query(name1_id, '2');

await Promise.all([
(op = await waitOperation(client2, op)),
waitOperation(client1, op1),
waitOperation(client2, op2),
]);

// delegate waits for completion
let delegate2 = await client2.identifiers().get('delegate2');
let op: any = { name: `delegation.${delegate2.prefix}` };
op = await waitOperation(client2, op);
delegate2 = await client2.identifiers().get('delegate2');
expect(delegate2.prefix).toEqual(op.response.i);
});
});
78 changes: 78 additions & 0 deletions examples/integration-scripts/singlesig-drt.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { CreateIdentiferArgs, SignifyClient } from 'signify-ts';
import {
getOrCreateClients,
getOrCreateContact,
getOrCreateIdentifier,
} from './utils/test-setup';
import { waitOperation } from './utils/test-util';

let delegator: SignifyClient, delegate: SignifyClient;
let name1_id: string, name1_oobi: string;
let contact1_id: string;

beforeAll(async () => {
[delegator, delegate] = await getOrCreateClients(2);
});
beforeAll(async () => {
[name1_id, name1_oobi] = await getOrCreateIdentifier(delegator, 'name1');
});
beforeAll(async () => {
contact1_id = await getOrCreateContact(delegate, 'contact1', name1_oobi);
});

describe('singlesig-drt', () => {
test('delegate1a', async () => {
// delegate creates identifier without witnesses
let kargs: CreateIdentiferArgs = {
delpre: name1_id,
};
let result = await delegate.identifiers().create('delegate1', kargs);
let op = await result.op();
let delegate1 = await delegate.identifiers().get('delegate1');
expect(op.name).toEqual(`delegation.${delegate1.prefix}`);

// delegator approves delegate
let seal = {
i: delegate1.prefix,
s: '0',
d: delegate1.prefix,
};
result = await delegator.identifiers().interact('name1', seal);
let op1 = await result.op();

let op2 = await delegate.keyStates().query(name1_id, '1');

await Promise.all([
waitOperation(delegate, op),
waitOperation(delegator, op1),
waitOperation(delegate, op2),
]);

kargs = {};
result = await delegate.identifiers().rotate('delegate1', kargs);
op = await result.op();
expect(op.name).toEqual(`delegation.${delegate1.prefix}`);

// delegator approves delegate
delegate1 = await delegate.identifiers().get('delegate1');

seal = {
i: delegate1.prefix,
s: '1',
d: delegate1.state.d,
};

result = await delegator.identifiers().interact('name1', seal);
op1 = await result.op();
op2 = await delegate.keyStates().query(name1_id, '2');

await Promise.all([
(op = await waitOperation(delegate, op)),
waitOperation(delegator, op1),
waitOperation(delegate, op2),
]);

expect(op.response.t).toEqual(`drt`);
expect(op.response.s).toEqual(`1`);
});
});
1 change: 1 addition & 0 deletions examples/integration-scripts/utils/test-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export async function waitOperation<T = any>(
throw new Error(`Operation ${op.name} not done`);
}

console.log('DONE', op.name);
return op;
}, options);
}
Expand Down
6 changes: 5 additions & 1 deletion src/keri/app/aiding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SignifyClient } from './clienting';
import { Tier } from '../core/salter';
import { Algos } from '../core/manager';
import { incept, interact, reply, rotate } from '../core/eventing';
import { b, Serials, Versionage } from '../core/core';
import { b, Ilks, Serials, Versionage } from '../core/core';
import { Tholder } from '../core/tholder';
import { MtrDex } from '../core/matter';
import { Serder } from '../core/serder';
Expand Down Expand Up @@ -287,6 +287,7 @@ export class Identifier {

const hab = await this.get(name);
const pre = hab.prefix;
const delegated = hab.state.di !== '';

const state = hab.state;
const count = state.k.length;
Expand Down Expand Up @@ -326,8 +327,11 @@ export class Identifier {
const adds = kargs.adds ?? [];
const data = kargs.data != undefined ? [kargs.data] : [];
const toad = kargs.toad;
const ilk = delegated ? Ilks.drt : Ilks.rot;

const serder = rotate({
pre: pre,
ilk: ilk,
keys: keys,
dig: dig,
sn: ridx,
Expand Down

0 comments on commit 5be1819

Please sign in to comment.