diff --git a/lib/api/tests/import_function.rs b/lib/api/tests/import_function.rs index 7e1737fec57..bb3199f5c11 100644 --- a/lib/api/tests/import_function.rs +++ b/lib/api/tests/import_function.rs @@ -47,6 +47,48 @@ fn pass_i64_between_host_and_plugin() -> Result<(), String> { Ok(()) } +#[universal_test] +fn pass_u64_between_host_and_plugin() -> Result<(), String> { + let mut store = Store::default(); + + let wat = r#"(module + (func $add_one_u64 (import "host" "add_one_u64") (param i64) (result i64)) + (func (export "add_three_u64") (param i64) (result i64) + (i64.add (call $add_one_u64 (i64.add (local.get 0) (i64.const 1))) (i64.const 1)) + ) + )"#; + let module = Module::new(&store, wat).map_err(|e| format!("{e:?}"))?; + + let imports = { + imports! { + "host" => { + "add_one_u64" => Function::new_typed(&mut store, |value: u64| value.wrapping_add(1)), + }, + } + }; + + let instance = Instance::new(&mut store, &module, &imports).map_err(|e| format!("{e:?}"))?; + let add_three_u64 = instance + .exports + .get_typed_function::(&store, "add_three_u64") + .map_err(|e| format!("{e:?}"))?; + + let mut numbers = Vec::::new(); + numbers.extend(0..=4); + numbers.extend((u64::MAX / 2 - 4)..=(u64::MAX / 2 + 4)); + numbers.extend((u64::MAX - 4)..=u64::MAX); + + for number in numbers { + let wasm_result = add_three_u64 + .call(&mut store, number) + .map_err(|e| format!("{e:?}"))?; + let compare_result = number.wrapping_add(3); + + assert_eq!(wasm_result, compare_result) + } + Ok(()) +} + #[universal_test] fn calling_function_exports() -> Result<()> { let mut store = Store::default();