Skip to content

Commit

Permalink
feat(test): Skeleton binding crates (#3866)
Browse files Browse the repository at this point in the history
# Motivation
We would like comprehensive pocket-ic tests for Oisy.

To that end, we would like to generate canister bindings to be used in
pocket-ic tests rather than maintaining the bindings manually. We will
start with the ledger bindings, then move on to the chain fusion signer
and rewards canisters.

There already bindings for use inside a canister. There is a TODO to
autogenerate them.

However it is inconvenient and sometimes very confusing if the API types
are generated twice, with identical names. We will therefore make `didc`
generate a file with just Rust types, and the two (pocket-ic and
canister) bindings will use those shared types.

A further constraint is that pocket-ic and canister bindings cannot be
compiled together into the same crate. We therefore need three separate
crates for types, pocket-ic bindings and internal canister bindings.

There is quite  a lot to do here, so we break it down into small steps.

# Changes
- Create the Rust crates needed to support pocket-ic and types bindings.

# Tests
- Existing CI should verify that the crates are well formed.
- The crates are currently empty, so there is nothing else to test at
this time.

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
bitdivine and github-actions[bot] authored Dec 17, 2024
1 parent 90d529b commit 35d499b
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 2 deletions.
23 changes: 23 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
members = [
"src/backend",
"src/cycles_ledger/client",
"src/cycles_ledger/pic",
"src/cycles_ledger/types",
"src/shared"
]
resolver = "2"
Expand All @@ -11,6 +13,8 @@ ic-cdk = "0.16.0"
ic-cdk-macros = "0.16.0"
ic-cdk-timers = "0.9.0"
ic-cycles-ledger-client = { path = "src/cycles_ledger/client" }
ic-cycles-ledger-pic = { path = "src/cycles_ledger/pic" }
ic-cycles-ledger-types = { path = "src/cycles_ledger/types" }
ic-ledger-types = "0.13.0"
ic-stable-structures = "0.6.7"
ic-metrics-encoder = "1.1.1"
Expand Down
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,18 @@ COPY Cargo.lock .
COPY Cargo.toml .
COPY src/backend/Cargo.toml src/backend/Cargo.toml
COPY src/cycles_ledger/client/Cargo.toml src/cycles_ledger/client/Cargo.toml
COPY src/cycles_ledger/pic/Cargo.toml src/cycles_ledger/pic/Cargo.toml
COPY src/cycles_ledger/types/Cargo.toml src/cycles_ledger/types/Cargo.toml
COPY src/shared/Cargo.toml src/shared/Cargo.toml
ENV CARGO_TARGET_DIR=/cargo_target
RUN mkdir -p src/backend/src \
&& touch src/backend/src/lib.rs \
&& mkdir -p src/cycles_ledger/client/src \
&& touch src/cycles_ledger/client/src/lib.rs \
&& mkdir -p src/cycles_ledger/pic/src \
&& touch src/cycles_ledger/pic/src/lib.rs \
&& mkdir -p src/cycles_ledger/types/src \
&& touch src/cycles_ledger/types/src/lib.rs \
&& mkdir -p src/shared/src \
&& touch src/shared/src/lib.rs \
&& ./docker/build --only-dependencies \
Expand Down
6 changes: 4 additions & 2 deletions scripts/lint.rust.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
# Lint the rust code
cargo clippy --locked --target wasm32-unknown-unknown --all-features -- -D warnings -W clippy::pedantic -A clippy::module-name-repetitions -A clippy::struct-field-names -A deprecated
# Lint the Rust canister code, excluding the autogenerated crates.
for crate in src/backend/Cargo.toml src/shared/Cargo.toml; do
cargo clippy --manifest-path "$crate" --locked --target wasm32-unknown-unknown --all-features -- -D warnings -W clippy::pedantic -A clippy::module-name-repetitions -A clippy::struct-field-names -A deprecated
done
12 changes: 12 additions & 0 deletions src/cycles_ledger/pic/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "ic-cycles-ledger-pic"
version = "0.1.0"
edition = "2021"

[dependencies]
candid = { workspace = true }
ic-cdk = { workspace = true }
ic-cycles-ledger-types = { workspace = true }
pocket-ic = { workspace = true }
serde = { workspace = true }
serde_bytes = { workspace = true }
1 change: 1 addition & 0 deletions src/cycles_ledger/pic/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//! TODO: Generate pic bindings.
10 changes: 10 additions & 0 deletions src/cycles_ledger/types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "ic-cycles-ledger-types"
version = "0.1.0"
edition = "2021"

[dependencies]
candid = { workspace = true }
ic-cdk = { workspace = true }
serde = { workspace = true }
serde_bytes = { workspace = true }
1 change: 1 addition & 0 deletions src/cycles_ledger/types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//! TODO: generate types
1 change: 1 addition & 0 deletions src/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2021"

[dependencies]
candid = { workspace = true }
getrandom = { workspace = true }
ic-canister-sig-creation = { workspace = true }
ic-cdk = { workspace = true }
ic-cdk-macros = { workspace = true }
Expand Down

0 comments on commit 35d499b

Please sign in to comment.