Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
yanganto opened this issue Jun 8, 2021 · 0 comments · Fixed by #66
Closed
1 task done

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

yanganto opened this issue Jun 8, 2021 · 0 comments · Fixed by #66
Labels
test Enhance the test experience utils Something helps develop ewasm contract

Comments

@yanganto
Copy link
Contributor

yanganto commented Jun 8, 2021

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

@yanganto yanganto added utils Something helps develop ewasm contract test Enhance the test experience labels Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test Enhance the test experience utils Something helps develop ewasm contract
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant