paritytech / paritytech/host-rust-core
Add an in-core mock host: MockPlatform + createMockHost
@decrypto21 is already working on this.
Since Jul 1, 2026.
- Dominant language
- Swift
- Stars
- 10
- Forks
- 3
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 148
Description
Context
A product holds no keys and only behaves in conversation with a host, so testing a product end-to-end needs both a host and a wallet/phone on the other end. The wallet is the hard part — manual, device-bound, not scriptable in CI — and standing up a real host per test is impractical. Tests need a host they can drive directly and deterministically, without a device.
Goal
Provide a faithful, in-core mock host: the same truapi-server core with a mock platform in the OS seam — "swap the seam, keep the core." Because the mock replaces only truapi-platform's capability seam (not the dispatcher, accounts, signing orchestration, permissions, statement store, or SSO), it is faithful by construction and cannot drift from a real host. It should be usable from both Rust (the native core) and JS (the real WASM core), and stay out of production builds.
Proposed shape
MockPlatform — Rust, in truapi-platform, behind a mock feature. A config-driven, in-memory implementation of all 11 capability traits, so it satisfies the blanket Platform:
let platform = MockPlatform::with_config(MockConfig {
device_permissions: PermissionPolicy::DenyAll,
chain: ChainBehavior::Scripted(frames),
faults: MockFaults { storage_error: Some("disk full".into()), ..Default::default() },
..Default::default()
});
Namespaced in-memory storage (product: / core:), per-capability permission policy, fault injection (MockFaults), configurable chain (ChainBehavior: Silent / Scripted / Closed / ConnectError), and recording oracles (navigations, notifications, confirmations, auth-state, sent RPC) for assertions.
createMockHost — JS, in @parity/truapi-host-wasm/web. The HostCallbacks sibling of MockPlatform, mocking the full generated host surface (kept complete by tsc), so the real WASM core runs against a mocked seam:
const mock = createMockHost();
const provider = await createWebWorkerProvider(
new HostWorker(), mock.callbacks, { runtimeConfig: mockRuntimeConfig() },
);
Scope
MockPlatformplus its config and oracle types intruapi-platform, behind amockfeature.- Through-core tests driving
MockPlatformviaTrUApiCore::from_platform_with_config+receive_from_product, proving requests flow through the real dispatcher and services (feature support, storage round-trip, permission-deny, preimage + confirm gate, and a fault surfacing as a wire error). createMockHost+mockRuntimeConfigin@parity/truapi-host-wasm/web.- A headless WASM-bridge test: the real WASM core invokes
createMockHost's callbacks across the JS↔SCALE↔WASM boundary (no browser, no worker). - CI coverage for the
truapi-host-wasmpackage (build the WASM, run the tests). - README docs for both crates.
Acceptance criteria
- The mock swaps only the platform seam; the real dispatcher and services run on top of it.
- Requests dispatch faithfully through the real core in tests, and the real WASM core drives the JS mock across the bridge.
- The
mockfeature is off by default and never enters the production WASM build.
Gating
Depends on #104 — the truapi-server, truapi-platform, and truapi-host-wasm crates exist only on that branch.
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.