Skip to content

Commit

Permalink
chore: Test more lines in messages.rs: indicates_finished
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus23 committed Mar 4, 2024
1 parent daf6edb commit c9dfd64
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions car-mirror/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,21 @@ mod test {
use wnfs_common::MemoryBlockStore;
use wnfs_unixfs_file::builder::FileBuilder;

async fn example_receiver_state() -> Result<ReceiverState> {
async fn loaded_receiver_state() -> Result<ReceiverState> {
let store = &MemoryBlockStore::new();

let root_cid = FileBuilder::new()
.content_bytes(vec![42; 500_000])
.build()?
.store(store)
.await?;

let dag = IncrementalDagVerification::new([root_cid], store, &NoCache).await?;

Ok(dag.into_receiver_state(Config::default().bloom_fpr))
}

async fn partial_receiver_state() -> Result<ReceiverState> {
let store = &MemoryBlockStore::new();
let store2 = &MemoryBlockStore::new();

Expand All @@ -118,7 +132,7 @@ mod test {

#[test_log::test(async_std::test)]
async fn test_encoding_format_json_concise() -> TestResult {
let receiver_state = example_receiver_state().await?;
let receiver_state = partial_receiver_state().await?;
let pull_request: PullRequest = receiver_state.clone().into();
let push_response: PushResponse = receiver_state.into();

Expand All @@ -132,7 +146,7 @@ mod test {

#[test_log::test(async_std::test)]
async fn test_dag_cbor_roundtrip() -> TestResult {
let receiver_state = example_receiver_state().await?;
let receiver_state = partial_receiver_state().await?;
let pull_request: PullRequest = receiver_state.clone().into();
let push_response: PushResponse = receiver_state.into();

Expand All @@ -144,4 +158,32 @@ mod test {

Ok(())
}

#[test_log::test(async_std::test)]
async fn test_pull_request_have_everything_indicates_finished() -> TestResult {
let pull_request: PullRequest = loaded_receiver_state().await?.into();
assert!(pull_request.indicates_finished());
Ok(())
}

#[test_log::test(async_std::test)]
async fn test_push_response_have_everything_indicates_finished() -> TestResult {
let push_response: PushResponse = loaded_receiver_state().await?.into();
assert!(push_response.indicates_finished());
Ok(())
}

#[test_log::test(async_std::test)]
async fn test_pull_request_partial_indicates_not_finished() -> TestResult {
let pull_request: PullRequest = partial_receiver_state().await?.into();
assert!(!pull_request.indicates_finished());
Ok(())
}

#[test_log::test(async_std::test)]
async fn test_push_response_partial_indicates_not_finished() -> TestResult {
let push_response: PushResponse = partial_receiver_state().await?.into();
assert!(!push_response.indicates_finished());
Ok(())
}
}

0 comments on commit c9dfd64

Please sign in to comment.