rust: add tests for EvmcContainer
@@ -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) };
+ }
+}
