Skip to content

Commit

Permalink
chore: e2e wasm64 (#534)
Browse files Browse the repository at this point in the history
* wip

* pocket-ic must be in dev dependencies

* conditional compilation for wasm target_family

* cleanup

* CI wasm64

* fix ci.yml

* fix cont.

* no fail-fast

* rm e2e-tests/src/lib.rs
  • Loading branch information
lwshang authored Dec 20, 2024
1 parent 921c858 commit e2bbc39
Show file tree
Hide file tree
Showing 17 changed files with 188 additions and 109 deletions.
48 changes: 45 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ concurrency:
jobs:
build:
name: cargo build
runs-on: ubuntu-24.04
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-24.04, macos-13-large]
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -44,6 +48,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-24.04, macos-13-large]
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -66,9 +71,43 @@ jobs:
- name: Run tests
run:
| # https://github.com/rust-lang/cargo/issues/6669 we have to run ALL tests with two commands
cargo test --all-targets
cargo test --all-targets --no-fail-fast
cargo test --doc

wasm64:
name: wasm64 e2e
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-24.04, macos-13-large]
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-wasm64-${{ hashFiles('Cargo.lock', 'rust-toolchain.toml') }}
restore-keys: |
${{ runner.os }}-wasm64-
${{ runner.os }}-
- name: Download pocket-ic
run: |
bash scripts/download_pocket_ic.sh
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly
components: rust-src
- name: Run tests
run:
WASM64=1 cargo test --package ic-cdk-e2e-tests --no-fail-fast

fmt:
name: cargo fmt
runs-on: ubuntu-24.04
Expand Down Expand Up @@ -141,7 +180,7 @@ jobs:
aggregate:
name: ci:required
if: ${{ always() }}
needs: [build, test, fmt, clippy, doc]
needs: [build, test, wasm64, fmt, clippy, doc]
runs-on: ubuntu-24.04
steps:
- name: check build result
Expand All @@ -150,6 +189,9 @@ jobs:
- name: check test result
if: ${{ needs.test.result != 'success' }}
run: exit 1
- name: check wasm64 result
if: ${{ needs.wasm64.result != 'success' }}
run: exit 1
- name: check fmt result
if: ${{ needs.fmt.result != 'success' }}
run: exit 1
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ publish = false

[dependencies]
candid.workspace = true
cargo_metadata = "0.18"
escargot = { version = "0.5.7", features = ["print"] }
futures.workspace = true
ic-cdk = { workspace = true, features = ["transform-closure"] }
ic-cdk-timers.workspace = true
lazy_static = "1.4.0"
serde_bytes.workspace = true
futures.workspace = true
sha2.workspace = true

[dev-dependencies]
cargo_metadata = "0.19"
hex.workspace = true
pocket-ic = { git = "https://github.com/dfinity/ic", tag = "release-2024-11-28_03-15-base" }
41 changes: 0 additions & 41 deletions e2e-tests/src/lib.rs

This file was deleted.

11 changes: 5 additions & 6 deletions e2e-tests/tests/api.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use candid::Principal;
use ic_cdk_e2e_tests::cargo_build_canister;
use pocket_ic::{ErrorCode, PocketIcBuilder, UserError, WasmResult};
use pocket_ic::{ErrorCode, UserError, WasmResult};

mod test_utilities;
use test_utilities::{cargo_build_canister, pocket_ic};

#[test]
fn call_api() {
let pic = PocketIcBuilder::new()
.with_application_subnet()
.with_nonmainnet_features(true)
.build();
let pic = pocket_ic();
let wasm = cargo_build_canister("api");
let canister_id = pic.create_canister();
pic.add_cycles(canister_id, 100_000_000_000_000);
Expand Down
10 changes: 6 additions & 4 deletions e2e-tests/tests/api_call.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use candid::{Encode, Principal};
use ic_cdk_e2e_tests::cargo_build_canister;
use pocket_ic::common::rest::RawEffectivePrincipal;
use pocket_ic::{call_candid, query_candid, PocketIc, WasmResult};
use pocket_ic::{call_candid, query_candid, WasmResult};

mod test_utilities;
use test_utilities::{cargo_build_canister, pocket_ic};

#[test]
fn call_apis() {
let pic = PocketIc::new();
let pic = pocket_ic();
let wasm = cargo_build_canister("api_call");
let canister_id = pic.create_canister();
pic.add_cycles(canister_id, 2_000_000_000_000);
Expand Down Expand Up @@ -41,7 +43,7 @@ fn call_apis() {

#[test]
fn cycles_burn() {
let pic = PocketIc::new();
let pic = pocket_ic();
let wasm = cargo_build_canister("api_call");
let canister_id = pic.create_canister();
pic.add_cycles(canister_id, 2_000_000_000_000);
Expand Down
10 changes: 6 additions & 4 deletions e2e-tests/tests/async.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use ic_cdk_e2e_tests::cargo_build_canister;
use pocket_ic::common::rest::RawEffectivePrincipal;
use pocket_ic::{call_candid, query_candid, CallError, ErrorCode, PocketIc};

mod test_utilities;
use test_utilities::{cargo_build_canister, pocket_ic};

#[test]
fn panic_after_async_frees_resources() {
let pic: PocketIc = PocketIc::new();
let pic: PocketIc = pocket_ic();
let wasm = cargo_build_canister("async");
let canister_id = pic.create_canister();
pic.add_cycles(canister_id, 2_000_000_000_000);
Expand Down Expand Up @@ -87,7 +89,7 @@ fn panic_after_async_frees_resources() {

#[test]
fn notify_calls() {
let pic = PocketIc::new();
let pic = pocket_ic();
let wasm = cargo_build_canister("async");
let sender_id = pic.create_canister();
pic.add_cycles(sender_id, 2_000_000_000_000);
Expand Down Expand Up @@ -117,7 +119,7 @@ fn notify_calls() {
// Composite queries are not enabled yet.
#[test]
fn test_composite_query() {
let pic = PocketIc::new();
let pic = pocket_ic();
let wasm = cargo_build_canister("async");
let sender_id = pic.create_canister();
pic.add_cycles(sender_id, 2_000_000_000_000);
Expand Down
11 changes: 5 additions & 6 deletions e2e-tests/tests/call.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use ic_cdk_e2e_tests::cargo_build_canister;
use pocket_ic::call_candid;
use pocket_ic::common::rest::RawEffectivePrincipal;
use pocket_ic::{call_candid, PocketIcBuilder};

mod test_utilities;
use test_utilities::{cargo_build_canister, pocket_ic};

#[test]
fn call() {
let pic = PocketIcBuilder::new()
.with_application_subnet()
.with_nonmainnet_features(true)
.build();
let pic = pocket_ic();
let wasm = cargo_build_canister("call");
let canister_id = pic.create_canister();
pic.add_cycles(canister_id, 100_000_000_000_000);
Expand Down
11 changes: 5 additions & 6 deletions e2e-tests/tests/canister_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ use ic_cdk::management_canister::{
CodeDeploymentRecord, ControllersChangeRecord, CreationRecord, FromCanisterRecord,
FromUserRecord, InstallCodeArgs, UninstallCodeArgs,
};
use ic_cdk_e2e_tests::cargo_build_canister;
use pocket_ic::common::rest::RawEffectivePrincipal;
use pocket_ic::{call_candid, call_candid_as, PocketIcBuilder};
use pocket_ic::{call_candid, call_candid_as};
use std::time::UNIX_EPOCH;

mod test_utilities;
use test_utilities::{cargo_build_canister, pocket_ic};

#[test]
fn test_canister_info() {
let pic = PocketIcBuilder::new()
.with_application_subnet()
.with_nonmainnet_features(true)
.build();
let pic = pocket_ic();
let wasm = cargo_build_canister("canister_info");
// As of PocketIC server v5.0.0 and client v4.0.0, the first canister creation happens at (time0+4).
// Each operation advances the Pic by 2 nanos, except for the last operation which advances only by 1 nano.
Expand Down
11 changes: 5 additions & 6 deletions e2e-tests/tests/chunk.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use candid::Principal;
use ic_cdk_e2e_tests::cargo_build_canister;
use pocket_ic::call_candid;
use pocket_ic::common::rest::RawEffectivePrincipal;
use pocket_ic::{call_candid, PocketIcBuilder};
use sha2::Digest;

mod test_utilities;
use test_utilities::{cargo_build_canister, pocket_ic};

#[test]
fn test_chunk() {
let pic = PocketIcBuilder::new()
.with_application_subnet()
.with_nonmainnet_features(true)
.build();
let pic = pocket_ic();
let wasm = cargo_build_canister("chunk");
let canister_id = pic.create_canister();
pic.add_cycles(canister_id, 100_000_000_000_000);
Expand Down
11 changes: 5 additions & 6 deletions e2e-tests/tests/http_request.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use candid::{Encode, Principal};
use ic_cdk_e2e_tests::cargo_build_canister;
use pocket_ic::common::rest::{
CanisterHttpHeader, CanisterHttpReply, CanisterHttpRequest, CanisterHttpResponse,
MockCanisterHttpResponse,
};
use pocket_ic::{PocketIc, PocketIcBuilder, WasmResult};
use pocket_ic::{PocketIc, WasmResult};

mod test_utilities;
use test_utilities::{cargo_build_canister, pocket_ic};

#[test]
fn test_http_request() {
let pic = PocketIcBuilder::new()
.with_application_subnet()
.with_nonmainnet_features(true)
.build();
let pic = pocket_ic();

let wasm = cargo_build_canister("http_request");
let canister_id = pic.create_canister();
Expand Down
11 changes: 4 additions & 7 deletions e2e-tests/tests/management_canister.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use ic_cdk_e2e_tests::cargo_build_canister;
use pocket_ic::call_candid;
use pocket_ic::common::rest::RawEffectivePrincipal;
use pocket_ic::PocketIcBuilder;

mod test_utilities;
use test_utilities::{cargo_build_canister, pocket_ic};

#[test]
fn test_management_canister() {
let pic = PocketIcBuilder::new()
.with_application_subnet()
.with_nonmainnet_features(true)
.with_ii_subnet() // Required for ecdsa and schnorr
.build();
let pic = pocket_ic();

let wasm = cargo_build_canister("management_canister");
let canister_id = pic.create_canister();
Expand Down
8 changes: 5 additions & 3 deletions e2e-tests/tests/reverse.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use candid::Principal;
use ic_cdk_e2e_tests::cargo_build_canister;
use pocket_ic::{PocketIc, WasmResult};
use pocket_ic::WasmResult;

mod test_utilities;
use test_utilities::{cargo_build_canister, pocket_ic};

#[test]
fn test_raw_api() {
let pic = PocketIc::new();
let pic = pocket_ic();
let wasm = cargo_build_canister("reverse");
let canister_id = pic.create_canister();
pic.add_cycles(canister_id, 2_000_000_000_000);
Expand Down
8 changes: 5 additions & 3 deletions e2e-tests/tests/simple_kv_store.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use ic_cdk_e2e_tests::cargo_build_canister;
use pocket_ic::common::rest::RawEffectivePrincipal;
use pocket_ic::{call_candid, query_candid, PocketIc};
use pocket_ic::{call_candid, query_candid};
use serde_bytes::ByteBuf;

mod test_utilities;
use test_utilities::{cargo_build_canister, pocket_ic};

/// Checks that a canister that uses [`ic_cdk::storage::stable_save`]
/// and [`ic_cdk::storage::stable_restore`] functions can keep its data
/// across upgrades.
#[test]
fn test_storage_roundtrip() {
let pic = PocketIc::new();
let pic = pocket_ic();
let wasm = cargo_build_canister("simple_kv_store");
let canister_id = pic.create_canister();
pic.add_cycles(canister_id, 2_000_000_000_000);
Expand Down
Loading

0 comments on commit e2bbc39

Please sign in to comment.