From fc3663ff2787ede401590e93db50fd152423b83d Mon Sep 17 00:00:00 2001 From: Soushi888 Date: Wed, 6 Mar 2024 04:01:50 -0500 Subject: [PATCH] connection between host and guest... finally ! --- .../zomes/coordinator/ping/src/lib.rs | 4 +- package.json | 16 ++++---- pnpm-lock.yaml | 38 +++++++++---------- tests/package.json | 8 ++-- tests/src/requests_and_offers/ping/common.ts | 3 -- .../src/requests_and_offers/ping/ping.test.ts | 31 +++------------ ui/.prettierrc | 1 + ui/package.json | 12 ++---- ui/src/lib/services/client.service.ts | 4 +- ui/src/routes/+layout.server.ts | 7 ++-- ui/src/routes/+layout.svelte | 30 +++++++++++++++ 11 files changed, 80 insertions(+), 74 deletions(-) delete mode 100644 tests/src/requests_and_offers/ping/common.ts diff --git a/dnas/requests_and_offers/zomes/coordinator/ping/src/lib.rs b/dnas/requests_and_offers/zomes/coordinator/ping/src/lib.rs index e1a629f..98f958f 100644 --- a/dnas/requests_and_offers/zomes/coordinator/ping/src/lib.rs +++ b/dnas/requests_and_offers/zomes/coordinator/ping/src/lib.rs @@ -1,6 +1,6 @@ use hdk::prelude::*; #[hdk_extern] -pub fn ping(_: ()) -> ExternResult<()> { - Ok(()) +pub fn ping(_: ()) -> ExternResult { + Ok("Pong".to_string()) } diff --git a/package.json b/package.json index 457b49b..96bee71 100644 --- a/package.json +++ b/package.json @@ -6,13 +6,15 @@ "tests" ], "scripts": { - "start": "AGENTS=1 npm run network", - "network": "hc s clean && npm run build:happ && UI_PORT=5173 concurrently \"npm run dev -w ui\" \"npm run launch:tauri\" \"holochain-playground\"", - "test": "pnpm run test:zomes && pnpm run test:ui", - "test:zomes": "npm run build:zomes && hc app pack workdir --recursive && npm t -w tests", - "test:ui": "cd ui && npm test", - "launch:happ": "hc-spin -n $AGENTS --ui-port $UI_PORT workdir/requests-and-offers.happ network -b http://127.0.0.1:54000 webrtc ws://127.0.0.1:55000", - "launch:tauri": "echo \"pass\" | RUST_LOG=warn hc launch --piped -n $AGENTS workdir/requests-and-offers.happ --ui-port $UI_PORT network -b http://127.0.0.1:54000 webrtc ws://127.0.0.1:55000", + "start": "AGENTS=1 BOOTSTRAP_PORT=$(port) SIGNAL_PORT=$(port) npm run network", + "network": "hc s clean && npm run build:happ && UI_PORT=8888 concurrently \"npm start -w ui\" \"npm run launch:happ\" \"holochain-playground\"", + "test": "npm run build:zomes && hc app pack workdir --recursive && npm t -w tests", + "test:ping": "npm run build:zomes && hc app pack workdir --recursive && npm t --filter ping -w tests", + "test:profiles": "npm run build:zomes && hc app pack workdir --recursive && npm t --filter profiles -w tests", + "launch:happ": "hc-spin -n $AGENTS --ui-port $UI_PORT workdir/requests-and-offers.happ", + "start:tauri": "AGENTS=2 BOOTSTRAP_PORT=$(port) SIGNAL_PORT=$(port) npm run network:tauri", + "network:tauri": "hc s clean && npm run build:happ && UI_PORT=8888 concurrently \"npm start -w ui\" \"npm run launch:tauri\" \"holochain-playground\"", + "launch:tauri": "concurrently \"hc run-local-services --bootstrap-port $BOOTSTRAP_PORT --signal-port $SIGNAL_PORT\" \"echo pass | RUST_LOG=warn hc launch --piped -n $AGENTS workdir/requests-and-offers.happ --ui-port $UI_PORT network --bootstrap http://127.0.0.1:\"$BOOTSTRAP_PORT\" webrtc ws://127.0.0.1:\"$SIGNAL_PORT\"\"", "package": "npm run build:happ && npm run package -w ui && hc web-app pack workdir --recursive", "build:happ": "npm run build:zomes && hc app pack workdir --recursive", "build:zomes": "RUSTFLAGS='' CARGO_TARGET_DIR=target cargo build --release --target wasm32-unknown-unknown" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ad9481d..fc6542a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ devDependencies: specifier: ^0.1.1 version: 0.1.1 '@holochain/hc-spin': - specifier: ^0.100.1 - version: 0.100.5 + specifier: ^0.200.10 + version: 0.200.10 concurrently: specifier: ^6.2.1 version: 6.5.1 @@ -97,8 +97,8 @@ packages: - utf-8-validate dev: true - /@holochain/hc-spin-rust-utils-darwin-arm64@0.100.2: - resolution: {integrity: sha512-vyJj3dqqy7iLGMy+M7rTow6jBdIlYXJjqh1lk1Gc5a7qiSz7PIDxM+xYgtcXiovzDt4E0p8/8q+vRw7yxixdaQ==} + /@holochain/hc-spin-rust-utils-darwin-arm64@0.200.3: + resolution: {integrity: sha512-2MuCVRiZdekyr0scvcieUhzYsp+TGwtxMOLqHqrPKLoMagB39M8PygA/mf8XGjQWMNuyWUVDenYezFIYMNxiig==} engines: {node: '>= 10'} cpu: [arm64] os: [darwin] @@ -106,8 +106,8 @@ packages: dev: true optional: true - /@holochain/hc-spin-rust-utils-darwin-x64@0.100.2: - resolution: {integrity: sha512-UEaxgJrLzZbMbBsf/d3QYX58FPrGXjOFWev19fvtK5hJXFPXrSwO1IqmeCLUo7HWuTLNVOfP4rCP59kb3bGwgA==} + /@holochain/hc-spin-rust-utils-darwin-x64@0.200.3: + resolution: {integrity: sha512-upcfJMHf2QhyZ6uNoVoMuoWNcuRL1WmWgcbflEWZHEu7I0QJh5ZY/z3LXKviU3tgdUZxRGntXm27vTablD7iOg==} engines: {node: '>= 10'} cpu: [x64] os: [darwin] @@ -115,8 +115,8 @@ packages: dev: true optional: true - /@holochain/hc-spin-rust-utils-linux-x64-gnu@0.100.2: - resolution: {integrity: sha512-JT8XFQJ2ghgXLqejJLUcEY95ANuGkwy1aaq7NNntY529Pp01hI10zrDKOvIxC1MX7yZn7yaPc0sjzkJhtkocCQ==} + /@holochain/hc-spin-rust-utils-linux-x64-gnu@0.200.3: + resolution: {integrity: sha512-Amwyrx/oSlbk5khOkyHbQqGFe16yXKJCDMA4lDM3cVtRl60ClwiY2g1ywxWckOoPiXtgBAL4AI5Ba4bDaysfDA==} engines: {node: '>= 10'} cpu: [x64] os: [linux] @@ -124,8 +124,8 @@ packages: dev: true optional: true - /@holochain/hc-spin-rust-utils-win32-x64-msvc@0.100.2: - resolution: {integrity: sha512-ScFgsqV/Sf4bcDDPYSMQ511V6ID2aXRlcgh7NBxbX5KLX/CX/HANuZk5gcdhvK0MNkFW2lS81GrFh0iH93EASA==} + /@holochain/hc-spin-rust-utils-win32-x64-msvc@0.200.3: + resolution: {integrity: sha512-yGcZFqYdPk3NXSgVcC8L3+65jRJrZPOD5qm9mGfJKACz4u/z47Co69RDTt5ZhCFJBXZ8N2fotFLwmeBKd00aCg==} engines: {node: '>= 10'} cpu: [x64] os: [win32] @@ -133,24 +133,24 @@ packages: dev: true optional: true - /@holochain/hc-spin-rust-utils@0.100.2: - resolution: {integrity: sha512-KYljLQmH5rKGbigvBE92sEqNcD6b+ZIvsvhhd8enivaSYAPB97feGzWm3veUe50dLWdXskrzai1NlUIxQ+TCag==} + /@holochain/hc-spin-rust-utils@0.200.3: + resolution: {integrity: sha512-tOGsO7FXU2IjMvr44zdnsv48niE1A9UWzF5F9z3Su1g9K4gzhBCeKESUIGR8RyFHO1G7sfB43010uKGijcVYfA==} engines: {node: '>= 10'} optionalDependencies: - '@holochain/hc-spin-rust-utils-darwin-arm64': 0.100.2 - '@holochain/hc-spin-rust-utils-darwin-x64': 0.100.2 - '@holochain/hc-spin-rust-utils-linux-x64-gnu': 0.100.2 - '@holochain/hc-spin-rust-utils-win32-x64-msvc': 0.100.2 + '@holochain/hc-spin-rust-utils-darwin-arm64': 0.200.3 + '@holochain/hc-spin-rust-utils-darwin-x64': 0.200.3 + '@holochain/hc-spin-rust-utils-linux-x64-gnu': 0.200.3 + '@holochain/hc-spin-rust-utils-win32-x64-msvc': 0.200.3 dev: true - /@holochain/hc-spin@0.100.5: - resolution: {integrity: sha512-XJNUwgjMSNWe2c7tGH0mTJ5ETDMIfTDYsDycmRbQL0NQZUhaGY7nT27+tecjW0Y2hHDS5Qq3rmMUo3JKEviKNA==} + /@holochain/hc-spin@0.200.10: + resolution: {integrity: sha512-FmoSKP8S7dioF3KStv4zizg/M/Np9MH7DH2jSdJKEja0E+59+GpMWr1xD2KJbo497ZQYjvHr10GGJE+/1IrTgA==} hasBin: true dependencies: '@electron-toolkit/preload': 3.0.0(electron@28.2.2) '@electron-toolkit/utils': 3.0.0(electron@28.2.2) '@holochain/client': 0.16.9 - '@holochain/hc-spin-rust-utils': 0.100.2 + '@holochain/hc-spin-rust-utils': 0.200.3 '@msgpack/msgpack': 2.8.0 commander: 11.1.0 electron: 28.2.2 diff --git a/tests/package.json b/tests/package.json index 88d08e6..c7352e7 100644 --- a/tests/package.json +++ b/tests/package.json @@ -2,12 +2,14 @@ "name": "tests", "private": true, "scripts": { - "test": "vitest run" + "test": "vitest run", + "test:ping": "vitest run --filter ping", + "test:profiles": "vitest run --filter profiles" }, "dependencies": { "@msgpack/msgpack": "^2.7.0", - "@holochain/client": "^0.12.2", - "@holochain/tryorama": "^0.11.0", + "@holochain/client": "^0.16", + "@holochain/tryorama": "^0.15.3", "typescript": "^4.9.4", "vitest": "^0.28.4" }, diff --git a/tests/src/requests_and_offers/ping/common.ts b/tests/src/requests_and_offers/ping/common.ts deleted file mode 100644 index e1b8106..0000000 --- a/tests/src/requests_and_offers/ping/common.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { CallableCell } from '@holochain/tryorama'; -import { NewEntryAction, ActionHash, Record, AppBundleSource, fakeActionHash, fakeAgentPubKey, fakeEntryHash, fakeDnaHash } from '@holochain/client'; - diff --git a/tests/src/requests_and_offers/ping/ping.test.ts b/tests/src/requests_and_offers/ping/ping.test.ts index 1c19660..7f1e752 100644 --- a/tests/src/requests_and_offers/ping/ping.test.ts +++ b/tests/src/requests_and_offers/ping/ping.test.ts @@ -1,42 +1,21 @@ -import { assert, expect, test, vi } from "vitest"; +import { assert, expect, test } from "vitest"; -import { - runScenario, - pause, - CallableCell, - Scenario, - Player, -} from "@holochain/tryorama"; -import { - NewEntryAction, - ActionHash, - Record, - AppBundleSource, - fakeDnaHash, - fakeActionHash, - fakeAgentPubKey, - fakeEntryHash, -} from "@holochain/client"; -import { decode } from "@msgpack/msgpack"; +import { runScenario } from "@holochain/tryorama"; const hAppPath = process.cwd() + "/../workdir/requests-and-offers.happ"; const appSource = { appBundleSource: { path: hAppPath } }; -function decodeOutputs(records: Record[]): unknown[] { - return records.map((r) => decode((r.entry as any).Present.entry)); -} - -test("ping", async () => { +test.only("ping", async () => { await runScenario(async (scenario) => { const [alice] = await scenario.addPlayersWithApps([appSource]); await scenario.shareAllAgents(); - const record: Record = await alice.cells[0].callZome({ + const record: String = await alice.cells[0].callZome({ zome_name: "ping", fn_name: "ping", payload: null, }); - assert.notOk(record); + expect(record).toEqual("Pong"); }); }); diff --git a/ui/.prettierrc b/ui/.prettierrc index 18b6b64..90d8429 100644 --- a/ui/.prettierrc +++ b/ui/.prettierrc @@ -1,5 +1,6 @@ { "useTabs": false, + "tabWidth": 2, "singleQuote": true, "trailingComma": "none", "printWidth": 100, diff --git a/ui/package.json b/ui/package.json index 7a54efa..cebf027 100644 --- a/ui/package.json +++ b/ui/package.json @@ -3,14 +3,10 @@ "version": "0.0.1", "private": true, "scripts": { - "start": "vite dev", - "dev": "vite dev --clearScreen false --port $UI_PORT", - "build": "vite build", - "preview": "vite preview", - "start:browser": "VITE_HC_PORT=$HC_PORT VITE_HC_ADMIN_PORT=$HC_ADMIN_PORT vite", - "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", - "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", - "package": "npm run build && node zip.js", + "start": "vite dev --clearScreen false --port $UI_PORT", + "build": "npm run check && vite build", + "check": "svelte-check --tsconfig ./tsconfig.json", + "package": "npm run build && cd dist && bestzip ../dist.zip *", "test": "vitest", "lint": "prettier --check . && eslint .", "format": "prettier --write ." diff --git a/ui/src/lib/services/client.service.ts b/ui/src/lib/services/client.service.ts index 508826a..b4f7e90 100644 --- a/ui/src/lib/services/client.service.ts +++ b/ui/src/lib/services/client.service.ts @@ -1,8 +1,8 @@ -import { AppAgentWebsocket } from '@holochain/client'; +import { AppAgentWebsocket, type AppAgentClient } from '@holochain/client'; export default class HolochainClientService { private static instance: HolochainClientService; - client: AppAgentWebsocket | null = null; + client: AppAgentClient | null = null; private readonly HOLOCHAIN_APP_ID = 'requests-and-offers'; private readonly IS_LAUNCHER = import.meta.env.VITE_IS_LAUNCHER; diff --git a/ui/src/routes/+layout.server.ts b/ui/src/routes/+layout.server.ts index b428806..ed284e3 100644 --- a/ui/src/routes/+layout.server.ts +++ b/ui/src/routes/+layout.server.ts @@ -2,8 +2,7 @@ import HolochainClientService from '@services/client.service'; import type { LayoutServerLoad } from './$types'; export const load: LayoutServerLoad = async () => { - console.log('layout server load'); - const holochainClientService = await HolochainClientService.getInstance(); - - console.log(holochainClientService.client); + // console.log('layout server load'); + // const holochainClientService = await HolochainClientService.getInstance(); + // console.log(holochainClientService.client); }; diff --git a/ui/src/routes/+layout.svelte b/ui/src/routes/+layout.svelte index d18b1d2..8a6e5ac 100644 --- a/ui/src/routes/+layout.svelte +++ b/ui/src/routes/+layout.svelte @@ -1,6 +1,36 @@