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
26 changes: 26 additions & 0 deletions .github/workflows/check-spec-drift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: check_spec_drift

on:
schedule:
# Every Sunday at 09:00 UTC
- cron: '0 9 * * 0'
workflow_dispatch:
workflow_call:
pull_request:

env:
# The dfinity/portal commit that pic-js is currently aligned with.
# Update this after syncing management-canister.ts with a newer spec.
# 2026/03/10: allow PUT/DELETE in http calls
IC_SPEC_PINNED_COMMIT: '415b6182079cabf7926231af12405032fdc62319'

jobs:
check_spec_drift:
name: check_spec_drift
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Check for spec drift
run: bash scripts/check-spec-drift.sh "$IC_SPEC_PINNED_COMMIT"
5 changes: 5 additions & 0 deletions .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ on:
type: boolean

jobs:
check_spec_drift:
name: check_spec_drift
uses: ./.github/workflows/check-spec-drift.yml

create_release_pr:
name: create_release_pr
needs: check_spec_drift
runs-on: ubuntu-latest
environment: release
permissions:
Expand Down
88 changes: 69 additions & 19 deletions bun.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@
"postinstall": "tar -xvf examples/nns_proxy/tests/state/nns_state.tar.xz -C examples/nns_proxy/tests/state"
},
"devDependencies": {
"@icp-sdk/bindgen": "^0.2.2",
"@icp-sdk/bindgen": "^0.2.3",
"@icp-sdk/core": "^5.0.0",
"@swc/core": "^1.15.18",
"@swc/jest": "^0.2.39",
"@tsconfig/node24": "^24.0.4",
"@types/jest": "^30.0.0",
"@types/node": "^25.4.0",
"@types/node": "^25.5.0",
"bip39": "^3.1.0",
"jest": "^30.3.0",
"npm-run-all": "^4.1.5",
"prettier": "3.8.1",
"ts-node": "^10.9.2",
"typescript": "^5.9.3",
"vitest": "^4.0.18"
"vitest": "^4.1.0"
}
}
15 changes: 15 additions & 0 deletions packages/pic/src/management-canister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,26 @@ export type LogVisibility =
| { public: null }
| { allowed_viewers: Principal[] };

const SnapshotVisibility = IDL.Variant({
controllers: IDL.Null,
public: IDL.Null,
allowed_viewers: IDL.Vec(IDL.Principal),
});

export type SnapshotVisibility =
| { controllers: null }
| { public: null }
| { allowed_viewers: Principal[] };

export interface CanisterSettings {
controllers: [] | [Principal[]];
compute_allocation: [] | [bigint];
memory_allocation: [] | [bigint];
freezing_threshold: [] | [bigint];
reserved_cycles_limit: [] | [bigint];
log_visibility: [] | [LogVisibility];
snapshot_visibility: [] | [SnapshotVisibility];
log_memory_limit: [] | [bigint];
wasm_memory_limit: [] | [bigint];
wasm_memory_threshold: [] | [bigint];
environment_variables: [] | [EnvironmentVariable[]];
Expand All @@ -44,6 +57,8 @@ export const CanisterSettings = IDL.Record({
freezing_threshold: IDL.Opt(IDL.Nat),
reserved_cycles_limit: IDL.Opt(IDL.Nat),
log_visibility: IDL.Opt(LogVisibility),
snapshot_visibility: IDL.Opt(SnapshotVisibility),
log_memory_limit: IDL.Opt(IDL.Nat),
wasm_memory_limit: IDL.Opt(IDL.Nat),
wasm_memory_threshold: IDL.Opt(IDL.Nat),
environment_variables: IDL.Opt(IDL.Vec(EnvironmentVariable)),
Expand Down
25 changes: 24 additions & 1 deletion packages/pic/src/pocket-ic-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,17 @@ export type LogVisibility =
| { public: null }
| { allowedViewers: Principal[] };

/**
* Snapshot visibility for canister settings.
*
* @category Types
* @see [Principal](https://js.icp.build/core/latest/libs/principal/api/classes/principal/)
*/
export type SnapshotVisibility =
| { controllers: null }
| { public: null }
| { allowedViewers: Principal[] };

/**
* Canister settings.
*
Expand Down Expand Up @@ -515,6 +526,16 @@ export interface CanisterSettings {
*/
logVisibility?: LogVisibility;

/**
* The snapshot visibility of the canister.
*/
snapshotVisibility?: SnapshotVisibility;

/**
* The log memory limit of the canister in bytes.
*/
logMemoryLimit?: bigint;

/**
* The WASM memory limit of the canister in bytes.
*/
Expand Down Expand Up @@ -783,7 +804,9 @@ export interface CanisterQueryStats {

/**
* The result of querying the status of a canister.
* Matches the IC management canister `canister_status` response.
* This is a subset of the IC management canister `canister_status` response.
* Some fields (e.g. `snapshotVisibility`, `logMemoryLimit`, `memoryMetrics`)
* are not yet included because the PocketIC server does not return them.
*
* @category Types
* @see [Principal](https://js.icp.build/core/latest/libs/principal/api/classes/principal/)
Expand Down
13 changes: 13 additions & 0 deletions packages/pic/src/pocket-ic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
isNil,
logVisibilityFromIDL,
optLogVisibilityToIDL,
optSnapshotVisibilityToIDL,
optional,
readFileAsBytes,
sha256,
Expand Down Expand Up @@ -187,6 +188,8 @@ export class PocketIc {
memoryAllocation,
reservedCyclesLimit,
logVisibility,
snapshotVisibility,
logMemoryLimit,
wasmMemoryLimit,
wasmMemoryThreshold,
environmentVariables,
Expand All @@ -201,6 +204,8 @@ export class PocketIc {
memoryAllocation,
reservedCyclesLimit,
logVisibility,
snapshotVisibility,
logMemoryLimit,
wasmMemoryLimit,
wasmMemoryThreshold,
environmentVariables,
Expand Down Expand Up @@ -248,6 +253,8 @@ export class PocketIc {
memoryAllocation,
reservedCyclesLimit,
logVisibility,
snapshotVisibility,
logMemoryLimit,
wasmMemoryLimit,
wasmMemoryThreshold,
environmentVariables,
Expand All @@ -263,6 +270,8 @@ export class PocketIc {
freezing_threshold: optional(freezingThreshold),
reserved_cycles_limit: optional(reservedCyclesLimit),
log_visibility: optLogVisibilityToIDL(logVisibility),
snapshot_visibility: optSnapshotVisibilityToIDL(snapshotVisibility),
log_memory_limit: optional(logMemoryLimit),
wasm_memory_limit: optional(wasmMemoryLimit),
wasm_memory_threshold: optional(wasmMemoryThreshold),
environment_variables: optional(environmentVariables),
Expand Down Expand Up @@ -614,6 +623,8 @@ export class PocketIc {
memoryAllocation,
reservedCyclesLimit,
logVisibility,
snapshotVisibility,
logMemoryLimit,
wasmMemoryLimit,
wasmMemoryThreshold,
environmentVariables,
Expand All @@ -628,6 +639,8 @@ export class PocketIc {
freezing_threshold: optional(freezingThreshold),
reserved_cycles_limit: optional(reservedCyclesLimit),
log_visibility: optLogVisibilityToIDL(logVisibility),
snapshot_visibility: optSnapshotVisibilityToIDL(snapshotVisibility),
log_memory_limit: optional(logMemoryLimit),
wasm_memory_limit: optional(wasmMemoryLimit),
wasm_memory_threshold: optional(wasmMemoryThreshold),
environment_variables: optional(environmentVariables),
Expand Down
21 changes: 20 additions & 1 deletion packages/pic/src/util/candid.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { IDL } from '@icp-sdk/core/candid';
import type { LogVisibility as LogVisibilityIDL } from '../management-canister';
import type { SnapshotVisibility as SnapshotVisibilityIDL } from '../management-canister';
import type { LogVisibility as LogVisibilityPIC } from '../pocket-ic-types';
import type { SnapshotVisibility as SnapshotVisibilityPIC } from '../pocket-ic-types';
import { isNil } from './is-nil';

export function optional<T>(value: T | undefined | null): [] | [T] {
return isNil(value) ? [] : [value];
}

export type { LogVisibilityIDL };
export type { LogVisibilityIDL, SnapshotVisibilityIDL };

export function optLogVisibilityToIDL(
lv: LogVisibilityPIC | undefined,
Expand All @@ -24,6 +26,23 @@ export function logVisibilityFromIDL(lv: LogVisibilityIDL): LogVisibilityPIC {
return { controllers: null };
}

export function optSnapshotVisibilityToIDL(
sv: SnapshotVisibilityPIC | undefined,
): [] | [SnapshotVisibilityIDL] {
if (sv === undefined) return [];
if ('controllers' in sv) return [{ controllers: null }];
if ('public' in sv) return [{ public: null }];
return [{ allowed_viewers: sv.allowedViewers }];
}

export function snapshotVisibilityFromIDL(
sv: SnapshotVisibilityIDL,
): SnapshotVisibilityPIC {
if ('allowed_viewers' in sv) return { allowedViewers: sv.allowed_viewers };
if ('public' in sv) return { public: null };
return { controllers: null };
}

export function decodeCandid<T>(types: IDL.Type[], data: Uint8Array): T | null {
const returnValues = IDL.decode(types, data);

Expand Down
2 changes: 2 additions & 0 deletions packages/pic/tests/src/pocket-ic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ describe.each(wasmVariants)('PocketIc — %s WASM', (_label, targetSize) => {
logVisibility: { public: null },
wasmMemoryThreshold: wasmThreshold,
environmentVariables: envVars,
snapshotVisibility: { controllers: null },
logMemoryLimit: 4_096n,
sender: CONTROLLER_PRINCIPAL,
});

Expand Down
Loading
Loading