Skip to content
Draft
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
28 changes: 28 additions & 0 deletions .github/workflows/icp_transfer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: icp_transfer

on:
push:
branches: [master]
pull_request:
paths:
- rust/icp_transfer/**
- .github/workflows/icp_transfer.yml

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
rust-icp_transfer:
runs-on: ubuntu-24.04
container: ghcr.io/dfinity/icp-dev-env-rust:1.0.0
env:
ICP_CLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Deploy and test
working-directory: rust/icp_transfer
run: |
icp network start -d
icp deploy
make test
43 changes: 0 additions & 43 deletions .github/workflows/rust-icp-transfer-example.yml

This file was deleted.

3 changes: 0 additions & 3 deletions rust/icp_transfer/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
.DS_Store
**/.DS_Store

# dfx temporary files
.dfx/

# generated files
**/declarations/

Expand Down
2 changes: 1 addition & 1 deletion rust/icp_transfer/Cargo.lock

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

4 changes: 1 addition & 3 deletions rust/icp_transfer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
[workspace]
members = [
"src/icp_transfer_backend"
]
members = ["backend"]
resolver = "2"
73 changes: 73 additions & 0 deletions rust/icp_transfer/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
IC_REVISION = d87954601e4b22972899e9957e800406a0a6b929
LEDGER_WASM_URL = https://download.dfinity.systems/ic/$(IC_REVISION)/canisters/ledger-canister.wasm.gz
LEDGER_PRINCIPAL = ryjl3-tyaaa-aaaaa-aaaba-cai

.PHONY: deploy-ledger test

# Download and deploy the ICP ledger canister at the well-known mainnet principal.
# On the local network, provisional_create_canister_with_cycles allows specifying
# an exact canister ID so that the backend (which hardcodes MAINNET_LEDGER_CANISTER_ID)
# finds the ledger at the expected address.
deploy-ledger:
@echo "=== Downloading ICP ledger WASM ==="
curl -sL $(LEDGER_WASM_URL) -o /tmp/ledger-canister.wasm.gz
gunzip -f /tmp/ledger-canister.wasm.gz
@echo "=== Creating ledger canister at $(LEDGER_PRINCIPAL) ==="
icp canister call aaaaa-aa provisional_create_canister_with_cycles \
'(record { amount = 10_000_000_000_000 : nat; settings = null; specified_id = opt principal "$(LEDGER_PRINCIPAL)" })' \
-n http://localhost:8000
@echo "=== Installing ICP ledger ==="
MINTER_ACCOUNT_ID=$$(icp identity account-id --identity anonymous) && \
DEFAULT_ACCOUNT_ID=$$(icp identity account-id) && \
icp canister install $(LEDGER_PRINCIPAL) \
--wasm /tmp/ledger-canister.wasm \
--args "(variant { Init = record { \
minting_account = \"$$MINTER_ACCOUNT_ID\"; \
initial_values = vec { record { \"$$DEFAULT_ACCOUNT_ID\"; record { e8s = 10_000_000_000 : nat64; }; }; }; \
send_whitelist = vec {}; \
transfer_fee = opt record { e8s = 10_000 : nat64; }; \
token_symbol = opt \"LICP\"; \
token_name = opt \"Local ICP\"; \
} })" \
-n http://localhost:8000 -y

test: deploy-ledger
@echo "=== Test 1: verify default account has initial ICP balance ==="
@DEFAULT_ACCOUNT_ID=$$(icp identity account-id) && \
ACCOUNT_BYTES=$$(python3 -c "b=bytes.fromhex('$$DEFAULT_ACCOUNT_ID'); print('vec{' + ';'.join(str(x) for x in b) + '}')") && \
result=$$(icp canister call $(LEDGER_PRINCIPAL) account_balance \
"(record { account = $$ACCOUNT_BYTES })" \
-n http://localhost:8000) && \
echo "$$result" && \
echo "$$result" | grep -q '10_000_000_000' && \
echo "PASS" || (echo "FAIL" && exit 1)

@echo "=== Test 2: fund the backend canister with 1 ICP ==="
@BACKEND_PRINCIPAL=$$(icp canister status backend -i) && \
BACKEND_ACCOUNT_ID=$$(icp identity account-id --of-principal $$BACKEND_PRINCIPAL) && \
BACKEND_ACCOUNT_BYTES=$$(python3 -c "b=bytes.fromhex('$$BACKEND_ACCOUNT_ID'); print('vec{' + ';'.join(str(x) for x in b) + '}')") && \
result=$$(icp canister call $(LEDGER_PRINCIPAL) transfer \
"(record { to = $$BACKEND_ACCOUNT_BYTES; memo = 0 : nat64; amount = record { e8s = 100_000_000 : nat64 }; fee = record { e8s = 10_000 : nat64 }; })" \
-n http://localhost:8000) && \
echo "$$result" && \
echo "$$result" | grep -q 'Ok' && \
echo "PASS" || (echo "FAIL" && exit 1)

@echo "=== Test 3: transfer ICP from backend canister to default identity ==="
@CALLER_PRINCIPAL=$$(icp identity principal) && \
result=$$(icp canister call backend transfer \
"(record { amount = record { e8s = 50_000_000 : nat64 }; to_principal = principal \"$$CALLER_PRINCIPAL\"; to_subaccount = null })") && \
echo "$$result" && \
echo "$$result" | grep -q 'Ok' && \
echo "PASS" || (echo "FAIL" && exit 1)

@echo "=== Test 4: verify backend ledger balance decreased after transfer ==="
@BACKEND_PRINCIPAL=$$(icp canister status backend -i) && \
BACKEND_ACCOUNT_ID=$$(icp identity account-id --of-principal $$BACKEND_PRINCIPAL) && \
BACKEND_ACCOUNT_BYTES=$$(python3 -c "b=bytes.fromhex('$$BACKEND_ACCOUNT_ID'); print('vec{' + ';'.join(str(x) for x in b) + '}')") && \
result=$$(icp canister call $(LEDGER_PRINCIPAL) account_balance \
"(record { account = $$BACKEND_ACCOUNT_BYTES })" \
-n http://localhost:8000) && \
echo "$$result" && \
echo "$$result" | grep -q 'e8s' && \
echo "PASS" || (echo "FAIL" && exit 1)
Loading
Loading