Skip to content

Commit

Permalink
fix types and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JettTech committed Aug 26, 2024
1 parent e280c8e commit 9cc3f8f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
12 changes: 5 additions & 7 deletions ts/src/local/conductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,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
18 changes: 11 additions & 7 deletions ts/src/trycp/util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Signal, SignalType } from "@holochain/client";
import { AppSignal, RawSignal, EncodedAppSignal, Signal, SignalType } from "@holochain/client";
import msgpack from "@msgpack/msgpack";
import assert from "node:assert";
import { TryCpApiResponse, _TryCpResponseWrapper } from "./types.js";
import { inspect } from "util";

/**
* Deserialize the binary response from TryCP
Expand All @@ -24,14 +25,17 @@ export const deserializeTryCpResponse = (response: Uint8Array) => {
* @returns The deserialized signal.
*/
export const deserializeTryCpSignal = (signal: Uint8Array) => {
const deserializedSignal = msgpack.decode(signal);
const deserializedSignal = msgpack.decode(signal) as RawSignal;
assertIsSignal(deserializedSignal);
if (SignalType.App in deserializedSignal) {
const {
[SignalType.App]: { cell_id, payload: decodedPayload, zome_name },
} = deserializedSignal;
let app_payload = { cell_id, payload: decodedPayload, zome_name };
return { App: app_payload } as Signal
const { cell_id, signal, zome_name } = deserializedSignal[SignalType.App] as EncodedAppSignal;
const decodedPayload = msgpack.decode(signal);
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
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
8 changes: 5 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,14 @@ 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 9cc3f8f

Please sign in to comment.