From c0898410d0b4cc55d0e03938e6d824147791a4fa Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Fri, 22 Mar 2019 15:16:47 +0100 Subject: [PATCH 1/2] Remove unrealistic tests --- ethcore/light/src/types/request/batch.rs | 38 ------------------------ 1 file changed, 38 deletions(-) diff --git a/ethcore/light/src/types/request/batch.rs b/ethcore/light/src/types/request/batch.rs index f99b49d2b27..65f1d24ae0d 100644 --- a/ethcore/light/src/types/request/batch.rs +++ b/ethcore/light/src/types/request/batch.rs @@ -274,25 +274,6 @@ mod tests { assert!(batch.next_complete().is_some()); } - #[test] - #[should_panic] - fn batch_tx_index_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::TransactionIndex(IncompleteTransactionIndexRequest { - 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(); - } - #[test] fn batch_receipts_backreference() { let mut builder = Builder::default(); @@ -310,23 +291,4 @@ mod tests { batch.answered += 1; 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(); - } } From a1cd94bad920fc17cbfbca83fd0d06d0eb531a81 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Fri, 22 Mar 2019 17:21:10 +0100 Subject: [PATCH 2/2] Add test that more closely resembles real usage --- ethcore/light/src/types/request/batch.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ethcore/light/src/types/request/batch.rs b/ethcore/light/src/types/request/batch.rs index 65f1d24ae0d..63641b5daa8 100644 --- a/ethcore/light/src/types/request/batch.rs +++ b/ethcore/light/src/types/request/batch.rs @@ -274,6 +274,29 @@ mod tests { assert!(batch.next_complete().is_some()); } + #[test] + fn batch_tx_index_backreference_public_api() { + let mut builder = Builder::default(); + builder.push(Request::HeaderProof(IncompleteHeaderProofRequest { + num: 100.into(), // header proof puts hash at output 0. + })).unwrap(); + builder.push(Request::TransactionIndex(IncompleteTransactionIndexRequest { + hash: Field::BackReference(0, 0), + })).unwrap(); + + let mut batch = builder.build(); + + assert!(batch.next_complete().is_some()); + let hdr_proof_res = header_proof::Response { + proof: vec![], + hash: 12.into(), + td: 21.into(), + }; + batch.supply_response_unchecked(&hdr_proof_res); + + assert!(batch.next_complete().is_some()); + } + #[test] fn batch_receipts_backreference() { let mut builder = Builder::default();