Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: RUN-1022: Add execution smoke tests #526

Merged
merged 2 commits into from
Jul 23, 2024
Merged
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
1 change: 1 addition & 0 deletions rs/execution_environment/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ rust_ic_test_suite(
size = "large",
srcs = glob(["tests/*.rs"]),
aliases = ALIASES,
compile_data = glob(["tests/test-data/**"]),
data = DATA,
env = ENV,
proc_macro_deps = MACRO_DEPENDENCIES + MACRO_DEV_DEPENDENCIES,
Expand Down
123 changes: 123 additions & 0 deletions rs/execution_environment/tests/smoke.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
use candid::{decode_one, encode_args, CandidType};
use ic_management_canister_types::{EmptyBlob, Payload};
use ic_state_machine_tests::{StateMachine, WasmResult};
use serde::Deserialize;

// https://github.com/dfinity/motoko/blob/master/test/perf/qr.mo
const QR: &[u8] = include_bytes!("test-data/qr.wasm");

// https://github.com/crusso/motoko-gc-limits#scalability-suite
const COMPACTING_GC: &[u8] = include_bytes!("test-data/compacting-gc.wasm.gz");
const COPYING_GC: &[u8] = include_bytes!("test-data/copying-gc.wasm.gz");

// https://github.com/dfinity/motoko/blob/master/test/perf/sha256.mo
const SHA256: &[u8] = include_bytes!("test-data/sha256.wasm");

// https://github.com/dfinity/examples/tree/master/rust/image-classification
const IMAGE_CLASSIFICATION: &[u8] = include_bytes!("test-data/image-classification.wasm.gz");

#[test]
fn qr() {
let env = StateMachine::new();
let arg = encode_args(()).unwrap();
let qr = env
.install_canister(QR.to_vec(), arg.clone(), None)
.unwrap();
let reply = env.execute_ingress(qr, "go", arg).unwrap();
assert_eq!(reply, WasmResult::Reply(EmptyBlob.encode()));
}

#[test]
fn compacting_gc() {
let env = StateMachine::new();
let compacting_gc = env
.install_canister(COMPACTING_GC.to_vec(), encode_args(()).unwrap(), None)
.unwrap();
let arg = vec![
0x44, 0x49, 0x44, 0x4c, 0x01, 0x6b, 0x01, 0xfb, 0x91, 0xc0, 0x43, 0x7f, 0x02, 0x7d, 0x00,
0x80, 0x10, 0x00,
];
let reply = env.execute_ingress(compacting_gc, "step", arg).unwrap();
assert_eq!(reply, WasmResult::Reply(EmptyBlob.encode()));
}

#[test]
fn copying_gc() {
let env = StateMachine::new();
let copying_gc = env
.install_canister(COPYING_GC.to_vec(), encode_args(()).unwrap(), None)
.unwrap();
let arg = vec![
0x44, 0x49, 0x44, 0x4c, 0x01, 0x6b, 0x01, 0xfb, 0x91, 0xc0, 0x43, 0x7f, 0x02, 0x7d, 0x00,
0x80, 0x10, 0x00,
];
let reply = env.execute_ingress(copying_gc, "step", arg).unwrap();
assert_eq!(reply, WasmResult::Reply(EmptyBlob.encode()));
}

#[test]
fn sha256() {
let env = StateMachine::new();
let sha256 = env
.install_canister(SHA256.to_vec(), encode_args(()).unwrap(), None)
.unwrap();
let reply = env
.execute_ingress(sha256, "go", encode_args(()).unwrap())
.unwrap();
assert_eq!(reply, WasmResult::Reply(EmptyBlob.encode()));
}

#[derive(CandidType, Deserialize, PartialEq, Debug)]
struct Classification {
label: String,
score: f32,
}

#[derive(CandidType, Deserialize, PartialEq, Debug)]
struct ClassificationError {
message: String,
}

#[derive(CandidType, Deserialize, PartialEq, Debug)]
enum ClassificationResult {
Ok(Vec<Classification>),
Err(ClassificationError),
}

#[test]
fn image_classification() {
let env = StateMachine::new();
let image_classification = env
.install_canister(
IMAGE_CLASSIFICATION.to_vec(),
encode_args(()).unwrap(),
None,
)
.unwrap();
let reply = env
.execute_ingress(image_classification, "run", encode_args(()).unwrap())
.unwrap();
match reply {
WasmResult::Reply(data) => {
let res: ClassificationResult = decode_one(&data).unwrap();
assert_eq!(
res,
ClassificationResult::Ok(vec![
Classification {
label: "tractor".to_string(),
score: 17.631065,
},
Classification {
label: "plow".to_string(),
score: 16.184143,
},
Classification {
label: "harvester".to_string(),
score: 14.577676,
}
])
);
}
WasmResult::Reject(err) => unreachable!("Unexpected: {}", err),
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.