mirror of https://github.com/status-im/evmc.git
rust: add tests for EvmcContainer
This commit is contained in:
parent
cab1073407
commit
6391748c9c
|
@ -30,8 +30,8 @@ impl<T: EvmcVm + Sized> EvmcContainer<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert boxed self into an FFI pointer, surrendering ownership of the heap data.
|
/// 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 {
|
pub unsafe fn into_ffi_pointer(boxed: Box<Self>) -> *mut ::evmc_sys::evmc_instance {
|
||||||
Box::into_raw(boxed) as *const ::evmc_sys::evmc_instance
|
Box::into_raw(boxed) as *mut ::evmc_sys::evmc_instance
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,3 +45,39 @@ where
|
||||||
&self.vm
|
&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) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue