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
41 changes: 41 additions & 0 deletions .github/actions/setup-canister-toolchain/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Setup Canister Toolchain
description: Install ICP CLI, Motoko toolchain, Rust wasm32 target, and configure caching

inputs:
package-manager:
description: 'Package manager to use (pnpm or bun)'
required: true

runs:
using: composite
steps:
- name: Install ICP CLI tools
shell: bash
run: ${{ inputs.package-manager }} add -g @icp-sdk/icp-cli @icp-sdk/ic-wasm

- name: Cache Mops
uses: actions/cache@v4
with:
path: |
~/.cache/mops
~/Library/Caches/mops
.mops
key: mops-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('mops.toml') }}

- name: Setup Motoko toolchain
shell: bash
run: |
${{ inputs.package-manager }} add -g ic-mops
mops install

- name: Cache Cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
target
key: cargo-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/Cargo.lock') }}

- name: Add wasm32 Rust target
shell: bash
run: rustup target add wasm32-unknown-unknown
12 changes: 6 additions & 6 deletions .github/workflows/e2e-test-nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ jobs:
- name: Setup PNPM
uses: dfinity/ci-tools/actions/setup-pnpm@main

- name: Setup DFX
uses: dfinity/setup-dfx@main
- name: Setup Canister Toolchain
uses: ./.github/actions/setup-canister-toolchain
with:
dfx-version: 'auto'
package-manager: pnpm

- name: Build
run: pnpm run build
Expand Down Expand Up @@ -64,10 +64,10 @@ jobs:
shell: bash
run: bun i --frozen-lockfile

- name: Setup DFX
uses: dfinity/setup-dfx@main
- name: Setup Canister Toolchain
uses: ./.github/actions/setup-canister-toolchain
with:
dfx-version: 'auto'
package-manager: bun

- name: Build
run: bun run build
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/.dfx/
/.icp/cache/
/.mops/
/node_modules/
/target/

Expand Down
3 changes: 3 additions & 0 deletions bun.lock

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

130 changes: 0 additions & 130 deletions dfx.json

This file was deleted.

25 changes: 24 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Examples

All examples are written in [TypeScript](https://www.typescriptlang.org/) with [Jest](https://jestjs.io/) as the test runner,
All examples are written in [TypeScript](https://www.typescriptlang.org/) with [Jest](https://jestjs.io/) or [Vitest](https://vitest.dev/) as the test runner,
but `@dfinity/pic` can be used with JavaScript and any other testing runner, such as [NodeJS](https://nodejs.org/dist/latest-v20.x/docs/api/test.html), [bun](https://bun.sh/docs/cli/test) or [Mocha](https://mochajs.org/).

## Setup
Expand All @@ -13,6 +13,27 @@ but `@dfinity/pic` can be used with JavaScript and any other testing runner, suc
bun i
```

- Build all examples:

```bash
bun build:examples
```

- Test all examples:

```bash
bun test:examples
```

- Build or test a single example:

```bash
bun build:examples -- counter
bun test:examples -- counter
```

## Examples

- [Counter](./counter/README.md)
This example demonstrates how to work with a simple canister as well as init arguments, canister upgrades and WASM reinstallation.
- [Clock](./clock/README.md)
Expand All @@ -21,6 +42,8 @@ but `@dfinity/pic` can be used with JavaScript and any other testing runner, suc
This example demonstrates how to work with more complex canisters, identities, canister upgrades, and stable memory management. It also shows how to use "live" mode with agent-js (in contrast to the pic-js actor).
- [Multicanister](./multicanister/README.md)
This example demonstrates how to work with multiple canisters and multiple subnets.
- [ICP Features](./icp_features/README.md)
This example demonstrates how to enable ICP features when creating a PocketIC instance.
- [NNS Proxy](./nns_proxy/README.md)
This example demonstrates how to work with an NNS state directory.
- [Google Search](./google_search/README.md)
Expand Down
8 changes: 4 additions & 4 deletions examples/clock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

This example demonstrates how to work with the replica's system time, canister timers as well as checking for canister existence and cycle management.

Build the counter canister:
Build the canister:

```shell
bun build:clock
bun build:examples -- clock
```

Run the counter tests:
Run the tests:

```shell
bun test:clock
bun test:examples -- clock
```
7 changes: 7 additions & 0 deletions examples/clock/canister.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: clock
recipe:
type: '@dfinity/motoko@v4.1.0'
configuration:
main: src/main.mo
candid: clock.did
compress: true
3 changes: 3 additions & 0 deletions examples/clock/clock.did
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
service : {
get : () -> (int) query;
}
4 changes: 2 additions & 2 deletions examples/clock/src/main.mo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Time "mo:base/Time";
import { setTimer; recurringTimer } = "mo:base/Timer";
import Time "mo:core/Time";
import { setTimer; recurringTimer } = "mo:core/Timer";

persistent actor Clock {
private type Time = Time.Time;
Expand Down
7 changes: 3 additions & 4 deletions examples/clock/tests/src/clock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ const WASM_PATH = resolve(
'..',
'..',
'..',
'.dfx',
'local',
'canisters',
'.icp',
'cache',
'artifacts',
'clock',
'clock.wasm.gz',
);

describe('Clock', () => {
Expand Down
8 changes: 4 additions & 4 deletions examples/counter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

This example demonstrates how to work with a simple canister as well as init arguments, canister upgrades and WASM reinstallation.

Build the counter canister:
Build the canister:

```shell
bun build:counter
bun build:examples -- counter
```

Run the counter tests:
Run the tests:

```shell
bun test:counter
bun test:examples -- counter
```
7 changes: 7 additions & 0 deletions examples/counter/canister.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: counter
recipe:
type: '@dfinity/motoko@v4.1.0'
configuration:
main: src/main.mo
candid: counter.did
compress: true
6 changes: 6 additions & 0 deletions examples/counter/counter.did
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
service : (nat) -> {
get : () -> (nat) query;
set : (nat) -> ();
inc : () -> ();
dec : () -> ();
}
2 changes: 1 addition & 1 deletion examples/counter/src/main.mo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Nat "mo:base/Nat";
import Nat "mo:core/Nat";

persistent actor class Counter(initial_count : Nat) {
private var counter = initial_count;
Expand Down
7 changes: 3 additions & 4 deletions examples/counter/tests/src/counter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ const WASM_PATH = resolve(
'..',
'..',
'..',
'.dfx',
'local',
'canisters',
'.icp',
'cache',
'artifacts',
'counter',
'counter.wasm.gz',
);

describe('Counter', () => {
Expand Down
10 changes: 5 additions & 5 deletions examples/google_search/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Multi canister
# Google Search

This example demonstrates how to test HTTPS Outcalls in canisters.
This example demonstrates how to mock HTTPS Outcalls in canisters.

Build the canisters:
Build the canister:

```shell
bun build:google_search
bun build:examples -- google_search
```

Run the tests:

```shell
bun test:google_search
bun test:examples -- google_search
```
Loading