chore: migrate rust/receiving-icp to icp-cli#1394
Merged
Merged
Conversation
Replaces dfx.json with icp.yaml, moves Rust source to backend/, adds Makefile with tests for account identifiers and ledger balance queries, and adds a CI workflow using icp-dev-env-rust:1.0.0. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ml + crate bumps
Replace hardcoded TESTICP ledger principal with env!("ICP_LEDGER_CANISTER_ID")
baked at compile time by the @dfinity/rust recipe:
local / production → ryjl3-tyaaa-aaaaa-aaaba-cai (ICP ledger)
staging → xafvr-biaaa-aaaai-aql5q-cai (TESTICP ledger)
icp.yaml now uses the environments block with per-environment
environment_variables under settings. Deploy with
`icp deploy --environment staging` to target TESTICP.
Also: ic-cdk 0.18 → 0.20, ic-ledger-types 0.15 → 0.16,
CI image 1.0.0 → 1.0.1.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ncipal env!() fails at compile time when ICP_LEDGER_CANISTER_ID is not injected by the recipe. The @dfinity/rust recipe does not yet inject environment_variables from the icp.yaml environments.settings block into the cargo build environment (only PUBLIC_CANISTER_ID:* vars are injected automatically). option_env! with a hardcoded fallback ensures the build always succeeds while still demonstrating the per-environment configuration concept in icp.yaml. When/if the recipe gains support for injecting custom env vars, the option_env! approach will pick them up automatically. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add ic_cdk::export_candid!() — required for candid-extractor to find
get_candid_pointer and extract the Candid interface
- Revert to env!("ICP_LEDGER_CANISTER_ID") — icp-cli injects environment
variables from the icp.yaml environments.settings block at build time,
so env!() works correctly
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Environment variables injected by icp-cli are read at RUNTIME via ic_cdk::api::env_var_value, not at compile time via env!(). They are stored as WASM metadata and retrieved when the canister executes — the same mechanism as Runtime.envVar in Motoko. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tion - Test 1: verify 64-char hex format (not just presence of a quote) - Test 4: match exact Candid output (0 : nat64) instead of grepping '0' - Test 5 (new): fund canister with 1 ICP, verify get_balance returns 100_000_000 e8s — this actually exercises the ledger inter-canister call - Test 6 (new): verify get_balance_of_subaccount(0,0) also returns 100_000_000 e8s - Test 7 (new): verify get_balance_of_subaccount(1,0) returns 0 (unfunded subaccount) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace Makefile with test.sh (bash) for Git Bash compatibility. New tests: - Test 8: fund subaccount(1,0) via account ID hex using `icp token transfer 1 "$sub1_hex"` — demonstrates that icp token transfer accepts ICP ledger account IDs directly as receivers - Cross-check: verify balance via `icp token balance "$hex"` to show CLI and canister agree on the funded subaccount balance Improvements: - Test 1: grep for 64-char hex format, extract account ID for reuse - Tests 5-7: match exact Candid output (100000000 : nat64) - Tests use natural bash variables (no $$ / \ continuation overhead) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…summary test.sh: - All balance checks now delta-based (before/after funding) — idempotent across re-runs regardless of prior state - Test 7: check unfunded subaccount(2,0) has 0 balance to prove independence (previous approach assumed (0,0) and (1,0) had different balances which fails after equal funding runs) - Remove unused e8s_from_icp helper and cross-check block README: - Separate "Deploy and test locally" from "Deploy to staging or production" - Describe what test.sh covers (7 tests, delta-based, idempotent) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
mbjorkqvist
approved these changes
Jun 18, 2026
mbjorkqvist
left a comment
Contributor
There was a problem hiding this comment.
Thanks @marc0olo! Just a few minor things to point out.
- lib.rs + README: describe ICP_LEDGER_CANISTER_ID as a canister environment variable (a canister setting applied at deploy time via icp.yaml), not 'WASM metadata' — per ic_cdk::api::env_var_value docs - Rename receiving_icp.yml → receiving-icp.yml to match example dir name convention (<example-dir>.yml) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
lwshang
approved these changes
Jun 18, 2026
lwshang
left a comment
Contributor
There was a problem hiding this comment.
Was the removal of the Candid file intentional?
Member
Author
so far yes because it is backend only. but I also thought about it lately again. in any case the candid could be obtained from the canister directly, so I am not sure if we need to include it in the examples if it isn't required for bindings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrates
rust/receiving-icpto icp-cli and showcases per-environment canister configuration via theicp.yamlenvironmentsblock.Changes
icp.yaml: replacesdfx.json; uses@dfinity/rust@v3.3.0. Defines three environments with per-canisterenvironment_variables:local→ICP_LEDGER_CANISTER_ID = ryjl3-tyaaa-aaaaa-aaaba-cai(pre-deployed by icp-cli)staging→ICP_LEDGER_CANISTER_ID = xafvr-biaaa-aaaai-aql5q-cai(TESTICP ledger)production→ICP_LEDGER_CANISTER_ID = ryjl3-tyaaa-aaaaa-aaaba-cai(mainnet ICP ledger)backend/lib.rs: replaces hardcoded TESTICP principal withic_cdk::api::env_var_value("ICP_LEDGER_CANISTER_ID")— reads the canister environment variable at runtime via the system API (the variable is a canister setting applied at deploy time, same mechanism asRuntime.envVarin Motoko);ic_cdk::export_candid!()added for Candid interface extractionCargo.toml: ic-cdk 0.18 → 0.20, ic-ledger-types 0.15 → 0.16test.sh(replacesMakefile): bash script; 7 tests plus idempotent delta-based balance checksREADME.md: environment table, deploy commands per environmentreceiving-icp.yml(renamed fromreceiving_icp.ymlto match example dir convention) usingghcr.io/dfinity/icp-dev-env-rust:1.0.1dfx.json, old workflowKey concept: environment-specific canister configuration
Deploying with
icp deploy --environment stagingtargets the TESTICP ledger without any code change — icp-cli reads theenvironmentsblock inicp.yamland appliesICP_LEDGER_CANISTER_IDas a canister setting. The canister reads it at runtime viaic_cdk::api::env_var_value. This pattern applies to any per-environment constant (ledger principals, feature flags, external canister IDs).Test plan
icp network start -d && icp deploy && bash test.shpasses locallyrust-receiving_icppasses🤖 Generated with Claude Code