Closed
Description
It is good and clear for a user building ewasm contract in a single file.
#[derive(Default, Serialize, Deserialize)]
struct SimpleStruct {
trust: bool,
description: String,
}
#[ewasm_fn]
fn check_input_object(s: SimpleStruct) -> Result<()> {
if !s.trust {
return Err(Error::NotTrustedInput.into());
}
Ok(())
}
#[ewasm_main]
fn main() -> Result<()> {
let contract = Contract::new()?;
match contract.get_function_selector()? {
fn_sig!(check_input_object) => input_from!(contract, check_input_object)?,
_ => return Err(Error::UnknownHandle.into()),
};
Ok(())
}
#[ewasm_test]
mod tests {
#[ewasm_test]
fn test_execute_basic_operation() {
let mut simple_struct = SimpleStruct::default();
ewasm_assert_eq!(
check_input_object(simple_struct),
vec![110, 111, 116, 32, 116, 114, 117, 115, 116, 32, 105, 110, 112, 117, 116]
)
}
}
Additional issues need to be solved and figure out before implementing
- The mod test is built with target
x86_64-unknown-linux-gnu
, and the other part is built with targetwasm32-unknown-unknown
, becausewasmedge
and the runtime environment only worksx86_64-unknown-linux-gnu
but notwasm32-unknown-unknown
Relating references