Skip to content

Commit

Permalink
Format tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Feb 24, 2024
1 parent d6c77e8 commit c6814ec
Show file tree
Hide file tree
Showing 4 changed files with 380 additions and 303 deletions.
48 changes: 27 additions & 21 deletions tests/src/trusted/trusted/common.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,13 +20,13 @@ export interface KeyCollectionWithKeys {
gpg_keys: GpgKeyResponse[];
}

export const decodeRecord = <T> (record: Record): T => {
export const decodeRecord = <T>(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
Expand All @@ -43,20 +43,26 @@ NTxJAQC4xdYMveSHdOiKO4ZhoojG6r7IqX8B8vAZsod6cF/8CA==
`;
}

export async function distributeGpgKey(cell: CallableCell, gpgKey: string): Promise<Record> {
return cell.callZome({
zome_name: "trusted",
fn_name: "distribute_gpg_key",
payload: {
public_key: gpgKey
},
});
export async function distributeGpgKey(
cell: CallableCell,
gpgKey: string,
): Promise<Record> {
return cell.callZome({
zome_name: "trusted",
fn_name: "distribute_gpg_key",
payload: {
public_key: gpgKey,
},
});
}

export async function createKeyCollection(cell: CallableCell, name: string): Promise<Record> {
return cell.callZome({
zome_name: "trusted",
fn_name: "create_key_collection",
payload: { name },
});
export async function createKeyCollection(
cell: CallableCell,
name: string,
): Promise<Record> {
return cell.callZome({
zome_name: "trusted",
fn_name: "create_key_collection",
payload: { name },
});
}
48 changes: 30 additions & 18 deletions tests/src/trusted/trusted/gpg-key-dist.test.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]);
Expand All @@ -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());
});
});
Loading

0 comments on commit c6814ec

Please sign in to comment.