From 4c081a1b539f57c310e53ac8b5b12f49645312c8 Mon Sep 17 00:00:00 2001 From: Petteri Stenius Date: Sat, 2 Dec 2023 01:23:16 +0200 Subject: [PATCH 1/6] delegate test --- .../integration-scripts/singlesig-dip.test.ts | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 examples/integration-scripts/singlesig-dip.test.ts diff --git a/examples/integration-scripts/singlesig-dip.test.ts b/examples/integration-scripts/singlesig-dip.test.ts new file mode 100644 index 00000000..e376f4b8 --- /dev/null +++ b/examples/integration-scripts/singlesig-dip.test.ts @@ -0,0 +1,74 @@ +import { CreateIdentiferArgs, EventResult, SignifyClient } from "signify-ts"; +import { getOrCreateClients, getOrCreateContact, getOrCreateIdentifier } from "./utils/test-setup"; +import { waitOperation } from "./utils/test-util"; +import { resolveEnvironment } from "./utils/resolve-env"; + +let client1: SignifyClient, client2: SignifyClient; +let name1_id: string, name1_oobi: string; +let contact1_id: string; + +beforeAll(async () => { + [client1, client2] = await getOrCreateClients(2); +}); +beforeAll(async () => { + [name1_id, name1_oobi] = await getOrCreateIdentifier(client1, "name1"); +}); +beforeAll(async () => { + contact1_id = await getOrCreateContact(client2, "contact1", name1_oobi); +}); + +describe("singlesig-dip", () => { + test("delegate1a", async () => { + let kargs: CreateIdentiferArgs = { + delpre: name1_id + }; + let result = await client2.identifiers().create("delegate1", kargs); + let op = await result.op(); + let dip1 = await client2.identifiers().get("delegate1"); + expect(op.name).toEqual(`delegation.${dip1.prefix}`); + }); + test("delegator1", async () => { + let dip1 = await client2.identifiers().get("delegate1"); + let seal = { + i: dip1.prefix, + s: 0, + d: dip1.prefix + }; + let result = await client1.identifiers().interact("name1", seal); + let op = waitOperation(client1, await result.op()); + }) + test("delegate1b", async () => { + let dip1 = await client2.identifiers().get("delegate1"); + let op: any = { name: `delegation.${dip1.prefix}` }; + op = await waitOperation(client2, op); + expect(dip1.prefix).toEqual(op.response.i); + }); + test("delegate2a", async () => { + let env = resolveEnvironment(); + let kargs: CreateIdentiferArgs = { + delpre: name1_id, + toad: env.witnessIds.length, + wits: env.witnessIds + }; + let result = await client2.identifiers().create("delegate2", kargs); + let op = await result.op(); + let dip1 = await client2.identifiers().get("delegate2"); + expect(op.name).toEqual(`delegation.${dip1.prefix}`); + }); + test("delegator2", async () => { + let dip1 = await client2.identifiers().get("delegate2"); + let seal = { + i: dip1.prefix, + s: 0, + d: dip1.prefix + }; + let result = await client1.identifiers().interact("name1", seal); + let op = waitOperation(client1, await result.op()); + }) + test("delegate2b", async () => { + let dip1 = await client2.identifiers().get("delegate2"); + let op: any = { name: `delegation.${dip1.prefix}` }; + op = await waitOperation(client2, op); + expect(dip1.prefix).toEqual(op.response.i); + }); +}); From e144f2e6aadd7494496f294f77f76c7d619d5161 Mon Sep 17 00:00:00 2001 From: Petteri Stenius Date: Sat, 2 Dec 2023 10:16:57 +0200 Subject: [PATCH 2/6] cleanup --- examples/integration-scripts/singlesig-dip.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/integration-scripts/singlesig-dip.test.ts b/examples/integration-scripts/singlesig-dip.test.ts index e376f4b8..a1439ab1 100644 --- a/examples/integration-scripts/singlesig-dip.test.ts +++ b/examples/integration-scripts/singlesig-dip.test.ts @@ -1,4 +1,4 @@ -import { CreateIdentiferArgs, EventResult, SignifyClient } from "signify-ts"; +import { CreateIdentiferArgs, SignifyClient } from "signify-ts"; import { getOrCreateClients, getOrCreateContact, getOrCreateIdentifier } from "./utils/test-setup"; import { waitOperation } from "./utils/test-util"; import { resolveEnvironment } from "./utils/resolve-env"; From 5ab8b3ddd581fc585c1b2c90a84bfcb756802436 Mon Sep 17 00:00:00 2001 From: Petteri Stenius Date: Sat, 2 Dec 2023 10:26:33 +0200 Subject: [PATCH 3/6] cleanup --- .../integration-scripts/singlesig-dip.test.ts | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/examples/integration-scripts/singlesig-dip.test.ts b/examples/integration-scripts/singlesig-dip.test.ts index a1439ab1..38a9a418 100644 --- a/examples/integration-scripts/singlesig-dip.test.ts +++ b/examples/integration-scripts/singlesig-dip.test.ts @@ -19,31 +19,35 @@ beforeAll(async () => { describe("singlesig-dip", () => { test("delegate1a", async () => { + // delegate creates identifier without witnesses let kargs: CreateIdentiferArgs = { delpre: name1_id }; let result = await client2.identifiers().create("delegate1", kargs); let op = await result.op(); - let dip1 = await client2.identifiers().get("delegate1"); - expect(op.name).toEqual(`delegation.${dip1.prefix}`); + let delegate1 = await client2.identifiers().get("delegate1"); + expect(op.name).toEqual(`delegation.${delegate1.prefix}`); }); test("delegator1", async () => { - let dip1 = await client2.identifiers().get("delegate1"); + // delegator approves delegate + let delegate1 = await client2.identifiers().get("delegate1"); let seal = { - i: dip1.prefix, + i: delegate1.prefix, s: 0, - d: dip1.prefix + d: delegate1.prefix }; let result = await client1.identifiers().interact("name1", seal); let op = waitOperation(client1, await result.op()); }) test("delegate1b", async () => { - let dip1 = await client2.identifiers().get("delegate1"); - let op: any = { name: `delegation.${dip1.prefix}` }; + // delegate waits for completion + let delegate1 = await client2.identifiers().get("delegate1"); + let op: any = { name: `delegation.${delegate1.prefix}` }; op = await waitOperation(client2, op); - expect(dip1.prefix).toEqual(op.response.i); + expect(delegate1.prefix).toEqual(op.response.i); }); test("delegate2a", async () => { + // delegate creates identifier with default witness config let env = resolveEnvironment(); let kargs: CreateIdentiferArgs = { delpre: name1_id, @@ -52,23 +56,26 @@ describe("singlesig-dip", () => { }; let result = await client2.identifiers().create("delegate2", kargs); let op = await result.op(); - let dip1 = await client2.identifiers().get("delegate2"); - expect(op.name).toEqual(`delegation.${dip1.prefix}`); + let delegate2 = await client2.identifiers().get("delegate2"); + expect(op.name).toEqual(`delegation.${delegate2.prefix}`); }); test("delegator2", async () => { - let dip1 = await client2.identifiers().get("delegate2"); + // delegator approves delegate + let delegate2 = await client2.identifiers().get("delegate2"); let seal = { - i: dip1.prefix, + i: delegate2.prefix, s: 0, - d: dip1.prefix + d: delegate2.prefix }; let result = await client1.identifiers().interact("name1", seal); let op = waitOperation(client1, await result.op()); }) - test("delegate2b", async () => { - let dip1 = await client2.identifiers().get("delegate2"); - let op: any = { name: `delegation.${dip1.prefix}` }; + // https://github.com/WebOfTrust/signify-ts/issues/145 + test.failing("delegate2b", async () => { + // delegate waits for completion + let delegate2 = await client2.identifiers().get("delegate2"); + let op: any = { name: `delegation.${delegate2.prefix}` }; op = await waitOperation(client2, op); - expect(dip1.prefix).toEqual(op.response.i); - }); + expect(delegate2.prefix).toEqual(op.response.i); + }, 30000); }); From 2272f43b0b813f6ef08369aa86f17464c2c98827 Mon Sep 17 00:00:00 2001 From: Petteri Stenius Date: Sat, 2 Dec 2023 10:34:11 +0200 Subject: [PATCH 4/6] fix code style issues --- .../integration-scripts/singlesig-dip.test.ts | 76 ++++++++++--------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/examples/integration-scripts/singlesig-dip.test.ts b/examples/integration-scripts/singlesig-dip.test.ts index 38a9a418..037dca0e 100644 --- a/examples/integration-scripts/singlesig-dip.test.ts +++ b/examples/integration-scripts/singlesig-dip.test.ts @@ -1,7 +1,11 @@ -import { CreateIdentiferArgs, SignifyClient } from "signify-ts"; -import { getOrCreateClients, getOrCreateContact, getOrCreateIdentifier } from "./utils/test-setup"; -import { waitOperation } from "./utils/test-util"; -import { resolveEnvironment } from "./utils/resolve-env"; +import { CreateIdentiferArgs, SignifyClient } from 'signify-ts'; +import { + getOrCreateClients, + getOrCreateContact, + getOrCreateIdentifier, +} from './utils/test-setup'; +import { waitOperation } from './utils/test-util'; +import { resolveEnvironment } from './utils/resolve-env'; let client1: SignifyClient, client2: SignifyClient; let name1_id: string, name1_oobi: string; @@ -11,71 +15,75 @@ beforeAll(async () => { [client1, client2] = await getOrCreateClients(2); }); beforeAll(async () => { - [name1_id, name1_oobi] = await getOrCreateIdentifier(client1, "name1"); + [name1_id, name1_oobi] = await getOrCreateIdentifier(client1, 'name1'); }); beforeAll(async () => { - contact1_id = await getOrCreateContact(client2, "contact1", name1_oobi); + contact1_id = await getOrCreateContact(client2, 'contact1', name1_oobi); }); -describe("singlesig-dip", () => { - test("delegate1a", async () => { +describe('singlesig-dip', () => { + test('delegate1a', async () => { // delegate creates identifier without witnesses let kargs: CreateIdentiferArgs = { - delpre: name1_id + delpre: name1_id, }; - let result = await client2.identifiers().create("delegate1", kargs); + let result = await client2.identifiers().create('delegate1', kargs); let op = await result.op(); - let delegate1 = await client2.identifiers().get("delegate1"); + let delegate1 = await client2.identifiers().get('delegate1'); expect(op.name).toEqual(`delegation.${delegate1.prefix}`); }); - test("delegator1", async () => { + test('delegator1', async () => { // delegator approves delegate - let delegate1 = await client2.identifiers().get("delegate1"); + let delegate1 = await client2.identifiers().get('delegate1'); let seal = { i: delegate1.prefix, s: 0, - d: delegate1.prefix + d: delegate1.prefix, }; - let result = await client1.identifiers().interact("name1", seal); + let result = await client1.identifiers().interact('name1', seal); let op = waitOperation(client1, await result.op()); - }) - test("delegate1b", async () => { + }); + test('delegate1b', async () => { // delegate waits for completion - let delegate1 = await client2.identifiers().get("delegate1"); + let delegate1 = await client2.identifiers().get('delegate1'); let op: any = { name: `delegation.${delegate1.prefix}` }; op = await waitOperation(client2, op); expect(delegate1.prefix).toEqual(op.response.i); }); - test("delegate2a", async () => { + test('delegate2a', async () => { // delegate creates identifier with default witness config let env = resolveEnvironment(); let kargs: CreateIdentiferArgs = { delpre: name1_id, toad: env.witnessIds.length, - wits: env.witnessIds + wits: env.witnessIds, }; - let result = await client2.identifiers().create("delegate2", kargs); + let result = await client2.identifiers().create('delegate2', kargs); let op = await result.op(); - let delegate2 = await client2.identifiers().get("delegate2"); + let delegate2 = await client2.identifiers().get('delegate2'); expect(op.name).toEqual(`delegation.${delegate2.prefix}`); }); - test("delegator2", async () => { + test('delegator2', async () => { // delegator approves delegate - let delegate2 = await client2.identifiers().get("delegate2"); + let delegate2 = await client2.identifiers().get('delegate2'); let seal = { i: delegate2.prefix, s: 0, - d: delegate2.prefix + d: delegate2.prefix, }; - let result = await client1.identifiers().interact("name1", seal); + let result = await client1.identifiers().interact('name1', seal); let op = waitOperation(client1, await result.op()); - }) + }); // https://github.com/WebOfTrust/signify-ts/issues/145 - test.failing("delegate2b", async () => { - // delegate waits for completion - let delegate2 = await client2.identifiers().get("delegate2"); - let op: any = { name: `delegation.${delegate2.prefix}` }; - op = await waitOperation(client2, op); - expect(delegate2.prefix).toEqual(op.response.i); - }, 30000); + test.failing( + 'delegate2b', + async () => { + // delegate waits for completion + let delegate2 = await client2.identifiers().get('delegate2'); + let op: any = { name: `delegation.${delegate2.prefix}` }; + op = await waitOperation(client2, op); + expect(delegate2.prefix).toEqual(op.response.i); + }, + 30000 + ); }); From 926b76b67e440af9b91efd89fc32f56a5c02f5fc Mon Sep 17 00:00:00 2001 From: Petteri Stenius Date: Sat, 16 Dec 2023 10:58:18 +0200 Subject: [PATCH 5/6] issue #145 - integration test to reproduce --- .../integration-scripts/singlesig-dip.test.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/examples/integration-scripts/singlesig-dip.test.ts b/examples/integration-scripts/singlesig-dip.test.ts index 037dca0e..1b3fc9c8 100644 --- a/examples/integration-scripts/singlesig-dip.test.ts +++ b/examples/integration-scripts/singlesig-dip.test.ts @@ -75,15 +75,11 @@ describe('singlesig-dip', () => { let op = waitOperation(client1, await result.op()); }); // https://github.com/WebOfTrust/signify-ts/issues/145 - test.failing( - 'delegate2b', - async () => { - // delegate waits for completion - let delegate2 = await client2.identifiers().get('delegate2'); - let op: any = { name: `delegation.${delegate2.prefix}` }; - op = await waitOperation(client2, op); - expect(delegate2.prefix).toEqual(op.response.i); - }, - 30000 - ); + test('delegate2b', async () => { + // delegate waits for completion + let delegate2 = await client2.identifiers().get('delegate2'); + let op: any = { name: `delegation.${delegate2.prefix}` }; + op = await waitOperation(client2, op); + expect(delegate2.prefix).toEqual(op.response.i); + }); }); From aa2d651363d246045ccb5e79d339c07fc41e9319 Mon Sep 17 00:00:00 2001 From: Petteri Stenius Date: Tue, 16 Jan 2024 23:32:30 +0200 Subject: [PATCH 6/6] change number to hex string --- examples/integration-scripts/singlesig-dip.test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/integration-scripts/singlesig-dip.test.ts b/examples/integration-scripts/singlesig-dip.test.ts index 1b3fc9c8..7a413e2c 100644 --- a/examples/integration-scripts/singlesig-dip.test.ts +++ b/examples/integration-scripts/singlesig-dip.test.ts @@ -37,7 +37,7 @@ describe('singlesig-dip', () => { let delegate1 = await client2.identifiers().get('delegate1'); let seal = { i: delegate1.prefix, - s: 0, + s: '0', d: delegate1.prefix, }; let result = await client1.identifiers().interact('name1', seal); @@ -68,13 +68,12 @@ describe('singlesig-dip', () => { let delegate2 = await client2.identifiers().get('delegate2'); let seal = { i: delegate2.prefix, - s: 0, + s: '0', d: delegate2.prefix, }; let result = await client1.identifiers().interact('name1', seal); let op = waitOperation(client1, await result.op()); }); - // https://github.com/WebOfTrust/signify-ts/issues/145 test('delegate2b', async () => { // delegate waits for completion let delegate2 = await client2.identifiers().get('delegate2');