Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

Commit

Permalink
Ready for review.
Browse files Browse the repository at this point in the history
  • Loading branch information
YaronWittenstein committed Jul 13, 2021
1 parent a41ecfb commit 9958d90
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
2 changes: 2 additions & 0 deletions crates/runtime/src/runtime/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ where

// Registering the externals provided to the Runtime
let (name, exports) = &self.imports;
debug_assert_ne!(name, "sm");

import_object.register(name, exports.clone());

import_object
Expand Down
16 changes: 0 additions & 16 deletions crates/runtime/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,6 @@ impl<'a> From<&'a [u8]> for WasmFile<'a> {
}
}

/// Creates a new `Wasmer Store`
pub fn wasmer_store() -> Store {
svm_compiler::new_store()
}

/// Creates a new `Wasmer Memory` consisting of a single page
/// The memory is of type non-shared and can grow without a limit
pub fn wasmer_memory(store: &Store) -> Memory {
let min = Pages(1);
let max = None;
let shared = false;
let ty = MemoryType::new(min, max, shared);

Memory::new(store, ty).expect("Memory allocation has failed.")
}

/// Compiles a wasm program in text format (a.k.a WAST) into a `Module` (`wasmer`)
pub fn wasmer_compile(store: &Store, wasm_file: WasmFile, gas_limit: Gas) -> Module {
let wasm = wasm_file.into_bytes();
Expand Down
34 changes: 25 additions & 9 deletions crates/runtime/tests/vmcalls_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ use svm_layout::{FixedLayout, Id};
use svm_runtime::{testing, vmcalls, Context};
use svm_types::{Address, Gas, ReceiptLog};

/// Creates a new `Wasmer Store`
pub fn wasmer_store() -> wasmer::Store {
svm_compiler::new_store()
}

/// Creates a new `Wasmer Memory` consisting of a single page
/// The memory is of type non-shared and can grow without a limit
fn wasmer_memory(store: &wasmer::Store) -> wasmer::Memory {
let min = wasmer::Pages(1);
let max = None;
let shared = false;
let ty = wasmer::MemoryType::new(min, max, shared);

wasmer::Memory::new(store, ty).expect("Memory allocation has failed.")
}

macro_rules! assert_vars32 {
($instance:expr, $( $var_id:expr => $expected:expr), *) => {{
__assert_vars_impl!(u32, $instance, $( $var_id => $expected), *)
Expand Down Expand Up @@ -74,7 +90,7 @@ fn vmcalls_empty_wasm() {

let gas_limit = Gas::new();

let store = testing::wasmer_store();
let store = wasmer_store();
let import_object = imports! {};

testing::wasmer_instantiate(&store, &import_object, wasm, gas_limit);
Expand All @@ -87,7 +103,7 @@ fn vmcalls_get32_set32() {
let gas_limit = Gas::new();
let layout: FixedLayout = vec![4, 2].into();

let store = testing::wasmer_store();
let store = wasmer_store();
let storage = testing::blank_storage(&app_addr, &layout);

let ctx = Context::new(gas_limit, storage, &template_addr.into(), &app_addr.into());
Expand Down Expand Up @@ -123,7 +139,7 @@ fn vmcalls_get64_set64() {
let gas_limit = Gas::new();
let layout: FixedLayout = vec![4, 2].into();

let store = testing::wasmer_store();
let store = wasmer_store();
let storage = testing::blank_storage(&app_addr, &layout);
let ctx = Context::new(gas_limit, storage, &template_addr.into(), &app_addr.into());

Expand Down Expand Up @@ -158,8 +174,8 @@ fn vmcalls_load160() {
let gas_limit = Gas::new();
let layout: FixedLayout = vec![20].into();

let store = testing::wasmer_store();
let memory = testing::wasmer_memory(&store);
let store = wasmer_store();
let memory = wasmer_memory(&store);
let storage = testing::blank_storage(&app_addr, &layout);

let ctx = Context::new_with_memory(
Expand Down Expand Up @@ -209,8 +225,8 @@ fn vmcalls_store160() {
let gas_limit = Gas::new();
let layout: FixedLayout = vec![20].into();

let store = testing::wasmer_store();
let memory = testing::wasmer_memory(&store);
let store = wasmer_store();
let memory = wasmer_memory(&store);
let storage = testing::blank_storage(&app_addr, &layout);
let ctx = Context::new_with_memory(
memory.clone(),
Expand Down Expand Up @@ -255,8 +271,8 @@ fn vmcalls_log() {
let gas_limit = Gas::new();
let layout = FixedLayout::default();

let store = testing::wasmer_store();
let memory = testing::wasmer_memory(&store);
let store = wasmer_store();
let memory = wasmer_memory(&store);
let storage = testing::blank_storage(&app_addr, &layout);
let ctx = Context::new_with_memory(
memory.clone(),
Expand Down

0 comments on commit 9958d90

Please sign in to comment.