Skip to content

Commit

Permalink
Don't run proptests in wasm32-unknown-unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus23 committed Aug 22, 2023
1 parent 2b2fd44 commit ab7a469
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 38 deletions.
3 changes: 0 additions & 3 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
65 changes: 34 additions & 31 deletions tests/car_writer_bytes_test.rs
Original file line number Diff line number Diff line change
@@ -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<Value = Cid> {
vec(any::<u8>(), 0..64)
.prop_map(|hash_bytes| Cid::new_v1(0x55, Multihash::wrap(0x00, &hash_bytes).unwrap()))
}
fn identity_hash_cid() -> impl Strategy<Value = Cid> {
vec(any::<u8>(), 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::<u8>(), 0..1_000), 0..100))] blocks: Vec<Vec<u8>>,
#[strategy(vec(identity_hash_cid(), 1..100))] roots: Vec<Cid>,
) {
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::<u8>(), 0..1_000), 0..100))] blocks: Vec<Vec<u8>>,
#[strategy(vec(identity_hash_cid(), 1..100))] roots: Vec<Cid>,
) {
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);
}
}

0 comments on commit ab7a469

Please sign in to comment.