Fix tests

This commit is contained in:
Sergey Pepyakin
2017-11-25 23:06:19 +03:00
parent 5b9e1f04ba
commit ea980415f6
2 changed files with 10 additions and 10 deletions

View File

@ -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];

View File

@ -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();