Skip to content

Commit

Permalink
connection between host and guest... finally !
Browse files Browse the repository at this point in the history
  • Loading branch information
Soushi888 committed Mar 6, 2024
1 parent 4098bd0 commit fc3663f
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 74 deletions.
4 changes: 2 additions & 2 deletions dnas/requests_and_offers/zomes/coordinator/ping/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use hdk::prelude::*;

#[hdk_extern]
pub fn ping(_: ()) -> ExternResult<()> {
Ok(())
pub fn ping(_: ()) -> ExternResult<String> {
Ok("Pong".to_string())
}
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
38 changes: 19 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
3 changes: 0 additions & 3 deletions tests/src/requests_and_offers/ping/common.ts

This file was deleted.

31 changes: 5 additions & 26 deletions tests/src/requests_and_offers/ping/ping.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});
1 change: 1 addition & 0 deletions ui/.prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"useTabs": false,
"tabWidth": 2,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
Expand Down
12 changes: 4 additions & 8 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 ."
Expand Down
4 changes: 2 additions & 2 deletions ui/src/lib/services/client.service.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
7 changes: 3 additions & 4 deletions ui/src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
30 changes: 30 additions & 0 deletions ui/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
<script lang="ts">
import Navbar from '$lib/NavBar.svelte';
import { onMount, setContext } from 'svelte';
import '../app.postcss';
import { AppAgentWebsocket, type AppAgentClient } from '@holochain/client';
let client: AppAgentClient | undefined;
let loading = true;
export const clientContext = 'client';
onMount(async () => {
// We pass an unused string as the url because it will dynamically be replaced in launcher environments
client = await AppAgentWebsocket.connect('https://UNUSED', 'requests-and-offers');
loading = false;
console.log('client :', client);
const record = await client.callZome({
cap_secret: null,
zome_name: 'ping',
role_name: 'requests_and_offers',
fn_name: 'ping',
payload: null
});
console.log('record :', record);
});
setContext(clientContext, {
getClient: () => client
});
</script>

<Navbar />
Expand Down

0 comments on commit fc3663f

Please sign in to comment.