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 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)))
|
||||
.expect("MemoryInstance created successfuly");
|
||||
mem.set(0, initial_content).expect("Successful initialize the memory");
|
||||
@ -269,7 +269,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
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");
|
||||
|
||||
let mut data = [0u8; 2];
|
||||
|
@ -129,12 +129,12 @@ struct MeasuredVariable {
|
||||
pub val: i32,
|
||||
}
|
||||
|
||||
impl ExternalVariableValue<UserErrorWithCode> for MeasuredVariable {
|
||||
impl ExternalVariableValue for MeasuredVariable {
|
||||
fn get(&self) -> RuntimeValue {
|
||||
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()?;
|
||||
Ok(())
|
||||
}
|
||||
@ -156,12 +156,12 @@ impl UserError for UserErrorWithCode {}
|
||||
|
||||
// user function executor
|
||||
struct FunctionExecutor {
|
||||
pub memory: Arc<MemoryInstance<UserErrorWithCode>>,
|
||||
pub memory: Arc<MemoryInstance>,
|
||||
pub values: Vec<i32>,
|
||||
}
|
||||
|
||||
impl UserFunctionExecutor<UserErrorWithCode> for FunctionExecutor {
|
||||
fn execute(&mut self, name: &str, context: CallerContext<UserErrorWithCode>) -> Result<Option<RuntimeValue>, Error<UserErrorWithCode>> {
|
||||
impl UserFunctionExecutor for FunctionExecutor {
|
||||
fn execute(&mut self, name: &str, context: CallerContext) -> Result<Option<RuntimeValue>, Error> {
|
||||
match name {
|
||||
"add" => {
|
||||
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();
|
||||
|
||||
struct OwnMemoryReference {
|
||||
pub memory: RefCell<Option<Arc<MemoryInstance<UserErrorWithCode>>>>,
|
||||
pub memory: RefCell<Option<Arc<MemoryInstance>>>,
|
||||
}
|
||||
struct OwnMemoryExecutor {
|
||||
pub memory_ref: Arc<OwnMemoryReference>,
|
||||
}
|
||||
|
||||
impl UserFunctionExecutor<UserErrorWithCode> for OwnMemoryExecutor {
|
||||
fn execute(&mut self, name: &str, context: CallerContext<UserErrorWithCode>) -> Result<Option<RuntimeValue>, Error<UserErrorWithCode>> {
|
||||
impl UserFunctionExecutor for OwnMemoryExecutor {
|
||||
fn execute(&mut self, name: &str, context: CallerContext) -> Result<Option<RuntimeValue>, Error> {
|
||||
match name {
|
||||
"add" => {
|
||||
let memory = self.memory_ref.memory.borrow_mut().as_ref().expect("initialized before execution; qed").clone();
|
||||
|
Reference in New Issue
Block a user