diff --git a/tests/src/trusted/trusted/common.ts b/tests/src/trusted/trusted/common.ts index 37fa9db..ad45d0c 100644 --- a/tests/src/trusted/trusted/common.ts +++ b/tests/src/trusted/trusted/common.ts @@ -1,6 +1,6 @@ -import { CallableCell } from '@holochain/tryorama'; -import { Record } from '@holochain/client'; -import { decode } from '@msgpack/msgpack'; +import { CallableCell } from "@holochain/tryorama"; +import { Record } from "@holochain/client"; +import { decode } from "@msgpack/msgpack"; export interface GpgKeyDist { public_key: string; @@ -20,13 +20,13 @@ export interface KeyCollectionWithKeys { gpg_keys: GpgKeyResponse[]; } -export const decodeRecord = (record: Record): T => { +export const decodeRecord = (record: Record): T => { // eslint-disable-next-line @typescript-eslint/no-explicit-any - return decode((record.entry as any).Present.entry) as T -} + return decode((record.entry as any).Present.entry) as T; +}; export function sampleGpgKey() { - return ` + return ` -----BEGIN PGP PUBLIC KEY BLOCK----- mDMEZdDsIBYJKwYBBAHaRw8BAQdAed156Mxx8965zeCQwuGxP1IbkyebXlSyY8Ux @@ -43,20 +43,26 @@ NTxJAQC4xdYMveSHdOiKO4ZhoojG6r7IqX8B8vAZsod6cF/8CA== `; } -export async function distributeGpgKey(cell: CallableCell, gpgKey: string): Promise { - return cell.callZome({ - zome_name: "trusted", - fn_name: "distribute_gpg_key", - payload: { - public_key: gpgKey - }, - }); +export async function distributeGpgKey( + cell: CallableCell, + gpgKey: string, +): Promise { + return cell.callZome({ + zome_name: "trusted", + fn_name: "distribute_gpg_key", + payload: { + public_key: gpgKey, + }, + }); } -export async function createKeyCollection(cell: CallableCell, name: string): Promise { - return cell.callZome({ - zome_name: "trusted", - fn_name: "create_key_collection", - payload: { name }, - }); +export async function createKeyCollection( + cell: CallableCell, + name: string, +): Promise { + return cell.callZome({ + zome_name: "trusted", + fn_name: "create_key_collection", + payload: { name }, + }); } diff --git a/tests/src/trusted/trusted/gpg-key-dist.test.ts b/tests/src/trusted/trusted/gpg-key-dist.test.ts index 85af63c..9fc4a42 100644 --- a/tests/src/trusted/trusted/gpg-key-dist.test.ts +++ b/tests/src/trusted/trusted/gpg-key-dist.test.ts @@ -1,32 +1,38 @@ import { assert, test } from "vitest"; -import { runScenario, dhtSync } from '@holochain/tryorama'; -import { Record } from '@holochain/client'; +import { runScenario, dhtSync } from "@holochain/tryorama"; +import { Record } from "@holochain/client"; -import { GpgKeyResponse, distributeGpgKey, sampleGpgKey } from './common.js'; +import { GpgKeyResponse, distributeGpgKey, sampleGpgKey } from "./common.js"; -test('Distribute GPG Key', async () => { - await runScenario(async scenario => { - const testAppPath = process.cwd() + '/../workdir/hWOT.happ'; +test("Distribute GPG Key", async () => { + await runScenario(async (scenario) => { + const testAppPath = process.cwd() + "/../workdir/hWOT.happ"; const appSource = { appBundleSource: { path: testAppPath } }; const [alice] = await scenario.addPlayersWithApps([appSource]); // Alice distributes a GpgKey - const record: Record = await distributeGpgKey(alice.cells[0], sampleGpgKey()); + const record: Record = await distributeGpgKey( + alice.cells[0], + sampleGpgKey(), + ); assert.ok(record); }); }); -test('Get my keys', async () => { - await runScenario(async scenario => { - const testAppPath = process.cwd() + '/../workdir/hWOT.happ'; +test("Get my keys", async () => { + await runScenario(async (scenario) => { + const testAppPath = process.cwd() + "/../workdir/hWOT.happ"; const appSource = { appBundleSource: { path: testAppPath } }; const [alice] = await scenario.addPlayersWithApps([appSource]); // Alice distributes a GpgKey - const record: Record = await distributeGpgKey(alice.cells[0], sampleGpgKey()); + const record: Record = await distributeGpgKey( + alice.cells[0], + sampleGpgKey(), + ); assert.ok(record); // Bob gets the created GpgKey @@ -41,17 +47,23 @@ test('Get my keys', async () => { }); }); -test('Search for a key', async () => { - await runScenario(async scenario => { - const testAppPath = process.cwd() + '/../workdir/hWOT.happ'; +test("Search for a key", async () => { + await runScenario(async (scenario) => { + const testAppPath = process.cwd() + "/../workdir/hWOT.happ"; const appSource = { appBundleSource: { path: testAppPath } }; - const [alice, bob] = await scenario.addPlayersWithApps([appSource, appSource]); + const [alice, bob] = await scenario.addPlayersWithApps([ + appSource, + appSource, + ]); await scenario.shareAllAgents(); // Alice distributes a GPG key - const record: Record = await distributeGpgKey(alice.cells[0], sampleGpgKey()); + const record: Record = await distributeGpgKey( + alice.cells[0], + sampleGpgKey(), + ); assert.ok(record); await dhtSync([alice, bob], alice.cells[0].cell_id[0]); @@ -62,11 +74,11 @@ test('Search for a key', async () => { fn_name: "search_keys", payload: { // Assume Alice has told Bob the fingerprint - query: "0B1D4843CA2F198CAC2F5C6A449D7AE5D2532CEF" + query: "0B1D4843CA2F198CAC2F5C6A449D7AE5D2532CEF", }, }); assert.equal(responses.length, 1); assert.equal(responses[0].gpg_key_dist.name, "Alice"); - assert.equal( responses[0].gpg_key_dist.public_key, sampleGpgKey().trim()); + assert.equal(responses[0].gpg_key_dist.public_key, sampleGpgKey().trim()); }); }); diff --git a/tests/src/trusted/trusted/key-collection.test.ts b/tests/src/trusted/trusted/key-collection.test.ts index 6f31dd8..f34e224 100644 --- a/tests/src/trusted/trusted/key-collection.test.ts +++ b/tests/src/trusted/trusted/key-collection.test.ts @@ -1,138 +1,170 @@ import { assert, test } from "vitest"; -import { runScenario, dhtSync } from '@holochain/tryorama'; -import { Record } from '@holochain/client'; - -import { GpgKeyDist, KeyCollectionWithKeys, createKeyCollection, decodeRecord, distributeGpgKey, sampleGpgKey } from './common.js'; - -test('Create key collection', async () => { - await runScenario(async scenario => { - const testAppPath = process.cwd() + '/../workdir/hWOT.happ'; - const appSource = { appBundleSource: { path: testAppPath } }; - - const [alice] = await scenario.addPlayersWithApps([appSource]); - - // Alice creates a key collection - const record: Record = await createKeyCollection(alice.cells[0], "a test"); - assert.ok(record); - }); +import { runScenario, dhtSync } from "@holochain/tryorama"; +import { Record } from "@holochain/client"; + +import { + GpgKeyDist, + KeyCollectionWithKeys, + createKeyCollection, + decodeRecord, + distributeGpgKey, + sampleGpgKey, +} from "./common.js"; + +test("Create key collection", async () => { + await runScenario(async (scenario) => { + const testAppPath = process.cwd() + "/../workdir/hWOT.happ"; + const appSource = { appBundleSource: { path: testAppPath } }; + + const [alice] = await scenario.addPlayersWithApps([appSource]); + + // Alice creates a key collection + const record: Record = await createKeyCollection(alice.cells[0], "a test"); + assert.ok(record); + }); }); -test('Create key collection limit', async () => { - await runScenario(async scenario => { - const testAppPath = process.cwd() + '/../workdir/hWOT.happ'; - const appSource = { appBundleSource: { path: testAppPath } }; - - const [alice] = await scenario.addPlayersWithApps([appSource]); - - // Alice creates the allowed number of key collections - for (let i = 0; i < 10; i++) { - const record: Record = await createKeyCollection(alice.cells[0], `a test ${i}`); - assert.ok(record); - } - - let failed = false; - try { - await createKeyCollection(alice.cells[0], `a test too many`); - } catch { - failed = true; - } - assert.ok(failed); - }); +test("Create key collection limit", async () => { + await runScenario(async (scenario) => { + const testAppPath = process.cwd() + "/../workdir/hWOT.happ"; + const appSource = { appBundleSource: { path: testAppPath } }; + + const [alice] = await scenario.addPlayersWithApps([appSource]); + + // Alice creates the allowed number of key collections + for (let i = 0; i < 10; i++) { + const record: Record = await createKeyCollection( + alice.cells[0], + `a test ${i}`, + ); + assert.ok(record); + } + + let failed = false; + try { + await createKeyCollection(alice.cells[0], `a test too many`); + } catch { + failed = true; + } + assert.ok(failed); + }); }); -test('Get my key collections', async () => { - await runScenario(async scenario => { - const testAppPath = process.cwd() + '/../workdir/hWOT.happ'; - const appSource = { appBundleSource: { path: testAppPath } }; - - const [alice] = await scenario.addPlayersWithApps([appSource]); - - // Alice creates some key collections - for (let i = 0; i < 2; i++) { - const record: Record = await createKeyCollection(alice.cells[0], `a test ${i}`); - assert.ok(record); - } - - const key_collections: KeyCollectionWithKeys[] = await alice.cells[0].callZome({ - zome_name: "trusted", - fn_name: "get_my_key_collections", - payload: null, - }); - - assert.equal(key_collections.length, 2); - }); +test("Get my key collections", async () => { + await runScenario(async (scenario) => { + const testAppPath = process.cwd() + "/../workdir/hWOT.happ"; + const appSource = { appBundleSource: { path: testAppPath } }; + + const [alice] = await scenario.addPlayersWithApps([appSource]); + + // Alice creates some key collections + for (let i = 0; i < 2; i++) { + const record: Record = await createKeyCollection( + alice.cells[0], + `a test ${i}`, + ); + assert.ok(record); + } + + const key_collections: KeyCollectionWithKeys[] = + await alice.cells[0].callZome({ + zome_name: "trusted", + fn_name: "get_my_key_collections", + payload: null, + }); + + assert.equal(key_collections.length, 2); + }); }); -test('Link GPG key to collection', async () => { - await runScenario(async scenario => { - const testAppPath = process.cwd() + '/../workdir/hWOT.happ'; - const appSource = { appBundleSource: { path: testAppPath } }; - - const [alice] = await scenario.addPlayersWithApps([appSource]); - - // Alice distributes a GPG key - const gpg_key_record: Record = await distributeGpgKey(alice.cells[0], sampleGpgKey()); - assert.ok(gpg_key_record); - - // Alice creates a key collection - const key_collection_record: Record = await createKeyCollection(alice.cells[0], "a test"); - assert.ok(key_collection_record); - - // Alice links the GPG key to the key collection - await alice.cells[0].callZome({ - zome_name: "trusted", - fn_name: "link_gpg_key_to_key_collection", - payload: { - gpg_key_fingerprint: decodeRecord(gpg_key_record).fingerprint, - key_collection_name: "a test", - }, - }); - - const key_collections: KeyCollectionWithKeys[] = await alice.cells[0].callZome({ - zome_name: "trusted", - fn_name: "get_my_key_collections", - payload: null, - }); - - assert.equal(key_collections.length, 1); - assert.equal(key_collections[0].gpg_keys.length, 1); +test("Link GPG key to collection", async () => { + await runScenario(async (scenario) => { + const testAppPath = process.cwd() + "/../workdir/hWOT.happ"; + const appSource = { appBundleSource: { path: testAppPath } }; + + const [alice] = await scenario.addPlayersWithApps([appSource]); + + // Alice distributes a GPG key + const gpg_key_record: Record = await distributeGpgKey( + alice.cells[0], + sampleGpgKey(), + ); + assert.ok(gpg_key_record); + + // Alice creates a key collection + const key_collection_record: Record = await createKeyCollection( + alice.cells[0], + "a test", + ); + assert.ok(key_collection_record); + + // Alice links the GPG key to the key collection + await alice.cells[0].callZome({ + zome_name: "trusted", + fn_name: "link_gpg_key_to_key_collection", + payload: { + gpg_key_fingerprint: + decodeRecord(gpg_key_record).fingerprint, + key_collection_name: "a test", + }, }); -}); - -test('Remote validation', async () => { - await runScenario(async scenario => { - const testAppPath = process.cwd() + '/../workdir/hWOT.happ'; - const appSource = { appBundleSource: { path: testAppPath } }; - - const [alice, bob] = await scenario.addPlayersWithApps([appSource, appSource]); - - await scenario.shareAllAgents(); - // Alice creates some keys collections - for (let i = 0; i < 3; i++) { - const record: Record = await createKeyCollection(alice.cells[0], `a test ${i}`); - assert.ok(record); - } + const key_collections: KeyCollectionWithKeys[] = + await alice.cells[0].callZome({ + zome_name: "trusted", + fn_name: "get_my_key_collections", + payload: null, + }); - // The DHT shouldn't sync if the remote validation fails - await dhtSync([alice, bob], alice.cells[0].cell_id[0]); - - // Alice distributes a GPG key - const gpg_key_record: Record = await distributeGpgKey(alice.cells[0], sampleGpgKey()); - assert.ok(gpg_key_record); - - // Alice links the GPG key to a key collection - await alice.cells[0].callZome({ - zome_name: "trusted", - fn_name: "link_gpg_key_to_key_collection", - payload: { - gpg_key_fingerprint: decodeRecord(gpg_key_record).fingerprint, - key_collection_name: "a test 1", - }, - }); + assert.equal(key_collections.length, 1); + assert.equal(key_collections[0].gpg_keys.length, 1); + }); +}); - // The DHT shouldn't sync if the remote validation fails - await dhtSync([alice, bob], alice.cells[0].cell_id[0]); +test("Remote validation", async () => { + await runScenario(async (scenario) => { + const testAppPath = process.cwd() + "/../workdir/hWOT.happ"; + const appSource = { appBundleSource: { path: testAppPath } }; + + const [alice, bob] = await scenario.addPlayersWithApps([ + appSource, + appSource, + ]); + + await scenario.shareAllAgents(); + + // Alice creates some keys collections + for (let i = 0; i < 3; i++) { + const record: Record = await createKeyCollection( + alice.cells[0], + `a test ${i}`, + ); + assert.ok(record); + } + + // The DHT shouldn't sync if the remote validation fails + await dhtSync([alice, bob], alice.cells[0].cell_id[0]); + + // Alice distributes a GPG key + const gpg_key_record: Record = await distributeGpgKey( + alice.cells[0], + sampleGpgKey(), + ); + assert.ok(gpg_key_record); + + // Alice links the GPG key to a key collection + await alice.cells[0].callZome({ + zome_name: "trusted", + fn_name: "link_gpg_key_to_key_collection", + payload: { + gpg_key_fingerprint: + decodeRecord(gpg_key_record).fingerprint, + key_collection_name: "a test 1", + }, }); + + // The DHT shouldn't sync if the remote validation fails + await dhtSync([alice, bob], alice.cells[0].cell_id[0]); + }); }); diff --git a/tests/src/trusted/trusted/reference-count.test.ts b/tests/src/trusted/trusted/reference-count.test.ts index 542c0d4..51b8dac 100644 --- a/tests/src/trusted/trusted/reference-count.test.ts +++ b/tests/src/trusted/trusted/reference-count.test.ts @@ -1,150 +1,177 @@ import { assert, test } from "vitest"; -import { runScenario, dhtSync } from '@holochain/tryorama'; -import { Record } from '@holochain/client'; - -import { GpgKeyDist, GpgKeyResponse, KeyCollectionWithKeys, createKeyCollection, decodeRecord, distributeGpgKey, sampleGpgKey } from './common.js'; - -test('Get my keys for a key which is in another agent\'s collection', async () => { - await runScenario(async scenario => { - const testAppPath = process.cwd() + '/../workdir/hWOT.happ'; - const appSource = { appBundleSource: { path: testAppPath } }; - - const [alice, bob] = await scenario.addPlayersWithApps([appSource, appSource]); - - await scenario.shareAllAgents(); - - // Alice distributes a GPG key - const record: Record = await distributeGpgKey(alice.cells[0], sampleGpgKey()); - assert.ok(record); - - await dhtSync([alice, bob], alice.cells[0].cell_id[0]); - - // Bob creates a collection - await createKeyCollection(bob.cells[0], "a test"); - - // Bob links the GPG key to their key collection - await bob.cells[0].callZome({ - zome_name: "trusted", - fn_name: "link_gpg_key_to_key_collection", - payload: { - gpg_key_fingerprint: decodeRecord(record).fingerprint, - key_collection_name: "a test", - }, - }); - - await dhtSync([alice, bob], alice.cells[0].cell_id[0]); - - // Alice searches for their own key - const responses: GpgKeyResponse[] = await alice.cells[0].callZome({ - zome_name: "trusted", - fn_name: "get_my_gpg_key_dists", - payload: null, - }); - assert.equal(responses.length, 1); - assert.equal(responses[0].gpg_key_dist.name, "Alice"); - assert.equal(responses[0].reference_count, 1); +import { runScenario, dhtSync } from "@holochain/tryorama"; +import { Record } from "@holochain/client"; + +import { + GpgKeyDist, + GpgKeyResponse, + KeyCollectionWithKeys, + createKeyCollection, + decodeRecord, + distributeGpgKey, + sampleGpgKey, +} from "./common.js"; + +test("Get my keys for a key which is in another agent's collection", async () => { + await runScenario(async (scenario) => { + const testAppPath = process.cwd() + "/../workdir/hWOT.happ"; + const appSource = { appBundleSource: { path: testAppPath } }; + + const [alice, bob] = await scenario.addPlayersWithApps([ + appSource, + appSource, + ]); + + await scenario.shareAllAgents(); + + // Alice distributes a GPG key + const record: Record = await distributeGpgKey( + alice.cells[0], + sampleGpgKey(), + ); + assert.ok(record); + + await dhtSync([alice, bob], alice.cells[0].cell_id[0]); + + // Bob creates a collection + await createKeyCollection(bob.cells[0], "a test"); + + // Bob links the GPG key to their key collection + await bob.cells[0].callZome({ + zome_name: "trusted", + fn_name: "link_gpg_key_to_key_collection", + payload: { + gpg_key_fingerprint: decodeRecord(record).fingerprint, + key_collection_name: "a test", + }, }); + + await dhtSync([alice, bob], alice.cells[0].cell_id[0]); + + // Alice searches for their own key + const responses: GpgKeyResponse[] = await alice.cells[0].callZome({ + zome_name: "trusted", + fn_name: "get_my_gpg_key_dists", + payload: null, + }); + assert.equal(responses.length, 1); + assert.equal(responses[0].gpg_key_dist.name, "Alice"); + assert.equal(responses[0].reference_count, 1); + }); }); -test('Search for a key which is in another agent\'s collection', async () => { - await runScenario(async scenario => { - const testAppPath = process.cwd() + '/../workdir/hWOT.happ'; - const appSource = { appBundleSource: { path: testAppPath } }; - - const [alice, bob] = await scenario.addPlayersWithApps([appSource, appSource]); - - await scenario.shareAllAgents(); - - // Alice distributes a GPG key - const record: Record = await distributeGpgKey(alice.cells[0], sampleGpgKey()); - assert.ok(record); - - await dhtSync([alice, bob], alice.cells[0].cell_id[0]); - - // Bob creates a collection - await createKeyCollection(bob.cells[0], "a test"); - - // Bob links the GPG key to their key collection - await bob.cells[0].callZome({ - zome_name: "trusted", - fn_name: "link_gpg_key_to_key_collection", - payload: { - gpg_key_fingerprint: decodeRecord(record).fingerprint, - key_collection_name: "a test", - }, - }); - - await dhtSync([alice, bob], alice.cells[0].cell_id[0]); - - // Alice searches for their own key - const responses: GpgKeyResponse[] = await alice.cells[0].callZome({ - zome_name: "trusted", - fn_name: "search_keys", - payload: { - query: "0B1D4843CA2F198CAC2F5C6A449D7AE5D2532CEF" - }, - }); - assert.equal(responses.length, 1); - assert.equal(responses[0].gpg_key_dist.name, "Alice"); - assert.equal(responses[0].reference_count, 1); +test("Search for a key which is in another agent's collection", async () => { + await runScenario(async (scenario) => { + const testAppPath = process.cwd() + "/../workdir/hWOT.happ"; + const appSource = { appBundleSource: { path: testAppPath } }; + + const [alice, bob] = await scenario.addPlayersWithApps([ + appSource, + appSource, + ]); + + await scenario.shareAllAgents(); + + // Alice distributes a GPG key + const record: Record = await distributeGpgKey( + alice.cells[0], + sampleGpgKey(), + ); + assert.ok(record); + + await dhtSync([alice, bob], alice.cells[0].cell_id[0]); + + // Bob creates a collection + await createKeyCollection(bob.cells[0], "a test"); + + // Bob links the GPG key to their key collection + await bob.cells[0].callZome({ + zome_name: "trusted", + fn_name: "link_gpg_key_to_key_collection", + payload: { + gpg_key_fingerprint: decodeRecord(record).fingerprint, + key_collection_name: "a test", + }, + }); + + await dhtSync([alice, bob], alice.cells[0].cell_id[0]); + + // Alice searches for their own key + const responses: GpgKeyResponse[] = await alice.cells[0].callZome({ + zome_name: "trusted", + fn_name: "search_keys", + payload: { + query: "0B1D4843CA2F198CAC2F5C6A449D7AE5D2532CEF", + }, }); + assert.equal(responses.length, 1); + assert.equal(responses[0].gpg_key_dist.name, "Alice"); + assert.equal(responses[0].reference_count, 1); + }); }); -test('Get my key collections for a key which is in another agent\'s collection', async () => { - await runScenario(async scenario => { - const testAppPath = process.cwd() + '/../workdir/hWOT.happ'; - const appSource = { appBundleSource: { path: testAppPath } }; - - const [alice, bob, carol] = await scenario.addPlayersWithApps([appSource, appSource, appSource]); - - await scenario.shareAllAgents(); - - // Alice distributes a GPG key - const record: Record = await distributeGpgKey(alice.cells[0], sampleGpgKey()); - assert.ok(record); - - // All need to be able to see Alice's GPG key - await dhtSync([alice, bob, carol], alice.cells[0].cell_id[0]); - - // Bob creates a collection - await createKeyCollection(bob.cells[0], "bob test"); - - // Bob links Alice's GPG key to their key collection - await bob.cells[0].callZome({ - zome_name: "trusted", - fn_name: "link_gpg_key_to_key_collection", - payload: { - gpg_key_fingerprint: decodeRecord(record).fingerprint, - key_collection_name: "bob test", - }, - }); - - // Carol creates a collection - await createKeyCollection(carol.cells[0], "carol test"); - - // Carol links Alice's GPG key to their key collection - await carol.cells[0].callZome({ - zome_name: "trusted", - fn_name: "link_gpg_key_to_key_collection", - payload: { - gpg_key_fingerprint: decodeRecord(record).fingerprint, - key_collection_name: "carol test", - }, - }); - - await dhtSync([alice, bob, carol], alice.cells[0].cell_id[0]); - - // Bob checks their key collections - const responses: KeyCollectionWithKeys[] = await bob.cells[0].callZome({ - zome_name: "trusted", - fn_name: "get_my_key_collections", - payload: null, - }); - assert.equal(responses.length, 1); - assert.equal(responses[0].name, "bob test"); - assert.equal(responses[0].gpg_keys.length, 1); - // It's in Bob's collection and Carol's collections - assert.equal(responses[0].gpg_keys[0].reference_count, 2); +test("Get my key collections for a key which is in another agent's collection", async () => { + await runScenario(async (scenario) => { + const testAppPath = process.cwd() + "/../workdir/hWOT.happ"; + const appSource = { appBundleSource: { path: testAppPath } }; + + const [alice, bob, carol] = await scenario.addPlayersWithApps([ + appSource, + appSource, + appSource, + ]); + + await scenario.shareAllAgents(); + + // Alice distributes a GPG key + const record: Record = await distributeGpgKey( + alice.cells[0], + sampleGpgKey(), + ); + assert.ok(record); + + // All need to be able to see Alice's GPG key + await dhtSync([alice, bob, carol], alice.cells[0].cell_id[0]); + + // Bob creates a collection + await createKeyCollection(bob.cells[0], "bob test"); + + // Bob links Alice's GPG key to their key collection + await bob.cells[0].callZome({ + zome_name: "trusted", + fn_name: "link_gpg_key_to_key_collection", + payload: { + gpg_key_fingerprint: decodeRecord(record).fingerprint, + key_collection_name: "bob test", + }, + }); + + // Carol creates a collection + await createKeyCollection(carol.cells[0], "carol test"); + + // Carol links Alice's GPG key to their key collection + await carol.cells[0].callZome({ + zome_name: "trusted", + fn_name: "link_gpg_key_to_key_collection", + payload: { + gpg_key_fingerprint: decodeRecord(record).fingerprint, + key_collection_name: "carol test", + }, + }); + + await dhtSync([alice, bob, carol], alice.cells[0].cell_id[0]); + + // Bob checks their key collections + const responses: KeyCollectionWithKeys[] = await bob.cells[0].callZome({ + zome_name: "trusted", + fn_name: "get_my_key_collections", + payload: null, }); + assert.equal(responses.length, 1); + assert.equal(responses[0].name, "bob test"); + assert.equal(responses[0].gpg_keys.length, 1); + // It's in Bob's collection and Carol's collections + assert.equal(responses[0].gpg_keys[0].reference_count, 2); + }); });