mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-26 05:02:03 +00:00
Fix tests
This commit is contained in:
@ -208,7 +208,7 @@ mod tests {
|
|||||||
use elements::MemoryType;
|
use elements::MemoryType;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
fn create_memory(initial_content: &[u8]) -> Arc<MemoryInstance<DummyUserError>> {
|
fn create_memory(initial_content: &[u8]) -> Arc<MemoryInstance> {
|
||||||
let mem = MemoryInstance::new(&MemoryType::new(1, Some(1)))
|
let mem = MemoryInstance::new(&MemoryType::new(1, Some(1)))
|
||||||
.expect("MemoryInstance created successfuly");
|
.expect("MemoryInstance created successfuly");
|
||||||
mem.set(0, initial_content).expect("Successful initialize the memory");
|
mem.set(0, initial_content).expect("Successful initialize the memory");
|
||||||
@ -269,7 +269,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn get_into() {
|
fn get_into() {
|
||||||
let mem = MemoryInstance::<DummyUserError>::new(&MemoryType::new(1, None)).expect("memory instance creation should not fail");
|
let mem = MemoryInstance::new(&MemoryType::new(1, None)).expect("memory instance creation should not fail");
|
||||||
mem.set(6, &[13, 17, 129]).expect("memory set should not fail");
|
mem.set(6, &[13, 17, 129]).expect("memory set should not fail");
|
||||||
|
|
||||||
let mut data = [0u8; 2];
|
let mut data = [0u8; 2];
|
||||||
|
@ -129,12 +129,12 @@ struct MeasuredVariable {
|
|||||||
pub val: i32,
|
pub val: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExternalVariableValue<UserErrorWithCode> for MeasuredVariable {
|
impl ExternalVariableValue for MeasuredVariable {
|
||||||
fn get(&self) -> RuntimeValue {
|
fn get(&self) -> RuntimeValue {
|
||||||
RuntimeValue::I32(self.val)
|
RuntimeValue::I32(self.val)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set(&mut self, val: RuntimeValue) -> Result<(), Error<UserErrorWithCode>> {
|
fn set(&mut self, val: RuntimeValue) -> Result<(), Error> {
|
||||||
self.val = val.try_into()?;
|
self.val = val.try_into()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -156,12 +156,12 @@ impl UserError for UserErrorWithCode {}
|
|||||||
|
|
||||||
// user function executor
|
// user function executor
|
||||||
struct FunctionExecutor {
|
struct FunctionExecutor {
|
||||||
pub memory: Arc<MemoryInstance<UserErrorWithCode>>,
|
pub memory: Arc<MemoryInstance>,
|
||||||
pub values: Vec<i32>,
|
pub values: Vec<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UserFunctionExecutor<UserErrorWithCode> for FunctionExecutor {
|
impl UserFunctionExecutor for FunctionExecutor {
|
||||||
fn execute(&mut self, name: &str, context: CallerContext<UserErrorWithCode>) -> Result<Option<RuntimeValue>, Error<UserErrorWithCode>> {
|
fn execute(&mut self, name: &str, context: CallerContext) -> Result<Option<RuntimeValue>, Error> {
|
||||||
match name {
|
match name {
|
||||||
"add" => {
|
"add" => {
|
||||||
let memory_value = self.memory.get(0, 1).unwrap()[0];
|
let memory_value = self.memory.get(0, 1).unwrap()[0];
|
||||||
@ -259,14 +259,14 @@ fn native_env_function_own_memory() {
|
|||||||
let program = ProgramInstance::new().unwrap();
|
let program = ProgramInstance::new().unwrap();
|
||||||
|
|
||||||
struct OwnMemoryReference {
|
struct OwnMemoryReference {
|
||||||
pub memory: RefCell<Option<Arc<MemoryInstance<UserErrorWithCode>>>>,
|
pub memory: RefCell<Option<Arc<MemoryInstance>>>,
|
||||||
}
|
}
|
||||||
struct OwnMemoryExecutor {
|
struct OwnMemoryExecutor {
|
||||||
pub memory_ref: Arc<OwnMemoryReference>,
|
pub memory_ref: Arc<OwnMemoryReference>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UserFunctionExecutor<UserErrorWithCode> for OwnMemoryExecutor {
|
impl UserFunctionExecutor for OwnMemoryExecutor {
|
||||||
fn execute(&mut self, name: &str, context: CallerContext<UserErrorWithCode>) -> Result<Option<RuntimeValue>, Error<UserErrorWithCode>> {
|
fn execute(&mut self, name: &str, context: CallerContext) -> Result<Option<RuntimeValue>, Error> {
|
||||||
match name {
|
match name {
|
||||||
"add" => {
|
"add" => {
|
||||||
let memory = self.memory_ref.memory.borrow_mut().as_ref().expect("initialized before execution; qed").clone();
|
let memory = self.memory_ref.memory.borrow_mut().as_ref().expect("initialized before execution; qed").clone();
|
||||||
|
Reference in New Issue
Block a user