Skip to content
This repository was archived by the owner on Dec 9, 2023. It is now read-only.

Commit 99af6d0

Browse files
committed
typing & serialisation pass at core API bindings, all hashes are now managed in base64
1 parent 5b85d02 commit 99af6d0

File tree

4 files changed

+164
-3
lines changed

4 files changed

+164
-3
lines changed

src/sensemaker_dna/agent.ts

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
import { DnaSource, Record, ActionHash, EntryHash, AppEntryDef, Create, AgentPubKey, encodeHashToBase64 } from "@holochain/client";
2+
import {
3+
pause,
4+
runScenario,
5+
Scenario,
6+
createConductor,
7+
addAllAgentsToAllConductors,
8+
cleanAllConductors,
9+
} from "@holochain/tryorama";
10+
import { decode } from "@msgpack/msgpack";
11+
import { AppletConfig, Assessment, AssessmentWithDimensionAndResource, CreateAppletConfigInput, CreateAssessmentInput, Method, RangeValueInteger } from "@neighbourhoods/client";
12+
import { ok } from "assert";
13+
import test from "tape-promise/tape";
14+
import { installAgent, sampleAppletConfig } from "../utils";
15+
16+
interface TestPost {
17+
title: string;
18+
content: string;
19+
}
20+
21+
export const setUpAliceandBob = async (
22+
with_config: boolean = false,
23+
resource_base_type?: any
24+
) => {
25+
const alice = await createConductor();
26+
const bob = await createConductor();
27+
const {
28+
agentsHapps: alice_happs,
29+
agent_key: alice_agent_key,
30+
ss_cell_id: ss_cell_id_alice,
31+
provider_cell_id: provider_cell_id_alice,
32+
} = await installAgent(
33+
alice,
34+
"alice",
35+
undefined,
36+
with_config,
37+
resource_base_type
38+
);
39+
const {
40+
agentsHapps: bob_happs,
41+
agent_key: bob_agent_key,
42+
ss_cell_id: ss_cell_id_bob,
43+
provider_cell_id: provider_cell_id_bob,
44+
} = await installAgent(
45+
bob,
46+
"bob",
47+
alice_agent_key,
48+
with_config,
49+
resource_base_type
50+
);
51+
await addAllAgentsToAllConductors([alice, bob]);
52+
return {
53+
alice,
54+
bob,
55+
alice_happs,
56+
bob_happs,
57+
alice_agent_key,
58+
bob_agent_key,
59+
ss_cell_id_alice,
60+
ss_cell_id_bob,
61+
provider_cell_id_alice,
62+
provider_cell_id_bob,
63+
};
64+
};
65+
66+
export default () => {
67+
test("test registering agent", async (t) => {
68+
await runScenario(async (scenario) => {
69+
const {
70+
alice,
71+
bob,
72+
alice_happs,
73+
bob_happs,
74+
alice_agent_key,
75+
bob_agent_key,
76+
ss_cell_id_alice,
77+
ss_cell_id_bob,
78+
provider_cell_id_alice,
79+
provider_cell_id_bob,
80+
} = await setUpAliceandBob();
81+
82+
const callZomeAlice = async (
83+
zome_name,
84+
fn_name,
85+
payload,
86+
is_ss = false
87+
) => {
88+
return await alice.appWs().callZome({
89+
cap_secret: null,
90+
cell_id: is_ss ? ss_cell_id_alice : provider_cell_id_alice,
91+
zome_name,
92+
fn_name,
93+
payload,
94+
provenance: alice_agent_key,
95+
});
96+
};
97+
const callZomeBob = async (
98+
zome_name,
99+
fn_name,
100+
payload,
101+
is_ss = false
102+
) => {
103+
return await bob.appWs().callZome({
104+
cap_secret: null,
105+
cell_id: is_ss ? ss_cell_id_bob : provider_cell_id_bob,
106+
zome_name,
107+
fn_name,
108+
payload,
109+
provenance: bob_agent_key,
110+
});
111+
};
112+
try {
113+
const pauseDuration = 1000
114+
await scenario.shareAllAgents();
115+
await pause(pauseDuration*2);
116+
117+
let agents: Array<AgentPubKey> = await callZomeAlice(
118+
"sensemaker",
119+
"get_all_agents",
120+
null,
121+
true
122+
);
123+
t.ok(agents);
124+
t.equal(agents.length, 0);
125+
console.log("agents", agents);
126+
// Wait for the created entry to be propagated to the other node.
127+
await pause(pauseDuration);
128+
129+
agents = await callZomeBob(
130+
"sensemaker",
131+
"get_all_agents",
132+
null,
133+
true
134+
);
135+
t.ok(agents);
136+
t.equal(agents.length, 1);
137+
t.equal(encodeHashToBase64(agents[0]), encodeHashToBase64(alice_agent_key));
138+
console.log("agents", agents);
139+
await pause(pauseDuration);
140+
141+
agents = await callZomeAlice(
142+
"sensemaker",
143+
"get_all_agents",
144+
null,
145+
true
146+
);
147+
t.ok(agents);
148+
t.equal(agents.length, 1);
149+
t.equal(encodeHashToBase64(agents[0]), encodeHashToBase64(bob_agent_key));
150+
console.log("agents", agents);
151+
} catch (e) {
152+
console.log(e);
153+
t.ok(null);
154+
}
155+
156+
await alice.shutDown();
157+
await bob.shutDown();
158+
await cleanAllConductors();
159+
});
160+
});
161+
};

src/sensemaker_dna/applet_config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
type AppEntryDef = import('@holochain/client').AppEntryDef;
22
type EntryHash = import('@holochain/client').EntryHash;
33

4-
import { AppletConfig, AppletConfigInput, ConfigCulturalContext, ConfigMethod, ConfigResourceDef, ConfigThreshold, CreateAppletConfigInput, CulturalContext, Dimension, Method, Range, Threshold } from "@neighbourhoods/client"
4+
import { AppletConfig, AppletConfigInput, ConfigCulturalContext, ConfigMethod, ConfigResourceDef, ConfigThreshold, CreateAppletConfigInput, CulturalContext, RawDimension as Dimension, Method, Range, Threshold } from "@neighbourhoods/client"
55

66
import { cleanAllConductors, pause, runScenario } from "@holochain/tryorama";
77
//@ts-ignore

src/sensemaker_dna/dashboard.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
cleanAllConductors,
99
} from "@holochain/tryorama";
1010
import { decode } from "@msgpack/msgpack";
11-
import { AppletConfig, Assessment, AssessmentWithDimensionAndResource, CreateAppletConfigInput, CreateAssessmentInput, Method, RangeValueInteger } from "@neighbourhoods/client";
11+
import { RawAppletConfig as AppletConfig, Assessment, AssessmentWithDimensionAndResource, CreateAppletConfigInput, RawCreateAssessmentInput as CreateAssessmentInput, Method, RangeValueInteger } from "@neighbourhoods/client";
1212
import { ok } from "assert";
1313
import test from "tape-promise/tape";
1414
import { installAgent, sampleAppletConfig } from "../utils";

src/sensemaker_dna/neighbourhood.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
cleanAllConductors,
99
} from "@holochain/tryorama";
1010
import { decode } from "@msgpack/msgpack";
11-
import { Assessment, AssessmentWithDimensionAndResource, CreateAssessmentInput, Method, RangeValueInteger, ResourceEh, GetAssessmentsForResourceInput } from "@neighbourhoods/client";
11+
import { RawAssessment as Assessment, AssessmentWithDimensionAndResource, RawCreateAssessmentInput as CreateAssessmentInput, RawMethod as Method, RangeValueInteger, ResourceEh, RawGetAssessmentsForResourceInput as GetAssessmentsForResourceInput } from "@neighbourhoods/client";
1212
import { ok } from "assert";
1313
import test from "tape-promise/tape";
1414
import { setUpAliceandBob } from "../utils";

0 commit comments

Comments
 (0)