Provide macro for exporting functions from wasm (#3801)

The macro generates the functions with the signature we expect for wasm
functions. This macro is useful for tests where we need to call into
wasm. Parameter passing is done by SCALE encoding the input and output
parameters.
This commit is contained in:
Bastian Köcher
2019-10-14 20:20:07 +02:00
committed by GitHub
parent b989c6f9ba
commit e3ae647c42
5 changed files with 312 additions and 144 deletions
+18 -18
View File
@@ -631,11 +631,11 @@ mod tests {
call $assert
)
)
"#).unwrap();
"#).unwrap().encode();
assert_eq!(
call_wasm(&mut ext, 8, &test_code[..], "test_sandbox", &code).unwrap(),
vec![1],
true.encode(),
);
}
@@ -673,7 +673,7 @@ mod tests {
call $assert
)
)
"#).unwrap();
"#).unwrap().encode();
let res = call_wasm(&mut ext, 8, &test_code[..], "test_exhaust_heap", &code);
assert_eq!(res.is_err(), true);
@@ -718,11 +718,11 @@ mod tests {
call $assert
)
)
"#).unwrap();
"#).unwrap().encode();
assert_eq!(
call_wasm(&mut ext, 8, &test_code[..], "test_sandbox", &code).unwrap(),
vec![1],
true.encode(),
);
}
@@ -752,11 +752,11 @@ mod tests {
)
)
)
"#).unwrap();
"#).unwrap().encode();
assert_eq!(
call_wasm(&mut ext, 8, &test_code[..], "test_sandbox_args", &code).unwrap(),
vec![1],
true.encode(),
);
}
@@ -774,11 +774,11 @@ mod tests {
)
)
)
"#).unwrap();
"#).unwrap().encode();
assert_eq!(
call_wasm(&mut ext, 8, &test_code[..], "test_sandbox_return_val", &code).unwrap(),
vec![1],
true.encode(),
);
}
@@ -794,11 +794,11 @@ mod tests {
(func (export "call")
)
)
"#).unwrap();
"#).unwrap().encode();
assert_eq!(
call_wasm(&mut ext, 8, &test_code[..], "test_sandbox_instantiate", &code).unwrap(),
vec![1],
1u8.encode(),
);
}
@@ -808,11 +808,11 @@ mod tests {
let test_code = WASM_BINARY;
// Corrupted wasm file
let code = &[0, 0, 0, 0, 1, 0, 0, 0];
let code = vec![0u8, 0, 0, 0, 1, 0, 0, 0].encode();
assert_eq!(
call_wasm(&mut ext, 8, &test_code[..], "test_sandbox_instantiate", code).unwrap(),
vec![1],
call_wasm(&mut ext, 8, &test_code[..], "test_sandbox_instantiate", &code).unwrap(),
1u8.encode(),
);
}
@@ -831,11 +831,11 @@ mod tests {
(start $start)
)
"#).unwrap();
"#).unwrap().encode();
assert_eq!(
call_wasm(&mut ext, 8, &test_code[..], "test_sandbox_instantiate", &code).unwrap(),
vec![0],
0u8.encode(),
);
}
@@ -855,11 +855,11 @@ mod tests {
(start $start)
)
"#).unwrap();
"#).unwrap().encode();
assert_eq!(
call_wasm(&mut ext, 8, &test_code[..], "test_sandbox_instantiate", &code).unwrap(),
vec![2],
2u8.encode(),
);
}
}