diff --git a/CHANGELOG.md b/CHANGELOG.md index 09c9b3ec..5dce5416 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,21 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Changed ### Fixed +## [0.5.3] + +### Added +- Convenience function getter to call zome of a given cell. + +## [0.5.2] + +### Added +- Conductor options to runScenario fn. + +## [0.5.1] + +### Added +- Missing library files. + ## [0.5.0] - Re-write Tryorama @@ -19,8 +34,6 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Middleware - Conductor configuration - Implicit usage of `tape` as test harness -### Changed -### Fixed ## [0.4.10] ### Fixed diff --git a/README.md b/README.md index f4485d43..8079a8a4 100644 --- a/README.md +++ b/README.md @@ -219,6 +219,48 @@ const createEntryHash: EntryHash = await aliceHapps.cells[0].callZome({ await conductor.shutDown(); ``` +### Convenience function for Zome calls + +When testing a Zome, there are usually a lot of calls to the cell with this +particular Zome. Specifying the Cell and the Zome name for every call is +repetitive. It is therefore convenient to use a handle to a particular +combination of Cell and Zome. + +Instead of + +```typescript +const [aliceHapps] = await conductor.installAgentsHapps({ + agentsDnas: [dnas], +}); +const createEntryHash: EntryHash = await aliceHapps.cells[0].callZome({ + zome_name: "crud", + fn_name: "create", + payload: entryContent, +}); +const readEntryHash: string = await aliceHapps.cells[0].callZome({ + zome_name: "crud", + fn_name: "read", + payload: createEntryHash, +}); +``` + +the shorthand access to the Zome can be called + +```typescript +const [aliceHapps] = await conductor.installAgentsHapps({ + agentsDnas: [dnas], +}); +const aliceCrudZomeCall = getZomeCaller(aliceHapps.cells[0], "crud"); +const entryHeaderHash: HeaderHash = await crudZomeCall( + "create", + "test-entry" +); +const readEntryHash: string = await crudZomeCall( + "read", + entryHeaderHash +); +``` + ## Signals `Scenario.addPlayer` as well as `Conductor.installAgentsHapps` allow for an diff --git a/package-lock.json b/package-lock.json index 57a83d3a..a0a007c5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@holochain/tryorama", - "version": "0.5.0", + "version": "0.5.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@holochain/tryorama", - "version": "0.5.0", + "version": "0.5.3", "license": "CAL-1.0", "workspaces": [ "crates/trycp_server/test" @@ -24,7 +24,6 @@ "@microsoft/api-extractor": "^7.24.2", "@msgpack/msgpack": "^2.7.2", "@types/lodash": "^4.14.182", - "@types/node": "^16.11.36", "@types/ramda": "^0.26.44", "@types/tape": "^4.13.2", "@types/tape-promise": "^4.0.1", diff --git a/package.json b/package.json index 018efde5..f79229c0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@holochain/tryorama", "description": "Toolset to manage Holochain conductors and facilitate running test scenarios", - "version": "0.5.2", + "version": "0.5.3", "author": "Holochain Foundation", "keywords": [ "holochain", @@ -17,7 +17,7 @@ "license": "CAL-1.0", "type": "module", "engines": { - "node": "^14.13.1 || >=16.0.0" + "node": "^14.13.1 || >=16.0.0 || >=18.0.0" }, "workspaces": [ "crates/trycp_server/test" @@ -27,7 +27,7 @@ }, "types": "./lib/index.d.ts", "files": [ - "lib/" + "lib" ], "scripts": { "build": "rimraf ./lib && tsc -p tsconfig.build.json && npm run build:docs", @@ -57,7 +57,6 @@ "@microsoft/api-extractor": "^7.24.2", "@msgpack/msgpack": "^2.7.2", "@types/lodash": "^4.14.182", - "@types/node": "^16.11.36", "@types/ramda": "^0.26.44", "@types/tape": "^4.13.2", "@types/tape-promise": "^4.0.1", @@ -77,4 +76,4 @@ "ts-node": "^10.8.0", "typescript": "^4.7.2" } -} \ No newline at end of file +} diff --git a/ts/src/common.ts b/ts/src/common.ts index f13c39cb..690296f0 100644 --- a/ts/src/common.ts +++ b/ts/src/common.ts @@ -4,7 +4,12 @@ import { InstalledAppInfo, InstalledCell, } from "@holochain/client"; -import { AgentHapp, CellZomeCallRequest, IConductor } from "./types.js"; +import { + AgentHapp, + CallableCell, + CellZomeCallRequest, + IConductor, +} from "./types.js"; export const addAllAgentsToAllConductors = async (conductors: IConductor[]) => { await Promise.all( @@ -80,3 +85,12 @@ const getCallableCell = ( return callZomeResponse; }, }); + +export const getZomeCaller = + (cell: CallableCell, zomeName: string) => + (fnName: string, payload: unknown): Promise => + cell.callZome({ + zome_name: zomeName, + fn_name: fnName, + payload, + }); diff --git a/ts/src/local/conductor.ts b/ts/src/local/conductor.ts index 2187f892..b4c3e48e 100644 --- a/ts/src/local/conductor.ts +++ b/ts/src/local/conductor.ts @@ -391,7 +391,7 @@ export class Conductor implements IConductor { * * @param options - An array of DNAs for each agent, resulting in a * 2-dimensional array, and a UID for the DNAs (optional). - * @returns An array with each agent's hApp. + * @returns An array with each agent's hApps. */ async installAgentsHapps(options: { agentsDnas: DnaSource[][]; diff --git a/ts/test/local/conductor.ts b/ts/test/local/conductor.ts index 60951f85..26378d68 100644 --- a/ts/test/local/conductor.ts +++ b/ts/test/local/conductor.ts @@ -7,7 +7,10 @@ import { import { readFileSync } from "node:fs"; import test from "tape-promise/tape.js"; import { URL } from "node:url"; -import { addAllAgentsToAllConductors } from "../../src/common.js"; +import { + addAllAgentsToAllConductors, + getZomeCaller, +} from "../../src/common.js"; import { cleanAllConductors, createConductor, @@ -15,6 +18,7 @@ import { } from "../../src/index.js"; import { pause } from "../../src/util.js"; import { FIXTURE_DNA_URL, FIXTURE_HAPP_URL } from "../fixture/index.js"; +import { HeaderHash } from "@holochain/client"; test("Local Conductor - Spawn a conductor with QUIC network", async (t) => { const conductor = await createConductor({ @@ -199,6 +203,26 @@ test("Local Conductor - Install and call a hApp bundle", async (t) => { await cleanAllConductors(); }); +test("Local Conductor - Get a convenience function for zome calls", async (t) => { + const conductor = await createConductor(); + const [aliceHapps] = await conductor.installAgentsHapps({ + agentsDnas: [[{ path: FIXTURE_DNA_URL.pathname }]], + }); + const crudZomeCall = getZomeCaller(aliceHapps.cells[0], "crud"); + t.equal(typeof crudZomeCall, "function", "getZomeCaller returns a function"); + + const entryHeaderHash: HeaderHash = await crudZomeCall( + "create", + "test-entry" + ); + const entryHeaderHashB64 = Buffer.from(entryHeaderHash).toString("base64"); + t.equal(entryHeaderHash.length, 39, "HeaderHash is 39 bytes long"); + t.ok(entryHeaderHashB64.startsWith("hCkk"), "HeaderHash starts with hCkk"); + + await conductor.shutDown(); + await cleanAllConductors(); +}); + test("Local Conductor - Install multiple agents and DNAs and get access to agents and cells", async (t) => { const conductor = await createConductor(); const [aliceHapps, bobHapps] = await conductor.installAgentsHapps({