Add a more realistic Batch test (#10511)

* Remove unrealistic tests

* Add test that more closely resembles real usage
This commit is contained in:
Hernando Castano 2019-03-25 10:42:33 +01:00 committed by GitHub
parent 023e511f83
commit 6cf3ba7efd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -275,8 +275,7 @@ mod tests {
} }
#[test] #[test]
#[should_panic] fn batch_tx_index_backreference_public_api() {
fn batch_tx_index_backreference_wrong_output() {
let mut builder = Builder::default(); let mut builder = Builder::default();
builder.push(Request::HeaderProof(IncompleteHeaderProofRequest { builder.push(Request::HeaderProof(IncompleteHeaderProofRequest {
num: 100.into(), // header proof puts hash at output 0. num: 100.into(), // header proof puts hash at output 0.
@ -286,11 +285,16 @@ mod tests {
})).unwrap(); })).unwrap();
let mut batch = builder.build(); let mut batch = builder.build();
batch.requests[1].fill(|_req_idx, _out_idx| Ok(Output::Number(42)));
batch.next_complete(); assert!(batch.next_complete().is_some());
batch.answered += 1; let hdr_proof_res = header_proof::Response {
batch.next_complete(); proof: vec![],
hash: 12.into(),
td: 21.into(),
};
batch.supply_response_unchecked(&hdr_proof_res);
assert!(batch.next_complete().is_some());
} }
#[test] #[test]
@ -310,23 +314,4 @@ mod tests {
batch.answered += 1; batch.answered += 1;
assert!(batch.next_complete().is_some()); assert!(batch.next_complete().is_some());
} }
#[test]
#[should_panic]
fn batch_receipts_backreference_wrong_output() {
let mut builder = Builder::default();
builder.push(Request::HeaderProof(IncompleteHeaderProofRequest {
num: 100.into(), // header proof puts hash at output 0.
})).unwrap();
builder.push(Request::Receipts(IncompleteReceiptsRequest {
hash: Field::BackReference(0, 0),
})).unwrap();
let mut batch = builder.build();
batch.requests[1].fill(|_req_idx, _out_idx| Ok(Output::Number(42)));
batch.next_complete();
batch.answered += 1;
batch.next_complete();
}
} }