Skip to content

Commit

Permalink
Fix hackatom testing
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed May 11, 2022
1 parent 95f2528 commit 2ba4f84
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
34 changes: 16 additions & 18 deletions contracts/hackatom/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn instantiate(
info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, HackError> {
// deps.api.debug("here we go 🚀");
deps.api.debug("here we go 🚀");

deps.storage.set(
CONFIG_KEY,
Expand All @@ -31,23 +31,6 @@ pub fn instantiate(
})?,
);

// Uncomment your favourite panic case

// panicked at 'Now what?', src/contract.rs:53:5
panic!("Now what?");

// panicked at 'oh no (a = 3)', src/contract.rs:56:5
// let a = 3;
// panic!("oh no (a = {a})");

// panicked at 'attempt to subtract with overflow', src/contract.rs:59:13
// #[allow(arithmetic_overflow)]
// let _ = 5u32 - 8u32;

// panicked at 'no entry found for key', src/contract.rs:62:13
// let map = std::collections::HashMap::<String, String>::new();
// let _ = map["foo"];

// This adds some unrelated event attribute for testing purposes
Ok(Response::new().add_attribute("Let the", "hacking begin"))
}
Expand Down Expand Up @@ -206,7 +189,22 @@ fn do_allocate_large_memory(pages: u32) -> Result<Response, HackError> {
}

fn do_panic() -> Result<Response, HackError> {
// Uncomment your favourite panic case

// panicked at 'This page intentionally faulted', src/contract.rs:53:5
panic!("This page intentionally faulted");

// panicked at 'oh no (a = 3)', src/contract.rs:56:5
// let a = 3;
// panic!("oh no (a = {a})");

// panicked at 'attempt to subtract with overflow', src/contract.rs:59:13
// #[allow(arithmetic_overflow)]
// let _ = 5u32 - 8u32;

// panicked at 'no entry found for key', src/contract.rs:62:13
// let map = std::collections::HashMap::<String, String>::new();
// let _ = map["foo"];
}

fn do_user_errors_in_api_calls(api: &dyn Api) -> Result<Response, HackError> {
Expand Down
2 changes: 1 addition & 1 deletion contracts/hackatom/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ fn execute_panic() {
);
match execute_res.unwrap_err() {
VmError::RuntimeErr { msg, .. } => {
assert_eq!(msg, "Wasmer runtime error: RuntimeError: unreachable")
assert_eq!(msg, "Wasmer runtime error: RuntimeError: Aborted: panicked at 'This page intentionally faulted', src/contract.rs:195:5")
}
err => panic!("Unexpected error: {:?}", err),
}
Expand Down

0 comments on commit 2ba4f84

Please sign in to comment.