1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use nucleus::ribosome::Runtime;
use wasmi::{RuntimeArgs, RuntimeValue, Trap};
pub fn invoke_debug(
runtime: &mut Runtime,
args: &RuntimeArgs,
) -> Result<Option<RuntimeValue>, Trap> {
let payload = runtime.load_utf8_from_args(args);
println!("{}", payload);
runtime
.context
.log(&format!("zome_log:DEBUG: '{}'", payload))
.expect("Logger should work");
Ok(Some(RuntimeValue::I32(0 as i32)))
}
#[cfg(test)]
pub mod tests {
use nucleus::ribosome::{
api::{tests::test_zome_api_function, ZomeApiFunction},
Defn,
};
pub fn test_debug_string() -> String {
"foo".to_string()
}
pub fn test_args_bytes() -> Vec<u8> {
test_debug_string().into_bytes()
}
#[test]
fn test_zome_api_function_debug() {
let (call_result, context) =
test_zome_api_function(ZomeApiFunction::Debug.as_str(), test_args_bytes());
assert!(call_result.is_empty());
assert_eq!(
"[\"zome_log:DEBUG: \\\'foo\\\'\", \"Zome Function \\\'test\\\' returned: Success\"]",
format!("{}", (*context.logger.lock().unwrap()).dump()),
);
}
}