Skip to content

Commit

Permalink
merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JettTech committed Aug 26, 2024
2 parents d696d99 + f94c472 commit 30cf7c9
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 34 deletions.
12 changes: 5 additions & 7 deletions ts/src/local/conductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,11 @@ export class Conductor implements IConductor {
installed_app_id,
network_seed,
};
if (agent_key) {
logger.debug(
`installing app with id ${installed_app_id} for agent ${encodeHashToBase64(
agent_key
)}`
);
}
logger.debug(
`installing app with id ${installed_app_id} for agent ${encodeHashToBase64(
agent_key
)}`
);
return this.adminWs().installApp(installAppRequest);
}

Expand Down
2 changes: 1 addition & 1 deletion ts/src/trycp/trycp-client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SignalCb, AppSignal, CallZomeRequestSigned } from "@holochain/client";
import { SignalCb, CallZomeRequestSigned } from "@holochain/client";
import msgpack from "@msgpack/msgpack";
import cloneDeep from "lodash/cloneDeep.js";
import assert from "node:assert";
Expand Down
17 changes: 11 additions & 6 deletions ts/src/trycp/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Signal, SignalType } from "@holochain/client";
import { AppSignal, RawSignal, Signal, SignalType } from "@holochain/client";
import msgpack from "@msgpack/msgpack";
import assert from "node:assert";
import { TryCpApiResponse, _TryCpResponseWrapper } from "./types.js";
Expand All @@ -25,13 +25,18 @@ export const deserializeTryCpResponse = (response: Uint8Array) => {
*/
export const deserializeTryCpSignal = (signal: Uint8Array) => {
const deserializedSignal = msgpack.decode(signal);
assertIsSignal(deserializedSignal);
assertIsRawSignal(deserializedSignal);
if (SignalType.App in deserializedSignal) {
const {
[SignalType.App]: { cell_id, payload: decodedPayload, zome_name },
[SignalType.App]: { cell_id, signal, zome_name },
} = deserializedSignal;
const app_payload = { cell_id, payload: decodedPayload, zome_name };
return { App: app_payload } as Signal;
const decodedPayload = msgpack.decode(signal) as T;
const app_signal: AppSignal = {
cell_id,
zome_name,
payload: decodedPayload,
};
return { App: app_signal } as Signal;
} else {
throw new Error("Receiving system signals is not implemented yet");
}
Expand Down Expand Up @@ -85,7 +90,7 @@ function assertIsApiResponse(
assert(response && typeof response === "object" && "type" in response);
}

function assertIsSignal(signal: unknown): asserts signal is Signal {
function assertIsRawSignal(signal: unknown): asserts signal is RawSignal {
assert(
signal &&
typeof signal === "object" &&
Expand Down
23 changes: 9 additions & 14 deletions ts/test/fixture/zomes/coordinator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ fn signal_loopback(value: LoopBack) -> ExternResult<()> {
}

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

let entry = Content("hello".to_string());
Expand All @@ -55,27 +57,22 @@ fn create_two_party_countersigning_session(with_other: AgentPubKey) -> ExternRes
let request = PreflightRequest::try_new(
entry_hash,
vec![
(
my_agent_info.agent_initial_pubkey,
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()?,
)),
ActionBase::Create(CreateBase::new(EntryTypesUnit::Content.try_into()?)),
PreflightBytes(vec![]),
)
.map_err(|e| {
wasm_error!(WasmErrorInner::Guest(format!(
.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())?;
Expand All @@ -97,9 +94,7 @@ fn create_two_party_countersigning_session(with_other: AgentPubKey) -> ExternRes
fn accept_two_party(request: PreflightRequest) -> ExternResult<PreflightResponse> {
let my_accept = accept_countersigning_preflight_request(request)?;
match my_accept {
PreflightRequestAcceptance::Accepted(response) => {
Ok(response)
}
PreflightRequestAcceptance::Accepted(response) => Ok(response),
e => Err(wasm_error!(WasmErrorInner::Guest(format!(
"Unexpected response: {:?}",
e
Expand Down
1 change: 0 additions & 1 deletion ts/test/local/conductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
CellProvisioningStrategy,
CloneId,
EntryHash,
AppSignal,
SignalType,
} from "@holochain/client";
import assert from "node:assert";
Expand Down
1 change: 0 additions & 1 deletion ts/test/local/scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
SignalCb,
AppWebsocket,
EntryHash,
AppSignal,
SignalType,
} from "@holochain/client";
import assert from "node:assert/strict";
Expand Down
3 changes: 2 additions & 1 deletion ts/test/trycp/conductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
CloneId,
encodeHashToBase64,
EntryHash,
SignalType,
GrantedFunctionsType,
} from "@holochain/client";
import assert from "node:assert";
Expand Down Expand Up @@ -433,7 +434,7 @@ test("TryCP Conductor - receive a signal", async (t) => {
});
const actualSignal = await signalReceived;
t.deepEqual(
actualSignal.payload,
actualSignal[SignalType.App].payload,
testSignal,
"received signal matches expected signal"
);
Expand Down
12 changes: 9 additions & 3 deletions ts/test/trycp/scenario.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Signal, SignalCb, EntryHash } from "@holochain/client";
import { Signal, SignalCb, EntryHash, SignalType } from "@holochain/client";
import { URL } from "node:url";
import test from "tape-promise/tape.js";
import { runLocalServices } from "../../src/common.js";
Expand Down Expand Up @@ -192,12 +192,18 @@ test("TryCP Scenario - receive signals with 2 conductors", async (t) => {
signalReceivedAlice,
signalReceivedBob,
]);

t.deepEqual(
actualSignalAlice.payload,
actualSignalAlice[SignalType.App].payload,
signalAlice,
"received alice's signal"
);
t.deepEqual(actualSignalBob.payload, signalBob, "received bob's signal");

t.deepEqual(
actualSignalBob[SignalType.App].payload,
signalBob,
"received bob's signal"
);

await scenario.cleanUp();
await tryCpServer.stop();
Expand Down

0 comments on commit 30cf7c9

Please sign in to comment.