Skip to content

Design and implement a way to help user setup the test environment #46

Closed
@yanganto

Description

@yanganto

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 target wasm32-unknown-unknown, because wasmedge and the runtime environment only works x86_64-unknown-linux-gnu but not wasm32-unknown-unknown

Relating references

Metadata

Metadata

Assignees

No one assigned

    Labels

    testEnhance the test experienceutilsSomething helps develop ewasm contract

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions