Skip to content

Commit a029a06

Browse files
ThetaSinnerjost-s
andauthored
Test system signals (#233)
* Test system signals * Update client * Fix tests * Update ts/test/local/scenario.ts Co-authored-by: Jost Schulte <[email protected]> * Update ts/test/local/scenario.ts Co-authored-by: Jost Schulte <[email protected]> --------- Co-authored-by: Jost Schulte <[email protected]>
1 parent d5033e0 commit a029a06

File tree

8 files changed

+213
-52
lines changed

8 files changed

+213
-52
lines changed

flake.lock

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 4 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"prepublishOnly": "npm run build"
4444
},
4545
"dependencies": {
46-
"@holochain/client": "^0.18.0-dev.8",
46+
"@holochain/client": "^0.18.0-dev.10",
4747
"get-port": "^6.1.2",
4848
"lodash": "^4.17.21",
4949
"uuid": "^8.3.2",

ts/test/fixture/zomes/coordinator/src/lib.rs

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use hdk::prelude::*;
2-
use integrity::{Content, EntryTypes, UpdateInput};
2+
use integrity::{Content, EntryTypes, EntryTypesUnit, UpdateInput};
33

44
#[hdk_extern]
55
pub fn create(input: Content) -> ExternResult<ActionHash> {
@@ -42,3 +42,97 @@ fn signal_loopback(value: LoopBack) -> ExternResult<()> {
4242
emit_signal(&value)?;
4343
Ok(())
4444
}
45+
46+
#[hdk_extern]
47+
fn create_two_party_countersigning_session(with_other: AgentPubKey) -> ExternResult<PreflightResponse> {
48+
let my_agent_info = agent_info()?;
49+
50+
let entry = Content("hello".to_string());
51+
52+
let entry_hash = hash_entry(EntryTypes::Content(entry.clone()))?;
53+
54+
let session_times = session_times_from_millis(10_000)?;
55+
let request = PreflightRequest::try_new(
56+
entry_hash,
57+
vec![
58+
(
59+
my_agent_info.agent_initial_pubkey,
60+
vec![],
61+
),
62+
(with_other.clone(), vec![]),
63+
],
64+
Vec::with_capacity(0),
65+
0,
66+
true,
67+
session_times,
68+
ActionBase::Create(CreateBase::new(
69+
EntryTypesUnit::Content.try_into()?,
70+
)),
71+
PreflightBytes(vec![]),
72+
)
73+
.map_err(|e| {
74+
wasm_error!(WasmErrorInner::Guest(format!(
75+
"Failed to create countersigning request: {:?}",
76+
e
77+
)))
78+
})?;
79+
80+
// Accept ours now and then Holochain should wait for the other party to join the session
81+
let my_acceptance = accept_countersigning_preflight_request(request.clone())?;
82+
83+
let response = match &my_acceptance {
84+
PreflightRequestAcceptance::Accepted(response) => response.clone(),
85+
e => {
86+
return Err(wasm_error!(WasmErrorInner::Guest(format!(
87+
"Unexpected response: {:?}",
88+
e
89+
))))
90+
}
91+
};
92+
93+
Ok(response)
94+
}
95+
96+
#[hdk_extern]
97+
fn accept_two_party(request: PreflightRequest) -> ExternResult<PreflightResponse> {
98+
let my_accept = accept_countersigning_preflight_request(request)?;
99+
match my_accept {
100+
PreflightRequestAcceptance::Accepted(response) => {
101+
Ok(response)
102+
}
103+
e => Err(wasm_error!(WasmErrorInner::Guest(format!(
104+
"Unexpected response: {:?}",
105+
e
106+
)))),
107+
}
108+
}
109+
110+
#[hdk_extern]
111+
fn commit_two_party(responses: Vec<PreflightResponse>) -> ExternResult<()> {
112+
let inner = Content("hello".to_string());
113+
114+
let entry = Entry::CounterSign(
115+
Box::new(
116+
CounterSigningSessionData::try_from_responses(responses, vec![]).map_err(
117+
|countersigning_error| {
118+
wasm_error!(WasmErrorInner::Guest(countersigning_error.to_string()))
119+
},
120+
)?,
121+
),
122+
inner.clone().try_into()?,
123+
);
124+
125+
let agreement = EntryTypes::Content(inner);
126+
let entry_def_index = ScopedEntryDefIndex::try_from(&agreement)?;
127+
let visibility = EntryVisibility::from(&agreement);
128+
129+
hdk::prelude::create(CreateInput::new(
130+
entry_def_index,
131+
visibility,
132+
entry,
133+
// Countersigned entries MUST have strict ordering.
134+
ChainTopOrdering::Strict,
135+
))?;
136+
137+
Ok(())
138+
}

ts/test/fixture/zomes/integrity/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use hdi::prelude::*;
22

33
#[hdk_entry_helper]
4+
#[derive(Clone)]
45
pub struct Content(pub String);
56

67
#[hdk_entry_helper]

ts/test/local/conductor.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
CellProvisioningStrategy,
77
CloneId,
88
EntryHash,
9+
Signal,
10+
SignalType,
911
} from "@holochain/client";
1012
import assert from "node:assert";
1113
import { readFileSync, realpathSync } from "node:fs";
@@ -165,10 +167,10 @@ test("Local Conductor - install app with deferred memproofs", async (t) => {
165167
const appWs = await conductor.connectAppWs(issued.token, port);
166168

167169
let appInfo = await appWs.appInfo();
168-
t.equal(
170+
t.deepEqual(
169171
appInfo.status,
170-
"awaiting_memproofs",
171-
"app status is awaiting_memproofs"
172+
{ disabled: { reason: "never_started" } },
173+
"app status is never_started"
172174
);
173175

174176
const response = await appWs.provideMemproofs({});
@@ -616,8 +618,9 @@ test("Local Conductor - Receive a signal", async (t) => {
616618
const { servicesProcess, signalingServerUrl } = await runLocalServices();
617619
let signalHandler: AppSignalCb | undefined;
618620
const signalReceived = new Promise<AppSignal>((resolve) => {
619-
signalHandler = (signal) => {
620-
resolve(signal);
621+
signalHandler = (signal: Signal) => {
622+
assert(SignalType.App in signal);
623+
resolve(signal[SignalType.App]);
621624
};
622625
});
623626
const conductor = await createConductor(signalingServerUrl);

0 commit comments

Comments
 (0)