diff --git a/.github/workflows/backend_only.yml b/.github/workflows/backend_only.yml new file mode 100644 index 000000000..370d80c7c --- /dev/null +++ b/.github/workflows/backend_only.yml @@ -0,0 +1,43 @@ +name: backend_only + +on: + push: + branches: [master] + pull_request: + paths: + - motoko/backend_only/** + - rust/backend_only/** + - .github/workflows/backend_only.yml + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + motoko-backend_only: + runs-on: ubuntu-24.04 + container: ghcr.io/dfinity/icp-dev-env-motoko:0.3.2 + env: + ICP_CLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 + - name: Deploy and test + working-directory: motoko/backend_only + run: | + icp network start -d + icp deploy + make test + + rust-backend_only: + runs-on: ubuntu-24.04 + container: ghcr.io/dfinity/icp-dev-env-rust:0.3.2 + env: + ICP_CLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 + - name: Deploy and test + working-directory: rust/backend_only + run: | + icp network start -d + icp deploy + make test diff --git a/motoko/backend_only/.devcontainer/devcontainer.json b/motoko/backend_only/.devcontainer/devcontainer.json deleted file mode 100644 index ebb0b8bcc..000000000 --- a/motoko/backend_only/.devcontainer/devcontainer.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "ICP Dev Environment", - "image": "ghcr.io/dfinity/icp-dev-env-slim:22", - "forwardPorts": [4943, 5173], - "portsAttributes": { - "4943": { - "label": "dfx", - "onAutoForward": "ignore" - }, - "5173": { - "label": "vite", - "onAutoForward": "openBrowser" - } - }, - "customizations": { - "vscode": { - "extensions": ["dfinity-foundation.vscode-motoko"] - } - } -} diff --git a/motoko/backend_only/BUILD.md b/motoko/backend_only/BUILD.md deleted file mode 100644 index 8877d3ed2..000000000 --- a/motoko/backend_only/BUILD.md +++ /dev/null @@ -1,26 +0,0 @@ -# Continue building locally - -Projects deployed through ICP Ninja are temporary; they will only be live for 30 minutes before they are removed. To continue building locally, follow these steps. - -### 1. Install developer tools - -Install [Node.js](https://nodejs.org/en/download/) and [icp-cli](https://cli.internetcomputer.org): - -```bash -npm install -g @icp-sdk/icp-cli @icp-sdk/ic-wasm -``` - -Then navigate into your project's directory that you downloaded from ICP Ninja. - -### 2. Deploy locally - -Start the local network and deploy the project: - -```bash -icp network start -d -icp deploy -``` - -## Additional examples - -Additional code examples and sample applications can be found in the [DFINITY examples repo](https://github.com/dfinity/examples). diff --git a/motoko/backend_only/Makefile b/motoko/backend_only/Makefile new file mode 100644 index 000000000..08b2e2255 --- /dev/null +++ b/motoko/backend_only/Makefile @@ -0,0 +1,8 @@ +.PHONY: test + +test: + @echo "=== Test 1: greet returns greeting ===" + @result=$$(icp canister call backend greet '("World")') && \ + echo "$$result" && \ + echo "$$result" | grep -q '"Hello, World!"' && \ + echo "PASS" || (echo "FAIL" && exit 1) diff --git a/motoko/backend_only/README.md b/motoko/backend_only/README.md index 1b694300a..b904b1ed8 100644 --- a/motoko/backend_only/README.md +++ b/motoko/backend_only/README.md @@ -1,55 +1,30 @@ # Motoko backend -[View this sample's code on GitHub](https://github.com/dfinity/examples/tree/master/motoko/backend_only) - -## Overview - -This backend only project demonstrates how to write a simple smart contract for ICP. - -## Deploying from ICP Ninja - -This example can be deployed directly from [ICP Ninja](https://icp.ninja), a browser-based IDE for ICP. To continue developing locally after deploying from ICP Ninja, see [BUILD.md](BUILD.md). - -[![Open in ICP Ninja](https://icp.ninja/assets/open.svg)](https://icp.ninja/i?g=https://github.com/dfinity/examples/motoko/backend_only) - -> **Note:** ICP Ninja currently uses `dfx` under the hood, which is why this example includes a `dfx.json` configuration file. `dfx` is the legacy CLI, being superseded by [icp-cli](https://cli.internetcomputer.org), which is what developers should use for local development. +This backend-only example demonstrates how to write a simple smart contract for ICP. It implements a single `greet(name)` query function that returns a greeting string. ## Build and deploy from the command line ### Prerequisites -- [x] Install [Node.js](https://nodejs.org/en/download/) -- [x] Install [icp-cli](https://cli.internetcomputer.org): `npm install -g @icp-sdk/icp-cli @icp-sdk/ic-wasm` +- Node.js +- icp-cli: `npm install -g @icp-sdk/icp-cli @icp-sdk/ic-wasm` ### Install -Clone the example project: - ```bash git clone https://github.com/dfinity/examples cd examples/motoko/backend_only ``` -### Deployment - -Start the local network: +### Deploy and test ```bash icp network start -d -``` - -Deploy the canister: - -```bash icp deploy -``` - -Stop the local network when done: - -```bash +make test icp network stop ``` ## Security considerations and best practices -If you base your application on this example, it is recommended that you familiarize yourself with and adhere to the [security best practices](https://internetcomputer.org/docs/building-apps/security/overview) for developing on ICP. This example may not implement all the best practices. +Refer to the [security best practices](https://docs.internetcomputer.org/guides/security/overview) for information on security and best practices for your ICP app. diff --git a/motoko/backend_only/backend/app.mo b/motoko/backend_only/backend/app.mo index 673eba2c1..89f994633 100644 --- a/motoko/backend_only/backend/app.mo +++ b/motoko/backend_only/backend/app.mo @@ -1,4 +1,4 @@ -persistent actor HelloWorld { +actor HelloWorld { public query func greet(name : Text) : async Text { return "Hello, " # name # "!"; }; diff --git a/motoko/backend_only/dfx.json b/motoko/backend_only/dfx.json deleted file mode 100644 index 5d7f13c3e..000000000 --- a/motoko/backend_only/dfx.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "canisters": { - "backend": { - "main": "backend/app.mo", - "type": "motoko", - "args": "--enhanced-orthogonal-persistence" - } - }, - "defaults": { - "build": { - "packtool": "mops sources" - } - } -} diff --git a/motoko/backend_only/icp.yaml b/motoko/backend_only/icp.yaml index b83566d40..fb741fade 100644 --- a/motoko/backend_only/icp.yaml +++ b/motoko/backend_only/icp.yaml @@ -1,6 +1,4 @@ canisters: - name: backend recipe: - type: "@dfinity/motoko@v4.1.0" - configuration: - main: backend/app.mo + type: "@dfinity/motoko@v5.0.0" diff --git a/motoko/backend_only/mops.toml b/motoko/backend_only/mops.toml index dc89d0891..d3f244542 100644 --- a/motoko/backend_only/mops.toml +++ b/motoko/backend_only/mops.toml @@ -1,11 +1,14 @@ [toolchain] -moc = "1.5.1" +moc = "1.9.0" [dependencies] -core = "2.4.0" +core = "2.5.0" [moc] -# M0236: use context dot notation (e.g. x.toText() instead of Nat.toText(x)) -# M0237: redundant explicit implicit arguments (e.g. Nat.compare is inferred automatically) -# M0223: redundant type instantiation (e.g. Array.tabulate instead of Array.tabulate) -args = ["-W=M0236,M0237,M0223"] +# M0236: use context dot notation +# M0237: redundant explicit implicit arguments +# M0223: redundant type instantiation +args = ["--default-persistent-actors", "-W=M0236,M0237,M0223"] + +[canisters.backend] +main = "backend/app.mo" diff --git a/rust/backend_only/.devcontainer/devcontainer.json b/rust/backend_only/.devcontainer/devcontainer.json deleted file mode 100644 index ebb0b8bcc..000000000 --- a/rust/backend_only/.devcontainer/devcontainer.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "ICP Dev Environment", - "image": "ghcr.io/dfinity/icp-dev-env-slim:22", - "forwardPorts": [4943, 5173], - "portsAttributes": { - "4943": { - "label": "dfx", - "onAutoForward": "ignore" - }, - "5173": { - "label": "vite", - "onAutoForward": "openBrowser" - } - }, - "customizations": { - "vscode": { - "extensions": ["dfinity-foundation.vscode-motoko"] - } - } -} diff --git a/rust/backend_only/BUILD.md b/rust/backend_only/BUILD.md deleted file mode 100644 index ffb6557ec..000000000 --- a/rust/backend_only/BUILD.md +++ /dev/null @@ -1,26 +0,0 @@ -# Continue building locally - -Projects deployed through ICP Ninja are temporary; they will only be live for 30 minutes before they are removed. To continue building locally, follow these steps. - -### 1. Install developer tools - -Install [Node.js](https://nodejs.org/en/download/) and [icp-cli](https://cli.icp.build): - -```bash -npm install -g @icp-sdk/icp-cli @icp-sdk/ic-wasm -``` - -Then navigate into your project's directory that you downloaded from ICP Ninja. - -### 2. Deploy locally - -Start the local network and deploy the project: - -```bash -icp network start -d -icp deploy -``` - -## Additional examples - -Additional code examples and sample applications can be found in the [DFINITY examples repo](https://github.com/dfinity/examples). diff --git a/rust/backend_only/Makefile b/rust/backend_only/Makefile new file mode 100644 index 000000000..390eb4bbf --- /dev/null +++ b/rust/backend_only/Makefile @@ -0,0 +1,8 @@ +.PHONY: test + +test: + @echo "=== Test 1/1: greet() returns a greeting ===" + @result=$$(icp canister call backend greet '("World")') && \ + echo "$$result" && \ + echo "$$result" | grep -q 'Hello, World!' && \ + echo "PASS" || (echo "FAIL" && exit 1) diff --git a/rust/backend_only/backend/Cargo.toml b/rust/backend_only/backend/Cargo.toml index 268b84c42..22acbdec9 100644 --- a/rust/backend_only/backend/Cargo.toml +++ b/rust/backend_only/backend/Cargo.toml @@ -10,5 +10,5 @@ crate-type = ["cdylib"] path = "lib.rs" [dependencies] -candid = "0.10.10" -ic-cdk = "0.16.0" +candid = "0.10" +ic-cdk = "0.20" diff --git a/rust/backend_only/dfx.json b/rust/backend_only/dfx.json deleted file mode 100644 index eaa52140b..000000000 --- a/rust/backend_only/dfx.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "canisters": { - "backend": { - "candid": "backend/backend.did", - "type": "custom", - "shrink": true, - "gzip": true, - "wasm": "target/wasm32-unknown-unknown/release/backend.wasm", - "build": [ - "cargo build --target wasm32-unknown-unknown --release -p backend", - "candid-extractor target/wasm32-unknown-unknown/release/backend.wasm > backend/backend.did" - ], - "metadata": [ - { - "name": "candid:service" - } - ] - } - } -} diff --git a/rust/backend_only/icp.yaml b/rust/backend_only/icp.yaml index b331b4584..ff944789f 100644 --- a/rust/backend_only/icp.yaml +++ b/rust/backend_only/icp.yaml @@ -1,6 +1,6 @@ canisters: - name: backend recipe: - type: "@dfinity/rust@v3.1.0" + type: "@dfinity/rust@v3.2.0" configuration: package: backend