Skip to content

Commit

Permalink
fix: updating wasmer, using new set_tunable function
Browse files Browse the repository at this point in the history
  • Loading branch information
kehiy committed Jan 1, 2024
1 parent 6cd6b50 commit 4a43d63
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
7 changes: 2 additions & 5 deletions tanour/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ edition = "2021"
[dependencies]
byteorder = "1.3"
log = "0.4"
wasmer = { version = "3.1", default-features = false, features = [
"wat",
"singlepass",
] }
wasmer-middlewares = "3.1"
wasmer = { version = "4.2.5", default-features = false, features = ["wat", "singlepass"] }
wasmer-middlewares = "4.2.5"
thiserror = "1.0"
hex = "0.4"
mockall = "0.10"
Expand Down
9 changes: 5 additions & 4 deletions tanour/src/wasmer/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::error::{Error, Result};
use log::debug;
use std::sync::Arc;
use wasmer::{
wasmparser::Operator, BaseTunables, CompilerConfig, EngineBuilder, Module, Pages, Singlepass,
Store, Target,
wasmparser::Operator, BaseTunables, CompilerConfig, EngineBuilder, Module, NativeEngineExt,
Pages, Singlepass, Store, Target,
};
use wasmer_middlewares::Metering;

Expand All @@ -26,8 +26,9 @@ pub fn compile(

let base = BaseTunables::for_target(&Target::default());
let tunables = LimitingTunables::new(base, Pages(memory_limit_page));
let store = Store::new_with_tunables(engine, tunables);
//let store = Store::default();
let store = Store::new(engine);
let store_engine = store.engine();
store_engine.to_owned().set_tunables(tunables);

let module = Module::new(&store, code).map_err(|original| Error::CompileError {
msg: format!("{original}"),
Expand Down
6 changes: 4 additions & 2 deletions tanour/src/wasmer/limiting_tunables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ impl<T: Tunables> Tunables for LimitingTunables<T> {
#[cfg(test)]
mod tests {
use super::*;
use wasmer::Singlepass;
use wasmer::{imports, wat2wasm, BaseTunables, Instance, Memory, Module, Pages, Store, Target};
use wasmer::{NativeEngineExt, Singlepass};

#[test]
fn test_tunables_limit_memory() -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -148,7 +148,9 @@ mod tests {
let tunables = LimitingTunables::new(base, Pages(24));

// Create a store, that holds the engine and our custom tunables
let mut store = Store::new_with_tunables(compiler, tunables);
let mut store = Store::new(compiler);
let engine = store.engine();
engine.to_owned().set_tunables(tunables);

println!("Compiling module...");
let module = Module::new(&store, wasm_bytes)?;
Expand Down
3 changes: 2 additions & 1 deletion tanour/tests/contract_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use hex_literal::hex;
use rand::Rng;
use tanour::{
blockchain_api::MockBlockchainAPI,
contract::{Contract, Params},
Expand All @@ -7,7 +8,7 @@ use test_contract::message::{Error, InstantiateMsg, ProcMsg, QueryMsg, QueryRsp}

fn make_test_contract(wat: &[u8], memory_limit_page: u32, metering_limit: u64) -> Contract {
let code = wat::parse_bytes(wat).unwrap().to_vec();
let address = rand::random();
let address = rand::thread_rng().gen::<[u8; 21]>();
let params = Params {
memory_limit_page,
metering_limit,
Expand Down

0 comments on commit 4a43d63

Please sign in to comment.