Skip to content

Commit 01b1e4d

Browse files
authored
Example with guards and asynchronous code for Rust canisters (#877)
* Infrastructure * integration test * examples with various futures * add dfx support * temp with made up future * clean-up * use same state field for single/multi items test * clean-up * doc * added Github workflow file * provision pocket-ic server * use same version as locally * added guard against parallel processing * upgrade PocketIc * added test against parallel processing. * simplify provisioning of PocketIC and added Linting * fix * fix order of CI steps * ensure items are not in processing when reset * add ownership
1 parent 46704c2 commit 01b1e4d

File tree

11 files changed

+2524
-0
lines changed

11 files changed

+2524
-0
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
/rust/dip721-nft-container/ @dfinity/sdk
6666
/rust/encrypted-notes-dapp-vetkd/ @dfinity/dept-crypto-library
6767
/rust/encrypted-notes-dapp/ @dfinity/div-Crypto
68+
/rust/guards/ @dfinity/cross-chain-team
6869
/rust/hello/ @dfinity/sdk
6970
/rust/icp_transfer/ @dfinity/growth
7071
/rust/image-classification/ @dfinity/runtime
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
POCKET_IC_SERVER_VERSION=${POCKET_IC_SERVER_VERSION:=4.0.0}
6+
POCKET_IC_SERVER_PATH=${POCKET_IC_SERVER_PATH:="${HOME}/bin/pocket-ic-server"}
7+
8+
if [[ $OSTYPE == "linux-gnu"* ]] || [[ $RUNNER_OS == "Linux" ]]
9+
then
10+
PLATFORM=linux
11+
elif [[ $OSTYPE == "darwin"* ]] || [[ $RUNNER_OS == "macOS" ]]
12+
then
13+
PLATFORM=darwin
14+
else
15+
echo "OS not supported: ${OSTYPE:-$RUNNER_OS}"
16+
exit 1
17+
fi
18+
19+
if [ ! -f "$POCKET_IC_SERVER_PATH" ]; then
20+
echo "Downloading PocketIC."
21+
mkdir -p "$(dirname "${POCKET_IC_SERVER_PATH}")"
22+
curl -sSL "https://github.com/dfinity/pocketic/releases/download/${POCKET_IC_SERVER_VERSION}/pocket-ic-x86_64-${PLATFORM}.gz" -o "${POCKET_IC_SERVER_PATH}".gz
23+
gunzip "${POCKET_IC_SERVER_PATH}.gz"
24+
chmod +x "${POCKET_IC_SERVER_PATH}"
25+
else
26+
echo "PocketIC server already exists, skipping download."
27+
fi
28+
29+
# Set environment variables.
30+
echo "POCKET_IC_BIN=${POCKET_IC_SERVER_PATH}" >> "$GITHUB_ENV"
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: rust-guards
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
paths:
8+
- rust/guards/**
9+
- .github/workflows/provision-darwin.sh
10+
- .github/workflows/provision-linux.sh
11+
- .github/workflows/provision-pocket-ic-server.sh
12+
- .github/workflows/rust-guards-example.yml
13+
- .ic-commit
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
jobs:
18+
rust-guards-darwin:
19+
runs-on: macos-12
20+
steps:
21+
- uses: actions/checkout@v1
22+
- name: Provision Darwin
23+
run: bash .github/workflows/provision-darwin.sh
24+
- name: Provision PocketIC Darwin
25+
run: bash .github/workflows/provision-pocket-ic-server.sh
26+
- name: Build Guards Darwin
27+
run: |
28+
pushd rust/guards
29+
cargo build --target wasm32-unknown-unknown --release
30+
popd
31+
- name: Lint Guards Darwin
32+
run: |
33+
pushd rust/guards
34+
cargo fmt --all -- --check && cargo clippy --all-targets --all-features -- -D warnings
35+
popd
36+
- name: Test Guards Darwin
37+
run: |
38+
pushd rust/guards
39+
cargo test
40+
popd
41+
rust-guards-linux:
42+
runs-on: ubuntu-20.04
43+
steps:
44+
- uses: actions/checkout@v1
45+
- name: Provision Linux
46+
run: bash .github/workflows/provision-linux.sh
47+
- name: Provision PocketIC Linux
48+
run: bash .github/workflows/provision-pocket-ic-server.sh
49+
- name: Build Guards Linux
50+
run: |
51+
pushd rust/guards
52+
cargo build --target wasm32-unknown-unknown --release
53+
popd
54+
- name: Lint Guards Linux
55+
run: |
56+
pushd rust/guards
57+
cargo fmt --all -- --check && cargo clippy --all-targets --all-features -- -D warnings
58+
popd
59+
- name: Test Guards Linux
60+
run: |
61+
pushd rust/guards
62+
cargo test
63+
popd

0 commit comments

Comments
 (0)