Skip to content

Commit

Permalink
fix: adapt tests to changes in client
Browse files Browse the repository at this point in the history
  • Loading branch information
jost-s committed Feb 28, 2024
1 parent 975caf2 commit 3fbc8ec
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
22 changes: 12 additions & 10 deletions ts/src/local/conductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ export class Conductor implements IConductor {
}

private async connectAdminWs() {
this._adminWs = await AdminWebsocket.connect(
this.adminApiUrl,
this.timeout
);
this._adminWs = await AdminWebsocket.connect({
url: this.adminApiUrl,
defaultTimeout: this.timeout,
});
logger.debug(`connected to Admin API @ ${this.adminApiUrl.href}\n`);
}

Expand Down Expand Up @@ -307,7 +307,10 @@ export class Conductor implements IConductor {
logger.debug(`connecting App WebSocket to port ${port}\n`);
const appApiUrl = new URL(this.adminApiUrl.href);
appApiUrl.port = port.toString();
const appWs = await AppWebsocket.connect(appApiUrl, this.timeout);
const appWs = await AppWebsocket.connect({
url: appApiUrl,
defaultTimeout: this.timeout,
});

// set up automatic zome call signing
const callZome = appWs.callZome;
Expand Down Expand Up @@ -335,11 +338,10 @@ export class Conductor implements IConductor {
logger.debug(`connecting App Agent WebSocket to port ${port}\n`);
const appApiUrl = new URL(HOST_URL.href);
appApiUrl.port = port.toString();
const appAgentWs = await AppAgentWebsocket.connect(
appApiUrl,
appId,
this.timeout
);
const appAgentWs = await AppAgentWebsocket.connect(appId, {
url: appApiUrl,
defaultTimeout: this.timeout,
});

// set up automatic zome call signing
const callZome = appAgentWs.callZome.bind(appAgentWs);
Expand Down
14 changes: 13 additions & 1 deletion ts/src/trycp/conductor/conductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
GrantedFunctions,
GrantedFunctionsType,
GrantZomeCallCapabilityRequest,
HolochainError,
InstallAppRequest,
InstalledAppId,
ListAppsRequest,
Expand Down Expand Up @@ -959,12 +960,24 @@ export class TryCpConductor implements IConductor {
const appInfo = appWs.appInfo.bind(appWs);
appWs.appInfo = async () => {
const currentAppInfo = await appInfo({ installed_app_id: appId });
if (!currentAppInfo) {
throw new HolochainError(
"AppNotFound",
`App info not found for the provided id "${appId}". App needs to be installed and enabled.`
);
}
cachedAppInfo = currentAppInfo;
return currentAppInfo;
};

const callZome = appWs.callZome.bind(appWs);
appWs.callZome = async (request: AppAgentCallZomeRequest) => {
if (!cachedAppInfo) {
throw new HolochainError(
"AppNotFound",
`App info not found for the provided id "${appId}". App needs to be installed and enabled.`
);
}
if ("role_name" in request && request.role_name) {
const cell_id = this.getCellIdFromRoleName(
request.role_name,
Expand All @@ -973,7 +986,6 @@ export class TryCpConductor implements IConductor {

const zomeCallPayload = {
...request,
// ...omit(request, "role_name"),
provenance: cachedAppInfo.agent_pub_key,
cell_id,
};
Expand Down
2 changes: 1 addition & 1 deletion ts/test/fixture/zomes/integrity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct UpdateInput {
pub content: String,
}

#[hdk_entry_defs]
#[hdk_entry_types]
#[unit_enum(EntryTypesUnit)]
pub enum EntryTypes {
Content(Content),
Expand Down
1 change: 1 addition & 0 deletions ts/test/local/conductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ test("Local Conductor - get app info with app ws", async (t) => {
const appInfo = await appWs.appInfo({
installed_app_id: app.installed_app_id,
});
assert(appInfo);
t.deepEqual(appInfo.status, { running: null });
await conductor.shutDown();
await stopLocalServices(servicesProcess);
Expand Down
4 changes: 3 additions & 1 deletion ts/test/trycp/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import assert from "node:assert/strict";
import { Buffer } from "node:buffer";
import { URL } from "node:url";
import test from "tape-promise/tape.js";
import { enableAndGetAgentApp } from "../../src/common.js";
import {
createTryCpConductor,
DEFAULT_PARTIAL_PLAYER_CONFIG,
Expand All @@ -13,7 +15,6 @@ import {
} from "../../src/trycp/trycp-server.js";
import { TRYCP_SUCCESS_RESPONSE } from "../../src/trycp/types.js";
import { FIXTURE_DNA_URL, FIXTURE_HAPP_URL } from "../fixture/index.js";
import { enableAndGetAgentApp } from "../../src/common.js";

const SERVER_URL = new URL(`ws://${TRYCP_SERVER_HOST}:${TRYCP_SERVER_PORT}`);
const createTryCpClient = () => TryCpClient.create(SERVER_URL);
Expand Down Expand Up @@ -287,6 +288,7 @@ test("TryCP Server - App API - get app info", async (t) => {
const alice = await enableAndGetAgentApp(adminWs, appWs, aliceApp);

const appInfo = await appWs.appInfo({ installed_app_id: alice.appId });
assert(appInfo);
t.deepEqual(appInfo.status, { running: null });

await conductor.disconnectAppInterface(port);
Expand Down

0 comments on commit 3fbc8ec

Please sign in to comment.