Merge pull request #348 from ethereum/rust-container

rust: add tests for EvmcContainer
This commit is contained in:
Alex Beregszaszi 2019-07-04 18:26:41 +01:00 committed by GitHub
commit 2a5c280206
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 38 additions and 2 deletions

View File

@ -30,8 +30,8 @@ impl<T: EvmcVm + Sized> EvmcContainer<T> {
}
/// Convert boxed self into an FFI pointer, surrendering ownership of the heap data.
pub unsafe fn into_ffi_pointer(boxed: Box<Self>) -> *const ::evmc_sys::evmc_instance {
Box::into_raw(boxed) as *const ::evmc_sys::evmc_instance
pub unsafe fn into_ffi_pointer(boxed: Box<Self>) -> *mut ::evmc_sys::evmc_instance {
Box::into_raw(boxed) as *mut ::evmc_sys::evmc_instance
}
}
@ -45,3 +45,39 @@ where
&self.vm
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::{ExecutionContext, ExecutionResult};
struct TestVm {}
impl EvmcVm for TestVm {
fn init() -> Self {
TestVm {}
}
fn execute(&self, _code: &[u8], _context: &ExecutionContext) -> ExecutionResult {
ExecutionResult::failure()
}
}
#[test]
fn container_new() {
let instance = ::evmc_sys::evmc_instance {
abi_version: ::evmc_sys::EVMC_ABI_VERSION as i32,
name: std::ptr::null(),
version: std::ptr::null(),
destroy: None,
execute: None,
get_capabilities: None,
set_tracer: None,
set_option: None,
};
let container = EvmcContainer::<TestVm>::new(instance);
let ptr = unsafe { EvmcContainer::into_ffi_pointer(Box::new(container)) };
unsafe { EvmcContainer::<TestVm>::from_ffi_pointer(ptr) };
}
}