Skip to content

Commit

Permalink
Restore zome call by role name instead of cell id
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Apr 29, 2024
1 parent f6b5b3c commit ef15f4a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
20 changes: 14 additions & 6 deletions ts/src/local/conductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getSigningCredentials,
InstallAppRequest,
AppAuthenticationToken,
AppCallZomeRequest,
} from "@holochain/client";
import getPort, { portNumbers } from "get-port";
import pick from "lodash/pick.js";
Expand Down Expand Up @@ -317,12 +318,19 @@ export class Conductor implements IConductor {

// set up automatic zome call signing
const callZome = appWs.callZome.bind(appWs);
appWs.callZome = async (
req: CallZomeRequest | CallZomeRequestSigned,
timeout?: number
) => {
if (!getSigningCredentials(req.cell_id)) {
await this.adminWs().authorizeSigningCredentials(req.cell_id);
appWs.callZome = async (req: AppCallZomeRequest, timeout?: number) => {
let cellId;
if ("role_name" in req) {
assert(appWs.cachedAppInfo);
cellId = appWs.getCellIdFromRoleName(
req.role_name,
appWs.cachedAppInfo
);
} else {
cellId = req.cell_id;
}
if (!getSigningCredentials(cellId)) {
await this.adminWs().authorizeSigningCredentials(cellId);
}
return callZome(req, timeout);
};
Expand Down
18 changes: 18 additions & 0 deletions ts/test/local/scenario.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ActionHash,
AppBundleSource,
AppSignal,
AppSignalCb,
Expand Down Expand Up @@ -278,3 +279,20 @@ test("Local Scenario - pauseUntilDhtEqual - Create multiple entries, read the la

await scenario.cleanUp();
});

test("Local Scenario - runScenario - call zome by role name", async (t) => {
await runScenario(async (scenario: Scenario) => {
const alice = await scenario.addPlayerWithApp({
path: FIXTURE_HAPP_URL.pathname,
});

const result = (await alice.appWs.callZome({
role_name: "test",
zome_name: "coordinator",
fn_name: "create",
payload: "hello",
})) as ActionHash;

t.ok(result);
});
});

0 comments on commit ef15f4a

Please sign in to comment.