Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Default reviewer for all changes in this repository.
# See https://docs.github.com/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
* @mordamax
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Changelog

## 0.9.0

### Changed

- **Upstream `@novasamatech/*` → `^0.8.0`** ([triangle-js-sdks#179](https://github.com/paritytech/triangle-js-sdks/pull/179)). v0.8 is **wire-incompatible** with v0.7 — a test host built on this release will only talk to products on `@novasamatech/host-api@^0.8.0`. Upgrade your product side in lockstep. Most products don't need code changes if they use `createPapiProvider` for chain access and `@novasamatech/product-react-renderer` for custom chat. The product-side breaking points are documented in [the v0.8 migration guide](https://github.com/paritytech/triangle-js-sdks/blob/release/0.8/docs/migration/v0.8.md): theme subscription struct, `OptionBool` encoding fix (signing + custom renderer), and a handful of variant renames.

### Breaking changes

- **Theme subscription** delivers the new `{ name, variant }` struct instead of a flat `'light' | 'dark'`. `setTheme('light' | 'dark')` keeps working as a shorthand (mapped to `{ name: { tag: 'Default', value: undefined }, variant: 'Light' | 'Dark' }`) and now also accepts the full struct so tests can drive custom-named themes (e.g. `setTheme({ name: { tag: 'Custom', value: 'midnight' }, variant: 'Dark' })`). `getTheme()` returns the struct — read `theme.variant` for the previous light/dark value.
- **`AllocatableResource` variant rename**: `BulletInAllowance` → `BulletinAllowance`. Affects tests that hand-build resource-allocation requests.

### Added

- **`PaymentLogEntry.purse`** records the optional purse selector from RFC-0017 — `into` on top-ups, `from` on payment requests. Undefined means the product targeted the main purse.
- **`Theme` and `ThemeInput` types** exported from the package root so tests can type their theme assertions.

### Internal

- New integration coverage: default + custom-theme struct round-trip, and a purse-selector assertion on the payment log.
- Test product (`test/test-product.ts`) updated for the new theme payload shape and gained a `paymentSmokeWithPurse` helper.

## 0.8.6

### Fixed
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

Lightweight test host for E2E testing embedded Polkadot dapps that use the Spektr host-container protocol (`@novasamatech/host-container`).

> **Upstream contract:** `0.9.x` tracks `@novasamatech/host-api`, `host-container`, and `host-api-wrapper` at `^0.8.0`. v0.8 is wire-incompatible with v0.7 — your product side must be on the same major as the test host.

## Why

Products built with `@novasamatech/host-api-wrapper` (formerly `@novasamatech/product-sdk`) run inside an iframe and communicate with the host via `postMessage`. The SDK injects `window.injectedWeb3.spektr` only when it detects a real parent frame running `@novasamatech/host-container`.
Expand Down Expand Up @@ -268,6 +270,22 @@ createTestHostFixture({
>
> Unmapped identities fall back to production-style derivation (`//Bob//dotnsId/index`). If `accounts: []` (unsigned host), unmapped `getProductAccount` / `getProductAccountAlias` calls return `err(RequestCredentialsErr.NotConnected)`, matching `polkadot-desktop`. Pre-mapped entries in `productAccounts` are still served.

### Theme control

The host delivers `host_theme_subscribe` as a `{ name, variant }` struct (upstream v0.8). `setTheme('light' | 'dark')` is a shorthand that maps to `{ name: { tag: 'Default', value: undefined }, variant: 'Light' | 'Dark' }`; pass the full struct to exercise custom-named theme branches:

```ts
await testHost.setTheme('dark'); // shorthand → Default / Dark
await testHost.setTheme({
name: { tag: 'Custom', value: 'midnight' },
variant: 'Dark',
});

const theme = await testHost.getTheme();
// theme.variant: 'Light' | 'Dark'
// theme.name.tag: 'Default' | 'Custom'
```

### Built-in chains

| Chain | Export |
Expand Down
53 changes: 53 additions & 0 deletions forum-post.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,56 @@
# host-api-test-sdk 0.9.0

Tracks upstream `@novasamatech/*@^0.8.0` ([triangle-js-sdks#179](https://github.com/paritytech/triangle-js-sdks/pull/179)). v0.8 is **wire-incompatible** with v0.7 — there is no compatibility shim, so your product side must be on `@novasamatech/host-api@^0.8.0` too. The [v0.8 migration guide](https://github.com/paritytech/triangle-js-sdks/blob/release/0.8/docs/migration/v0.8.md) lists all the product-side touchpoints; most products that use `createPapiProvider` for chain access and `@novasamatech/product-react-renderer` for custom chat don't need code changes.

## What changed on our side

### Theme subscription is a struct now

The host now delivers a `Theme` struct on `host_theme_subscribe` instead of the flat `'light' | 'dark'` enum:

```ts
type Theme = {
name: { tag: 'Default'; value: undefined } | { tag: 'Custom'; value: string };
variant: 'Light' | 'Dark';
};
```

`setTheme('light' | 'dark')` keeps working as a shorthand — it maps to `{ name: { tag: 'Default', value: undefined }, variant: 'Light' | 'Dark' }`. New: you can pass the full struct to test product branches that read `theme.name`:

```ts
await testHost.setTheme({
name: { tag: 'Custom', value: 'midnight' },
variant: 'Dark',
});
```

`getTheme()` returns the struct — use `theme.variant` where you previously had `'light'/'dark'`.

### Payment log records the purse selector

Upstream v0.8 added an optional purse selector to `topUp` (`into`) and `requestPayment` (`from`) per RFC-0017. The test host now surfaces the selector on `PaymentLogEntry.purse`:

```ts
await testHost.getPaymentLog();
// → [{ type: 'top-up', amount: 1000n, purse: 7, ... },
// { type: 'request', amount: 500n, purse: 7, ... }]
```

Calls that omit the selector still target the main purse and the log entry's `purse` is `undefined`.

### Variant rename: `BulletInAllowance` → `BulletinAllowance`

If you hand-build resource-allocation requests in a test, rename the tag. Products going through the wrapper need no change.

## What you need to do

1. Upgrade to `0.9.0` and bump your product's `@novasamatech/host-api` (and related) to `^0.8.0` at the same time.
2. If you call `subscribeTheme(cb)` in your product or `getTheme()` in tests, switch to reading `theme.variant` (note the capitalization: `'Light' | 'Dark'`). Or branch on `theme.name.tag === 'Custom'` if you support custom themes.
3. Grep tests for `BulletInAllowance` and rename to `BulletinAllowance`.
4. Re-verify any custom signing flows (`withSignedTransaction`) and custom chat renderers — the upstream `OptionBool` encoding fix flips `true`/`false` against older peers. The test SDK rides through the upstream fix transparently; you should not need to change code, just re-run your suite.

---

# host-api-test-sdk 0.4.0

## Product account mapping
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@parity/host-api-test-sdk",
"version": "0.8.6",
"version": "0.9.0",
"description": "Lightweight test host for Spektr product E2E testing — embeds dapps with auto-signing dev accounts, no Docker needed",
"license": "MIT",
"repository": {
Expand Down Expand Up @@ -42,11 +42,11 @@
}
},
"dependencies": {
"@novasamatech/host-api": "^0.7.9"
"@novasamatech/host-api": "^0.8.0"
},
"devDependencies": {
"@novasamatech/host-api-wrapper": "^0.7.9",
"@novasamatech/host-container": "^0.7.9",
"@novasamatech/host-api-wrapper": "^0.8.0",
"@novasamatech/host-container": "^0.8.0",
"@polkadot/keyring": "^14.0.0",
"@polkadot/types": "^16.0.0",
"@polkadot/util": "^14.0.0",
Expand Down
72 changes: 36 additions & 36 deletions pnpm-lock.yaml

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

28 changes: 22 additions & 6 deletions src/browser/host-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ import type {
SigningLogEntry,
StatementSubmissionLogEntry,
TestHostAPI,
Theme,
ThemeInput,
} from "../types.js";

// ── Types ──────────────────────────────────────────────────────────
Expand Down Expand Up @@ -117,9 +119,21 @@ const paymentStatuses = new Map<string, { tag: string; value?: string }>();
const paymentStatusSubscribers = new Map<string, Set<(status: any) => void>>();
let paymentCounter = 0;
let nextNotificationId = 1;
let currentTheme: "light" | "dark" = "light";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const themeSubscribers = new Set<(theme: any) => void>();
let currentTheme: Theme = {
name: { tag: "Default", value: undefined },
variant: "Light",
};
const themeSubscribers = new Set<(theme: Theme) => void>();

function normalizeTheme(input: ThemeInput): Theme {
if (input === "light" || input === "dark") {
return {
name: { tag: "Default", value: undefined },
variant: input === "light" ? "Light" : "Dark",
};
}
return input;
}
let loginBehavior: LoginBehavior = "success";
let isAuthenticated = false;
let permissionBehavior: PermissionBehavior = "approve-all";
Expand Down Expand Up @@ -1092,6 +1106,7 @@ function setupContainer(
type: "top-up",
amount: params.amount,
source: params.source,
purse: params.into,
timestamp: Date.now(),
});
paymentBalance += params.amount;
Expand All @@ -1116,6 +1131,7 @@ function setupContainer(
amount: params.amount,
destination: params.destination,
paymentId,
purse: params.from,
timestamp: Date.now(),
});

Expand Down Expand Up @@ -1373,10 +1389,10 @@ async function init(): Promise<void> {
return currentTheme;
},

setTheme(theme: "light" | "dark") {
currentTheme = theme;
setTheme(theme: ThemeInput) {
currentTheme = normalizeTheme(theme);
for (const sub of themeSubscribers) {
sub(theme);
sub(currentTheme);
}
},

Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ export type {
SigningLogEntry,
TestHostAPI,
TestHostServer,
Theme,
ThemeInput,
} from './types.js';
Loading
Loading