Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cosmwasm-vm tests on windows #1369

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ wat = "1.0"
clap = "2.33.3"
rand = "0.8"
leb128 = "0.2"
cfg-if = "1.0.0"

[[bench]]
name = "main"
Expand Down
8 changes: 7 additions & 1 deletion packages/vm/benches/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ const MEMORY_CACHE_SIZE: Size = Size::mebi(200);
const INSTANTIATION_THREADS: usize = 128;
const CONTRACTS: u64 = 10;

static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
cfg_if::cfg_if! {
if #[cfg(windows)] {
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom_windows.wasm");
} else {
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
}
}

fn bench_instance(c: &mut Criterion) {
let mut group = c.benchmark_group("Instance");
Expand Down
8 changes: 7 additions & 1 deletion packages/vm/examples/multi_threaded_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ const DEFAULT_INSTANCE_OPTIONS: InstanceOptions = InstanceOptions {
// Cache
const MEMORY_CACHE_SIZE: Size = Size::mebi(200);

static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
cfg_if::cfg_if! {
if #[cfg(windows)] {
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom_windows.wasm");
} else {
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
}
}

const SAVE_WASM_THREADS: usize = 32;
const INSTANTIATION_THREADS: usize = 2048;
Expand Down
34 changes: 30 additions & 4 deletions packages/vm/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,21 @@ mod tests {
};
const TESTING_MEMORY_CACHE_SIZE: Size = Size::mebi(200);

static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
static IBC_CONTRACT: &[u8] = include_bytes!("../testdata/ibc_reflect.wasm");
cfg_if::cfg_if! {
if #[cfg(windows)] {
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom_windows.wasm");
} else {
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
}
}

cfg_if::cfg_if! {
if #[cfg(windows)] {
static IBC_CONTRACT: &[u8] = include_bytes!("../testdata/ibc_reflect_windows.wasm");
} else {
static IBC_CONTRACT: &[u8] = include_bytes!("../testdata/ibc_reflect.wasm");
}
}

fn default_features() -> HashSet<String> {
features_from_csv("iterator,staking")
Expand Down Expand Up @@ -523,8 +536,21 @@ mod tests {

match cache.load_wasm(&checksum).unwrap_err() {
VmError::CacheErr { msg, .. } => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert!(msg
.starts_with("Error opening Wasm file for reading: No such file or directory"))
cfg_if::cfg_if! {
if #[cfg(windows)] {
assert!(
msg.starts_with(
"Error opening Wasm file for reading: The system cannot find the file specified"
)
)
} else {
assert!(
msg.starts_with(
"Error opening Wasm file for reading: No such file or directory"
)
)
}
}
}
e => panic!("Unexpected error: {:?}", e),
}
Expand Down
16 changes: 14 additions & 2 deletions packages/vm/src/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,13 @@ mod tests {
use crate::testing::{mock_env, mock_info, mock_instance};
use cosmwasm_std::{coins, Empty};

static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
cfg_if::cfg_if! {
if #[cfg(windows)] {
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom_windows.wasm");
} else {
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
}
}

#[test]
fn call_instantiate_works() {
Expand Down Expand Up @@ -685,7 +691,13 @@ mod tests {
Empty, Event, IbcAcknowledgement, IbcOrder, Reply, ReplyOn, SubMsgResponse,
SubMsgResult,
};
static CONTRACT: &[u8] = include_bytes!("../testdata/ibc_reflect.wasm");
cfg_if::cfg_if! {
if #[cfg(windows)] {
static CONTRACT: &[u8] = include_bytes!("../testdata/ibc_reflect_windows.wasm");
} else {
static CONTRACT: &[u8] = include_bytes!("../testdata/ibc_reflect.wasm");
}
}
const IBC_VERSION: &str = "ibc-reflect-v1";
fn setup(
instance: &mut Instance<MockApi, MockStorage, MockQuerier>,
Expand Down
8 changes: 7 additions & 1 deletion packages/vm/src/compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,13 @@ mod tests {
static CONTRACT_0_12: &[u8] = include_bytes!("../testdata/hackatom_0.12.wasm");
static CONTRACT_0_14: &[u8] = include_bytes!("../testdata/hackatom_0.14.wasm");
static CONTRACT_0_15: &[u8] = include_bytes!("../testdata/hackatom_0.15.wasm");
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
cfg_if::cfg_if! {
if #[cfg(windows)] {
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom_windows.wasm");
} else {
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
}
}

fn default_features() -> HashSet<String> {
["staking".to_string()].iter().cloned().collect()
Expand Down
8 changes: 7 additions & 1 deletion packages/vm/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,13 @@ mod tests {
};
use wasmer::{imports, Function, Instance as WasmerInstance};

static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
cfg_if::cfg_if! {
if #[cfg(windows)] {
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom_windows.wasm");
} else {
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
}
}

// prepared data
const INIT_KEY: &[u8] = b"foo";
Expand Down
8 changes: 7 additions & 1 deletion packages/vm/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,13 @@ mod tests {
use crate::testing::{MockApi, MockQuerier, MockStorage};
use crate::wasm_backend::compile;

static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
cfg_if::cfg_if! {
if #[cfg(windows)] {
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom_windows.wasm");
} else {
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
}
}

// prepared data
const KEY1: &[u8] = b"ant";
Expand Down
8 changes: 7 additions & 1 deletion packages/vm/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,13 @@ mod tests {
const KIB: usize = 1024;
const MIB: usize = 1024 * 1024;
const DEFAULT_QUERY_GAS_LIMIT: u64 = 300_000;
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
cfg_if::cfg_if! {
if #[cfg(windows)] {
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom_windows.wasm");
} else {
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
}
}

#[test]
fn required_features_works() {
Expand Down
8 changes: 7 additions & 1 deletion packages/vm/src/static_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ mod tests {
use parity_wasm::elements::Internal;
use wasmer::{Cranelift, Store, Universal};

static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
cfg_if::cfg_if! {
if #[cfg(windows)] {
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom_windows.wasm");
} else {
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
}
}
static CORRUPTED: &[u8] = include_bytes!("../testdata/corrupted.wasm");

#[test]
Expand Down
8 changes: 7 additions & 1 deletion packages/vm/src/wasm_backend/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ pub fn compile(
mod tests {
use super::*;

static CONTRACT: &[u8] = include_bytes!("../../testdata/floaty.wasm");
cfg_if::cfg_if! {
if #[cfg(windows)] {
static CONTRACT: &[u8] = include_bytes!("../../testdata/floaty_windows.wasm");
} else {
static CONTRACT: &[u8] = include_bytes!("../../testdata/floaty.wasm");
}
}

#[test]
fn contract_with_floats_fails_check() {
Expand Down
1 change: 1 addition & 0 deletions packages/vm/testdata/floaty_windows.wasm
1 change: 1 addition & 0 deletions packages/vm/testdata/hackatom_windows.wasm
1 change: 1 addition & 0 deletions packages/vm/testdata/ibc_reflect_windows.wasm