-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't run proptests in wasm32-unknown-unknown
- Loading branch information
Showing
3 changed files
with
38 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |