diff --git a/bindings/rust/evmc-vm/src/container.rs b/bindings/rust/evmc-vm/src/container.rs index e81d0c6..d3513d9 100644 --- a/bindings/rust/evmc-vm/src/container.rs +++ b/bindings/rust/evmc-vm/src/container.rs @@ -30,8 +30,8 @@ impl EvmcContainer { } /// Convert boxed self into an FFI pointer, surrendering ownership of the heap data. - pub unsafe fn into_ffi_pointer(boxed: Box) -> *const ::evmc_sys::evmc_instance { - Box::into_raw(boxed) as *const ::evmc_sys::evmc_instance + pub unsafe fn into_ffi_pointer(boxed: Box) -> *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::::new(instance); + + let ptr = unsafe { EvmcContainer::into_ffi_pointer(Box::new(container)) }; + + unsafe { EvmcContainer::::from_ffi_pointer(ptr) }; + } +}