Skip to content

Commit

Permalink
Test system signals (#233)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
ThetaSinner and jost-s authored Aug 23, 2024
1 parent d5033e0 commit a029a06
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 52 deletions.
40 changes: 20 additions & 20 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 4 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"prepublishOnly": "npm run build"
},
"dependencies": {
"@holochain/client": "^0.18.0-dev.8",
"@holochain/client": "^0.18.0-dev.10",
"get-port": "^6.1.2",
"lodash": "^4.17.21",
"uuid": "^8.3.2",
Expand Down
96 changes: 95 additions & 1 deletion ts/test/fixture/zomes/coordinator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use hdk::prelude::*;
use integrity::{Content, EntryTypes, UpdateInput};
use integrity::{Content, EntryTypes, EntryTypesUnit, UpdateInput};

#[hdk_extern]
pub fn create(input: Content) -> ExternResult<ActionHash> {
Expand Down Expand Up @@ -42,3 +42,97 @@ fn signal_loopback(value: LoopBack) -> ExternResult<()> {
emit_signal(&value)?;
Ok(())
}

#[hdk_extern]
fn create_two_party_countersigning_session(with_other: AgentPubKey) -> ExternResult<PreflightResponse> {
let my_agent_info = agent_info()?;

let entry = Content("hello".to_string());

let entry_hash = hash_entry(EntryTypes::Content(entry.clone()))?;

let session_times = session_times_from_millis(10_000)?;
let request = PreflightRequest::try_new(
entry_hash,
vec![
(
my_agent_info.agent_initial_pubkey,
vec![],
),
(with_other.clone(), vec![]),
],
Vec::with_capacity(0),
0,
true,
session_times,
ActionBase::Create(CreateBase::new(
EntryTypesUnit::Content.try_into()?,
)),
PreflightBytes(vec![]),
)
.map_err(|e| {
wasm_error!(WasmErrorInner::Guest(format!(
"Failed to create countersigning request: {:?}",
e
)))
})?;

// Accept ours now and then Holochain should wait for the other party to join the session
let my_acceptance = accept_countersigning_preflight_request(request.clone())?;

let response = match &my_acceptance {
PreflightRequestAcceptance::Accepted(response) => response.clone(),
e => {
return Err(wasm_error!(WasmErrorInner::Guest(format!(
"Unexpected response: {:?}",
e
))))
}
};

Ok(response)
}

#[hdk_extern]
fn accept_two_party(request: PreflightRequest) -> ExternResult<PreflightResponse> {
let my_accept = accept_countersigning_preflight_request(request)?;
match my_accept {
PreflightRequestAcceptance::Accepted(response) => {
Ok(response)
}
e => Err(wasm_error!(WasmErrorInner::Guest(format!(
"Unexpected response: {:?}",
e
)))),
}
}

#[hdk_extern]
fn commit_two_party(responses: Vec<PreflightResponse>) -> ExternResult<()> {
let inner = Content("hello".to_string());

let entry = Entry::CounterSign(
Box::new(
CounterSigningSessionData::try_from_responses(responses, vec![]).map_err(
|countersigning_error| {
wasm_error!(WasmErrorInner::Guest(countersigning_error.to_string()))
},
)?,
),
inner.clone().try_into()?,
);

let agreement = EntryTypes::Content(inner);
let entry_def_index = ScopedEntryDefIndex::try_from(&agreement)?;
let visibility = EntryVisibility::from(&agreement);

hdk::prelude::create(CreateInput::new(
entry_def_index,
visibility,
entry,
// Countersigned entries MUST have strict ordering.
ChainTopOrdering::Strict,
))?;

Ok(())
}
1 change: 1 addition & 0 deletions ts/test/fixture/zomes/integrity/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use hdi::prelude::*;

#[hdk_entry_helper]
#[derive(Clone)]
pub struct Content(pub String);

#[hdk_entry_helper]
Expand Down
13 changes: 8 additions & 5 deletions ts/test/local/conductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
CellProvisioningStrategy,
CloneId,
EntryHash,
Signal,
SignalType,
} from "@holochain/client";
import assert from "node:assert";
import { readFileSync, realpathSync } from "node:fs";
Expand Down Expand Up @@ -165,10 +167,10 @@ test("Local Conductor - install app with deferred memproofs", async (t) => {
const appWs = await conductor.connectAppWs(issued.token, port);

let appInfo = await appWs.appInfo();
t.equal(
t.deepEqual(
appInfo.status,
"awaiting_memproofs",
"app status is awaiting_memproofs"
{ disabled: { reason: "never_started" } },
"app status is never_started"
);

const response = await appWs.provideMemproofs({});
Expand Down Expand Up @@ -616,8 +618,9 @@ test("Local Conductor - Receive a signal", async (t) => {
const { servicesProcess, signalingServerUrl } = await runLocalServices();
let signalHandler: AppSignalCb | undefined;
const signalReceived = new Promise<AppSignal>((resolve) => {
signalHandler = (signal) => {
resolve(signal);
signalHandler = (signal: Signal) => {
assert(SignalType.App in signal);
resolve(signal[SignalType.App]);
};
});
const conductor = await createConductor(signalingServerUrl);
Expand Down
Loading

0 comments on commit a029a06

Please sign in to comment.