Skip to content

Commit

Permalink
rust: add test for ExecutionResult without data
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Apr 23, 2019
1 parent 6be5dae commit 0d757c4
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion bindings/rust/evmc-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl Into<*const ffi::evmc_result> for ExecutionResult {
extern "C" fn release_result(result: *const ffi::evmc_result) {
unsafe {
let tmp = Box::from_raw(result as *mut ffi::evmc_result);
if tmp.output_data.is_null() {
if !tmp.output_data.is_null() {
let buf_layout =
std::alloc::Layout::from_size_align(tmp.output_size, 1).expect("Bad layout");
std::alloc::dealloc(tmp.output_data as *mut u8, buf_layout);
Expand Down Expand Up @@ -196,4 +196,27 @@ mod tests {
}
}
}

#[test]
fn into_ffi_empty_data() {
let r = ExecutionResult::new(
ffi::evmc_status_code::EVMC_FAILURE,
420,
None,
ffi::evmc_address { bytes: [0u8; 20] },
);

let f: *const ffi::evmc_result = r.into();
assert!(!f.is_null());
unsafe {
assert!((*f).status_code == ffi::evmc_status_code::EVMC_FAILURE);
assert!((*f).gas_left == 420);
assert!((*f).output_data.is_null());
assert!((*f).output_size == 0);
assert!((*f).create_address.bytes == [0u8; 20]);
if (*f).release.is_some() {
(*f).release.unwrap()(f);
}
}
}
}

0 comments on commit 0d757c4

Please # to comment.