From ffd7d6d2516606e1d433b29c9d82cef9b67e1943 Mon Sep 17 00:00:00 2001 From: ThetaSinner Date: Wed, 27 Mar 2024 03:30:37 +0000 Subject: [PATCH] First fetch test --- .../zomes/coordinator/fetch/src/lib.rs | 10 ++-- tests/src/checked/common.ts | 2 + tests/src/checked/fetch/common.ts | 53 +++++++++++++++++++ tests/src/checked/fetch/fetch.test.ts | 18 +++++++ tests/src/checked/signing_keys/common.ts | 2 - .../signing_keys/key-collection.test.ts | 2 +- .../signing_keys/reference-count.test.ts | 2 +- .../signing_keys/validation-key-dist.test.ts | 2 +- 8 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 tests/src/checked/common.ts create mode 100644 tests/src/checked/fetch/common.ts create mode 100644 tests/src/checked/fetch/fetch.test.ts diff --git a/dnas/checked/zomes/coordinator/fetch/src/lib.rs b/dnas/checked/zomes/coordinator/fetch/src/lib.rs index b10475f..3dca739 100644 --- a/dnas/checked/zomes/coordinator/fetch/src/lib.rs +++ b/dnas/checked/zomes/coordinator/fetch/src/lib.rs @@ -66,7 +66,7 @@ fn prepare_fetch(request: PrepareFetchRequest) -> ExternResult response .decode() @@ -78,12 +78,10 @@ fn prepare_fetch(request: PrepareFetchRequest) -> ExternResult, key_collections: Vec) { +fn pick_signatures(possible_signatures: Vec, key_collections: Vec) -> Vec { let possible_signatures: Vec<(Action, AssetSignature)> = possible_signatures .into_iter() .filter_map(|record| { @@ -129,5 +127,5 @@ fn pick_signatures(possible_signatures: Vec, key_collections: Vec, +// reason: FetchCheckSignatureReason, +// } + +export interface FetchCheckSignaturePinned { + author: AgentPubKey; + key_collection: string; + key_name: string; +} + +export type FetchCheckSignatureReason = + | { RandomRecent: null } + | { RandomHistorical: null } + | { Pinned: FetchCheckSignaturePinned }; + +export interface FetchCheckSignature { + signature: Uint8Array; + reason: FetchCheckSignatureReason; +} + +export const prepareFetch = async ( + cell: CallableCell, + request: PrepareFetchRequest, +): Promise => { + return cell.callZome({ + zome_name: "fetch", + fn_name: "prepare_fetch", + payload: request, + }); +} diff --git a/tests/src/checked/fetch/fetch.test.ts b/tests/src/checked/fetch/fetch.test.ts new file mode 100644 index 0000000..20e90e1 --- /dev/null +++ b/tests/src/checked/fetch/fetch.test.ts @@ -0,0 +1,18 @@ +import { assert, test } from "vitest"; + +import { runScenario } from "@holochain/tryorama"; + +import {testAppPath} from "../common"; +import {prepareFetch} from "./common"; + +test("Fetch with no existing signatures", async () => { + await runScenario(async (scenario) => { + const appSource = { appBundleSource: { path: testAppPath } }; + + const [alice] = await scenario.addPlayersWithApps([appSource]); + + const check_signatures = await prepareFetch(alice.cells[0], { fetch_url: "https://example.com/sample.csv" }); + + assert.equal(check_signatures.length, 0); + }); +}); diff --git a/tests/src/checked/signing_keys/common.ts b/tests/src/checked/signing_keys/common.ts index 06f7a7f..502f7d7 100644 --- a/tests/src/checked/signing_keys/common.ts +++ b/tests/src/checked/signing_keys/common.ts @@ -4,8 +4,6 @@ import { decode } from "@msgpack/msgpack"; const utf8Encode = new TextEncoder(); -export const testAppPath = process.cwd() + "/../workdir/checked.happ"; - export interface VerificationKeyDistMarkRotated { new_verification_key_dist_address: Uint8Array; } diff --git a/tests/src/checked/signing_keys/key-collection.test.ts b/tests/src/checked/signing_keys/key-collection.test.ts index 6087308..77491db 100644 --- a/tests/src/checked/signing_keys/key-collection.test.ts +++ b/tests/src/checked/signing_keys/key-collection.test.ts @@ -7,13 +7,13 @@ import { createKeyCollection, distributeVerificationKey, sampleMiniSignKey, - testAppPath, sampleMiniSignProof, sampleMiniSignProofSignature, getMyKeyCollections, linkVerificationKeyToKeyCollection, unlinkVerificationKeyToKeyCollection, } from "./common.js"; +import {testAppPath} from "../common"; test("Create key collection", async () => { await runScenario(async (scenario) => { diff --git a/tests/src/checked/signing_keys/reference-count.test.ts b/tests/src/checked/signing_keys/reference-count.test.ts index 4e26727..d3e3b89 100644 --- a/tests/src/checked/signing_keys/reference-count.test.ts +++ b/tests/src/checked/signing_keys/reference-count.test.ts @@ -7,7 +7,6 @@ import { createKeyCollection, distributeVerificationKey, sampleMiniSignKey, - testAppPath, sampleMiniSignProof, sampleMiniSignProofSignature, linkVerificationKeyToKeyCollection, @@ -15,6 +14,7 @@ import { searchKeys, getMyKeyCollections, } from "./common.js"; +import {testAppPath} from "../common"; test("Get my keys for a key which is in another agent's collection", async () => { await runScenario(async (scenario) => { diff --git a/tests/src/checked/signing_keys/validation-key-dist.test.ts b/tests/src/checked/signing_keys/validation-key-dist.test.ts index deb8ab8..3692769 100644 --- a/tests/src/checked/signing_keys/validation-key-dist.test.ts +++ b/tests/src/checked/signing_keys/validation-key-dist.test.ts @@ -6,7 +6,6 @@ import { Record } from "@holochain/client"; import { distributeVerificationKey, sampleMiniSignKey, - testAppPath, sampleMiniSignProof, sampleMiniSignProofSignature, sampleMiniSignProofSignature2, @@ -17,6 +16,7 @@ import { searchKeysLocal, markVerificationKeyRotated, } from "./common.js"; +import {testAppPath} from "../common"; test("Distribute a key", async () => { await runScenario(async (scenario) => {