Skip to content

Commit

Permalink
First fetch test
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Mar 27, 2024
1 parent 4d1542b commit ffd7d6d
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 11 deletions.
10 changes: 4 additions & 6 deletions dnas/checked/zomes/coordinator/fetch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn prepare_fetch(request: PrepareFetchRequest) -> ExternResult<Vec<FetchCheckSig
"signing_keys".to_string(),
"get_my_key_collections".into(),
None,
ExternIO::encode(()).map_err(|e| wasm_error!(WasmErrorInner::Guest(e.to_string())))?,
(),
)? {
ZomeCallResponse::Ok(response) => response
.decode()
Expand All @@ -78,12 +78,10 @@ fn prepare_fetch(request: PrepareFetchRequest) -> ExternResult<Vec<FetchCheckSig
}
};

pick_signatures(signatures, key_collections);

Ok(vec![])
Ok(pick_signatures(signatures, key_collections))
}

fn pick_signatures(possible_signatures: Vec<Record>, key_collections: Vec<KeyCollectionWithKeys>) {
fn pick_signatures(possible_signatures: Vec<Record>, key_collections: Vec<KeyCollectionWithKeys>) -> Vec<FetchCheckSignature> {
let possible_signatures: Vec<(Action, AssetSignature)> = possible_signatures
.into_iter()
.filter_map(|record| {
Expand Down Expand Up @@ -129,5 +127,5 @@ fn pick_signatures(possible_signatures: Vec<Record>, key_collections: Vec<KeyCol
}
}

todo!()
picked_signatures
}
2 changes: 2 additions & 0 deletions tests/src/checked/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

export const testAppPath = process.cwd() + "/../workdir/checked.happ";
53 changes: 53 additions & 0 deletions tests/src/checked/fetch/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {CallableCell} from "@holochain/tryorama";
import {AgentPubKey, Record} from "@holochain/client";

export interface PrepareFetchRequest {
fetch_url: string;
}

// #[derive(Serialize, Deserialize, Debug)]
// pub struct FetchCheckSignaturePinned {
// pub author: AgentPubKey,
// pub key_collection: String,
// pub key_name: String,
// }
//
// #[derive(Serialize, Deserialize, Debug)]
// pub enum FetchCheckSignatureReason {
// RandomRecent,
// RandomHistorical,
// Pinned(FetchCheckSignaturePinned),
// }
//
// #[derive(Serialize, Deserialize, Debug)]
// pub struct FetchCheckSignature {
// signature: Vec<u8>,
// 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<FetchCheckSignature[]> => {
return cell.callZome({
zome_name: "fetch",
fn_name: "prepare_fetch",
payload: request,
});
}
18 changes: 18 additions & 0 deletions tests/src/checked/fetch/fetch.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
2 changes: 0 additions & 2 deletions tests/src/checked/signing_keys/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/checked/signing_keys/key-collection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/src/checked/signing_keys/reference-count.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {
createKeyCollection,
distributeVerificationKey,
sampleMiniSignKey,
testAppPath,
sampleMiniSignProof,
sampleMiniSignProofSignature,
linkVerificationKeyToKeyCollection,
getMyVerificationKeyDistributions,
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) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/src/checked/signing_keys/validation-key-dist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Record } from "@holochain/client";
import {
distributeVerificationKey,
sampleMiniSignKey,
testAppPath,
sampleMiniSignProof,
sampleMiniSignProofSignature,
sampleMiniSignProofSignature2,
Expand All @@ -17,6 +16,7 @@ import {
searchKeysLocal,
markVerificationKeyRotated,
} from "./common.js";
import {testAppPath} from "../common";

test("Distribute a key", async () => {
await runScenario(async (scenario) => {
Expand Down

0 comments on commit ffd7d6d

Please sign in to comment.