paritytech / paritytech/host-rust-core
Browser E2E harness for the mock host + `createMockClient`
@decrypto21 is already working on this.
Since Jul 3, 2026.
- Dominant language
- Swift
- Stars
- 10
- Forks
- 3
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 148
Description
Context
#257 (delivered by PR #258) added the in-core mock host: MockPlatform (Rust) and createMockHost (JS), proven through the real dispatcher and a headless wasm-bridge.test.ts that drives the real WASM core across the JS↔SCALE↔WASM boundary. By design that test uses no real Web Worker, no iframe, and no product transport — so the highest-fidelity path is still unproven: a real product, in a real browser, talking to the real core over the production transport. Adopting the mock in a product test is also more setup than it should be (createMockHost + provider + createClient by hand).
Goal
Prove the mock host end to end in a real browser — the real truapi-server WASM core in a Web Worker, a product in an iframe connecting via the SDK's real getClientSync() sandbox path over a real MessageChannel, driven headless by Playwright — and make "switch a product to mock mode" a one-liner so product tests adopt it trivially.
Proposed shape
@parity/truapi-mock-e2e — a private (unpublished) workspace package holding the browser harness. Two topologies:
- single-page (
src/main.tsx): host + product in one page, wired with a singlecreateMockClient()call; - iframe (
src/host.tsx+src/product.tsx): mirrors production embedding — the host boots the core +createIframeHost; the product runs in an iframe with no mock code, connecting throughgetClientSync().
Dependencies resolve through the npm workspace (no machine-specific paths), so it runs anywhere the repo does.
createMockClient — a @parity/truapi-host-wasm/testing subpath export that collapses createMockHost + createWebWorkerProvider + createClient into one call, returning the product client plus the mock for assertions:
import HostWorker from "@parity/truapi-host-wasm/worker-runtime?worker";
import { createMockClient } from "@parity/truapi-host-wasm/testing";
const { client, mock } = await createMockClient(new HostWorker(), { devicePermissions: "allow-all" });
await client.system.handshake();
// ... drive the product client; assert via mock.navigations(), etc.
Scope
@parity/truapi-mock-e2epackage: Vite + React harness (single-page + iframe topologies), portable workspacefile:deps.createMockClient(+MockClienttype) exported from@parity/truapi-host-wasm/testing.- Playwright suite: (1) product-in-iframe round-trip through the real core; (2) a single-page test that executes
createMockClientat runtime. Assert on both product results and the mock's recorded oracles (e.g.navigations()). - A
mock-e2eCI job: build the WASM + workspace packages, install Chromium, run Playwright. Runs for signal; not a requiredci-statusgate until it has a green baseline in CI. - README docs for the new package and the
/testingexport.
Acceptance criteria
- The suite passes headlessly with a real
Web Workerand realiframe(not a stubbed transport). - The product reaches the core only through the SDK's real
getClientSync()sandbox path; the product contains no mock code. createMockClienthas executing runtime coverage, not just typecheck.- No dependency on a device or a live chain; the run is deterministic and repeatable.
- The harness is dev-only / private and never enters a production build.
Gating
Stacked on #257 / PR #258 (createMockHost, the providers, and the /testing export live there)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.