Skip to content

Commit

Permalink
make compatibile with signal changes and pubkey as optional
Browse files Browse the repository at this point in the history
  • Loading branch information
JettTech committed Aug 26, 2024
1 parent a029a06 commit e280c8e
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 49 deletions.
2 changes: 1 addition & 1 deletion docs/tryorama.appoptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ _(Optional)_ A network seed to override the hApps' network seed.

</td><td>

AppSignalCb
SignalCb


</td><td>
Expand Down
2 changes: 1 addition & 1 deletion docs/tryorama.appoptions.signalhandler.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ A signal handler for the conductor.
**Signature:**

```typescript
signalHandler?: AppSignalCb;
signalHandler?: SignalCb;
```
2 changes: 1 addition & 1 deletion docs/tryorama.clientsplayersoptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ _(Optional)_ Configuration for the conductor (optional).

</td><td>

AppSignalCb
SignalCb


</td><td>
Expand Down
2 changes: 1 addition & 1 deletion docs/tryorama.clientsplayersoptions.signalhandler.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ A signal handler to be registered in conductors.
**Signature:**

```typescript
signalHandler?: AppSignalCb;
signalHandler?: SignalCb;
```
4 changes: 2 additions & 2 deletions docs/tryorama.getcallablecell.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ getCallableCell: (appWs: IAppWebsocket, cell: ClonedCell | ProvisionedCell) => {
callZome: <T>(request: CellZomeCallRequest, timeout?: number) => Promise<T>;
cell_id: import("@holochain/client").CellId;
clone_id: string;
original_dna_hash: import("@spartan-hc/holo-hash").DnaHash;
original_dna_hash: Uint8Array;
dna_modifiers: import("@holochain/client").DnaModifiers;
name: string;
enabled: boolean;
Expand Down Expand Up @@ -78,7 +78,7 @@ Cell to bind zome call function to.
</tbody></table>
**Returns:**

{ callZome: &lt;T&gt;(request: [CellZomeCallRequest](./tryorama.cellzomecallrequest.md)<!-- -->, timeout?: number) =&gt; Promise&lt;T&gt;; cell\_id: import("@holochain/client").CellId; clone\_id: string; original\_dna\_hash: import("@spartan-hc/holo-hash").DnaHash; dna\_modifiers: import("@holochain/client").DnaModifiers; name: string; enabled: boolean; } \| { callZome: &lt;T&gt;(request: [CellZomeCallRequest](./tryorama.cellzomecallrequest.md)<!-- -->, timeout?: number) =&gt; Promise&lt;T&gt;; cell\_id: import("@holochain/client").CellId; dna\_modifiers: import("@holochain/client").DnaModifiers; name: string; }
{ callZome: &lt;T&gt;(request: [CellZomeCallRequest](./tryorama.cellzomecallrequest.md)<!-- -->, timeout?: number) =&gt; Promise&lt;T&gt;; cell\_id: import("@holochain/client").CellId; clone\_id: string; original\_dna\_hash: Uint8Array; dna\_modifiers: import("@holochain/client").DnaModifiers; name: string; enabled: boolean; } \| { callZome: &lt;T&gt;(request: [CellZomeCallRequest](./tryorama.cellzomecallrequest.md)<!-- -->, timeout?: number) =&gt; Promise&lt;T&gt;; cell\_id: import("@holochain/client").CellId; dna\_modifiers: import("@holochain/client").DnaModifiers; name: string; }

A callable cell.

4 changes: 2 additions & 2 deletions docs/tryorama.trycpclient.setsignalhandler.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
**Signature:**

```typescript
setSignalHandler(port: number, signalHandler?: AppSignalCb): void;
setSignalHandler(port: number, signalHandler?: SignalCb): void;
```

## Parameters
Expand Down Expand Up @@ -49,7 +49,7 @@ signalHandler

</td><td>

AppSignalCb
SignalCb


</td><td>
Expand Down
4 changes: 2 additions & 2 deletions docs/tryorama.trycpconductor.on.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Attach a signal handler.
**Signature:**

```typescript
on(port: number, signalHandler: AppSignalCb): void;
on(port: number, signalHandler: SignalCb): void;
```

## Parameters
Expand Down Expand Up @@ -53,7 +53,7 @@ signalHandler

</td><td>

AppSignalCb
SignalCb


</td><td>
Expand Down
12 changes: 7 additions & 5 deletions ts/src/local/conductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,13 @@ export class Conductor implements IConductor {
installed_app_id,
network_seed,
};
logger.debug(
`installing app with id ${installed_app_id} for agent ${encodeHashToBase64(
agent_key
)}`
);
if (!!agent_key) {
logger.debug(
`installing app with id ${installed_app_id} for agent ${encodeHashToBase64(
agent_key
)}`
);
}
return this.adminWs().installApp(installAppRequest);
}

Expand Down
4 changes: 2 additions & 2 deletions ts/src/trycp/conductor/conductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
AgentPubKey,
AppAuthenticationToken,
AppBundleSource,
AppSignalCb,
SignalCb,
AttachAppInterfaceRequest,
CallZomeRequest,
CallZomeRequestSigned,
Expand Down Expand Up @@ -332,7 +332,7 @@ export class TryCpConductor implements IConductor {
* @param signalHandler - The signal handler to register.
* @param port - The port of the app interface.
*/
on(port: number, signalHandler: AppSignalCb) {
on(port: number, signalHandler: SignalCb) {
this.tryCpClient.setSignalHandler(port, signalHandler);
}

Expand Down
4 changes: 2 additions & 2 deletions ts/src/trycp/conductor/scenario.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AgentPubKey, AppBundleSource, AppSignalCb } from "@holochain/client";
import { AgentPubKey, AppBundleSource, SignalCb } from "@holochain/client";
import { ChildProcessWithoutNullStreams } from "node:child_process";
import { URL } from "url";
import { v4 as uuidv4 } from "uuid";
Expand Down Expand Up @@ -49,7 +49,7 @@ export interface ClientsPlayersOptions {
/**
* A signal handler to be registered in conductors.
*/
signalHandler?: AppSignalCb;
signalHandler?: SignalCb;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions ts/src/trycp/trycp-client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppSignalCb, CallZomeRequestSigned } from "@holochain/client";
import { SignalCb, AppSignal, CallZomeRequestSigned } from "@holochain/client";
import msgpack from "@msgpack/msgpack";
import cloneDeep from "lodash/cloneDeep.js";
import assert from "node:assert";
Expand Down Expand Up @@ -46,7 +46,7 @@ export class TryCpClient {
responseReject: (reason: TryCpResponseErrorValue) => void;
};
};
private signalHandlers: Record<number, AppSignalCb | undefined>;
private signalHandlers: Record<number, SignalCb | undefined>;

// can be set in local test cases
bootstrapServerUrl: URL | undefined;
Expand Down Expand Up @@ -143,7 +143,7 @@ export class TryCpClient {
return connectPromise;
}

setSignalHandler(port: number, signalHandler?: AppSignalCb) {
setSignalHandler(port: number, signalHandler?: SignalCb) {
this.signalHandlers[port] = signalHandler;
}

Expand Down
8 changes: 4 additions & 4 deletions ts/src/trycp/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ export const deserializeTryCpResponse = (response: Uint8Array) => {
* @param signal - The signal to deserialize.
* @returns The deserialized signal.
*/
export const deserializeTryCpSignal = <T>(signal: Uint8Array) => {
export const deserializeTryCpSignal = (signal: Uint8Array) => {
const deserializedSignal = msgpack.decode(signal);
assertIsSignal(deserializedSignal);
if (SignalType.App in deserializedSignal) {
const {
[SignalType.App]: { cell_id, signal: payload, zome_name },
[SignalType.App]: { cell_id, payload: decodedPayload, zome_name },
} = deserializedSignal;
const decodedPayload = msgpack.decode(payload) as T;
return { cell_id, payload: decodedPayload, zome_name };
let app_payload = { cell_id, payload: decodedPayload, zome_name };
return { App: app_payload } as Signal
} else {
throw new Error("Receiving system signals is not implemented yet");
}
Expand Down
4 changes: 2 additions & 2 deletions ts/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
AppAuthenticationToken,
AppBundleSource,
AppInfo,
AppSignalCb,
SignalCb,
AppWebsocket,
CallZomeRequest,
CellId,
Expand Down Expand Up @@ -151,7 +151,7 @@ export interface AppOptions {
/**
* A signal handler for the conductor.
*/
signalHandler?: AppSignalCb;
signalHandler?: SignalCb;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions ts/test/local/conductor.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
ActionHash,
AppBundleSource,
AppSignal,
AppSignalCb,
Signal,
SignalCb,
CellProvisioningStrategy,
CloneId,
EntryHash,
Signal,
AppSignal,
SignalType,
} from "@holochain/client";
import assert from "node:assert";
Expand Down Expand Up @@ -616,8 +616,8 @@ test("Local Conductor - create and read an entry, 2 conductors, 2 cells, 2 agent

test("Local Conductor - Receive a signal", async (t) => {
const { servicesProcess, signalingServerUrl } = await runLocalServices();
let signalHandler: AppSignalCb | undefined;
const signalReceived = new Promise<AppSignal>((resolve) => {
let signalHandler: SignalCb | undefined;
const signalReceived = new Promise<Signal>((resolve) => {
signalHandler = (signal: Signal) => {
assert(SignalType.App in signal);
resolve(signal[SignalType.App]);
Expand Down
18 changes: 9 additions & 9 deletions ts/test/local/scenario.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
ActionHash,
AppBundleSource,
AppSignal,
AppSignalCb,
Signal,
SignalCb,
AppWebsocket,
EntryHash,
Signal,
AppSignal,
SignalType,
} from "@holochain/client";
import assert from "node:assert/strict";
Expand Down Expand Up @@ -66,8 +66,8 @@ test("Local Scenario - runScenario - Catch error when calling a zome of an undef

test("Local Scenario - runScenario - Catch error that occurs in a signal handler", async (t) => {
await runScenario(async (scenario: Scenario) => {
let signalHandlerAlice: AppSignalCb | undefined;
const signalReceivedAlice = new Promise<AppSignal>((_, reject) => {
let signalHandlerAlice: SignalCb | undefined;
const signalReceivedAlice = new Promise<Signal>((_, reject) => {
signalHandlerAlice = () => {
reject();
};
Expand Down Expand Up @@ -201,16 +201,16 @@ test("Local Scenario - Conductor maintains data after shutdown and restart", asy
test("Local Scenario - Receive signals with 2 conductors", async (t) => {
const scenario = new Scenario();

let signalHandlerAlice: AppSignalCb | undefined;
const signalReceivedAlice = new Promise<AppSignal>((resolve) => {
let signalHandlerAlice: SignalCb | undefined;
const signalReceivedAlice = new Promise<Signal>((resolve) => {
signalHandlerAlice = (signal: Signal) => {
assert(SignalType.App in signal);
resolve(signal[SignalType.App]);
};
});

let signalHandlerBob: AppSignalCb | undefined;
const signalReceivedBob = new Promise<AppSignal>((resolve) => {
let signalHandlerBob: SignalCb | undefined;
const signalReceivedBob = new Promise<Signal>((resolve) => {
signalHandlerBob = (signal: Signal) => {
assert(SignalType.App in signal);
resolve(signal[SignalType.App]);
Expand Down
5 changes: 3 additions & 2 deletions ts/test/trycp/conductor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
ActionHash,
AppBundleSource,
Signal,
AppSignal,
CellProvisioningStrategy,
CellType,
Expand Down Expand Up @@ -395,8 +396,8 @@ test("TryCP Conductor - receive a signal", async (t) => {
const testSignal = { value: "signal" };

let signalHandler;
const signalReceived = new Promise<AppSignal>((resolve) => {
signalHandler = (signal: AppSignal) => {
const signalReceived = new Promise<Signal>((resolve) => {
signalHandler = (signal: Signal) => {
resolve(signal);
};
});
Expand Down
10 changes: 5 additions & 5 deletions ts/test/trycp/scenario.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppSignal, AppSignalCb, EntryHash } from "@holochain/client";
import { Signal, SignalCb, EntryHash } 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 @@ -152,14 +152,14 @@ test("TryCP Scenario - receive signals with 2 conductors", async (t) => {
} = await runLocalServices());
const client = await scenario.addClient(SERVER_URL);

let signalHandlerAlice: AppSignalCb | undefined;
const signalReceivedAlice = new Promise<AppSignal>((resolve) => {
let signalHandlerAlice: SignalCb | undefined;
const signalReceivedAlice = new Promise<Signal>((resolve) => {
signalHandlerAlice = (signal) => {
resolve(signal);
};
});
let signalHandlerBob: AppSignalCb | undefined;
const signalReceivedBob = new Promise<AppSignal>((resolve) => {
let signalHandlerBob: SignalCb | undefined;
const signalReceivedBob = new Promise<Signal>((resolve) => {
signalHandlerBob = (signal) => {
resolve(signal);
};
Expand Down

0 comments on commit e280c8e

Please sign in to comment.