Files
wasmer/tests/compilers/deterministic.rs
Syrus Akbary a419ccdf52 Move Webassembly objects to Store and remove Context
Co-authored-by: ptitSeb <sebastien.chev@gmail.com>
Co-authored-by: Manos Pitsidianakis <manos@wasmer.io>
2022-07-19 15:31:51 +03:00

45 lines
814 B
Rust

use anyhow::Result;
use wasmer::{wat2wasm, Module, Store};
fn compile_and_compare(wasm: &[u8]) -> Result<()> {
let store = Store::default();
// compile for first time
let module = Module::new(&store, wasm)?;
let first = module.serialize()?;
// compile for second time
let module = Module::new(&store, wasm)?;
let second = module.serialize()?;
assert!(first == second);
Ok(())
}
#[test]
fn deterministic_empty() -> Result<()> {
let wasm_bytes = wat2wasm(
br#"
(module)
"#,
)?;
compile_and_compare(&wasm_bytes)
}
#[test]
fn deterministic_table() -> Result<()> {
let wasm_bytes = wat2wasm(
br#"
(module
(table 2 funcref)
(func $f1)
(func $f2)
(elem (i32.const 0) $f1 $f2))
"#,
)?;
compile_and_compare(&wasm_bytes)
}