Skip to content

Commit

Permalink
Fixing delegation tests to work correctly now.
Browse files Browse the repository at this point in the history
  • Loading branch information
pfeairheller committed Jan 18, 2024
1 parent 180645b commit 6982001
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 29 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');
let op4 = await client2.keyStates().query(aid0.prefix, '1');

// 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');
await waitOperation(client2, op3);

// Client 2 check approval
await waitOperation(client2, op2);
const aid2 = await client2.identifiers().get('delegate');
Expand Down
64 changes: 36 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,62 @@ 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);

});
});

0 comments on commit 6982001

Please sign in to comment.