diff --git a/Cargo.lock b/Cargo.lock index 5cd871e..a756b2c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -395,10 +395,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ "cfg-if", - "js-sys", "libc", "wasi", - "wasm-bindgen", ] [[package]] @@ -414,7 +412,6 @@ dependencies = [ "anyhow", "cid", "futures", - "getrandom", "libipld", "multihash", "proptest", diff --git a/Cargo.toml b/Cargo.toml index 732bb8e..58e4767 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,17 +18,17 @@ ipld = { package = "libipld", version = "0.16", features = ["dag-cbor", "derive" thiserror = "1" tokio = { version = "^1", features = ["io-util"] } unsigned-varint = "0.7.1" -getrandom = { version = "0.2", features = ["js"] } [dev-dependencies] multihash = "0.18" tokio = { version = "^1", features = ["macros", "sync", "rt", "io-util"] } -proptest = "1.1" -test-strategy = "0.3" - [features] default = [] [target.'cfg(target_arch = "wasm32")'.dev-dependencies] wasm-bindgen-test = { version = "^0.3" } + +[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] +proptest = "1.1" +test-strategy = "0.3" diff --git a/tests/car_writer_bytes_test.rs b/tests/car_writer_bytes_test.rs index 5457789..88d1984 100644 --- a/tests/car_writer_bytes_test.rs +++ b/tests/car_writer_bytes_test.rs @@ -1,35 +1,38 @@ -use cid::Cid; -use iroh_car::*; -use multihash::{Code, Multihash, MultihashDigest}; -use proptest::{collection::vec, prelude::any, prop_assert_eq, strategy::Strategy}; -use test_strategy::proptest; +#[cfg(not(target_arch = "wasm32"))] +mod proptests { + use cid::Cid; + use iroh_car::*; + use multihash::{Code, Multihash, MultihashDigest}; + use proptest::{collection::vec, prelude::any, prop_assert_eq, strategy::Strategy}; + use test_strategy::proptest; -fn identity_hash_cid() -> impl Strategy { - vec(any::(), 0..64) - .prop_map(|hash_bytes| Cid::new_v1(0x55, Multihash::wrap(0x00, &hash_bytes).unwrap())) -} + fn identity_hash_cid() -> impl Strategy { + vec(any::(), 0..64) + .prop_map(|hash_bytes| Cid::new_v1(0x55, Multihash::wrap(0x00, &hash_bytes).unwrap())) + } -#[proptest(max_shrink_iters = 1_000_000)] -fn write_returns_bytes_written( - #[strategy(vec(vec(any::(), 0..1_000), 0..100))] blocks: Vec>, - #[strategy(vec(identity_hash_cid(), 1..100))] roots: Vec, -) { - let (supposedly_written, actually_written) = tokio::runtime::Builder::new_current_thread() - .enable_all() - .build() - .expect("Failed building the Runtime") - .block_on(async move { - let mut writer = CarWriter::new(CarHeader::new_v1(roots), Vec::new()); - let mut written = 0; - written += writer.write_header().await.unwrap(); - for block in blocks { - let hash = Code::Blake3_256.digest(&block); - let cid = Cid::new_v1(0x55, hash); - written += writer.write(cid, block).await.unwrap(); - } - let buffer = writer.finish().await.unwrap(); - (written, buffer.len()) - }); + #[proptest(max_shrink_iters = 1_000_000)] + fn write_returns_bytes_written( + #[strategy(vec(vec(any::(), 0..1_000), 0..100))] blocks: Vec>, + #[strategy(vec(identity_hash_cid(), 1..100))] roots: Vec, + ) { + let (supposedly_written, actually_written) = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .expect("Failed building the Runtime") + .block_on(async move { + let mut writer = CarWriter::new(CarHeader::new_v1(roots), Vec::new()); + let mut written = 0; + written += writer.write_header().await.unwrap(); + for block in blocks { + let hash = Code::Blake3_256.digest(&block); + let cid = Cid::new_v1(0x55, hash); + written += writer.write(cid, block).await.unwrap(); + } + let buffer = writer.finish().await.unwrap(); + (written, buffer.len()) + }); - prop_assert_eq!(supposedly_written, actually_written); + prop_assert_eq!(supposedly_written, actually_written); + } }