request builder tests

This commit is contained in:
Robert Habermeier 2017-03-08 20:07:45 +01:00
parent d9087dd2b6
commit aea9b1d6cc
2 changed files with 52 additions and 2 deletions

View File

@ -114,3 +114,53 @@ impl Requests {
/// Get access to the underlying slice of requests. /// Get access to the underlying slice of requests.
pub fn requests(&self) -> &[Request] { &self.requests } pub fn requests(&self) -> &[Request] { &self.requests }
} }
#[cfg(test)]
mod tests {
use request::*;
use super::RequestBuilder;
use util::H256;
#[test]
fn all_scalar() {
let mut builder = RequestBuilder::default();
builder.push(Request::HeaderProof(IncompleteHeaderProofRequest {
num: 100.into(),
})).unwrap();
builder.push(Request::Receipts(IncompleteReceiptsRequest {
hash: H256::default().into(),
})).unwrap();
}
#[test]
#[should_panic]
fn missing_backref() {
let mut builder = RequestBuilder::default();
builder.push(Request::HeaderProof(IncompleteHeaderProofRequest {
num: Field::BackReference(100, 3),
})).unwrap();
}
#[test]
#[should_panic]
fn wrong_kind() {
let mut builder = RequestBuilder::default();
assert!(builder.push(Request::HeaderProof(IncompleteHeaderProofRequest {
num: 100.into(),
})).is_ok());
builder.push(Request::HeaderProof(IncompleteHeaderProofRequest {
num: Field::BackReference(0, 0),
})).unwrap();
}
#[test]
fn good_backreference() {
let mut builder = RequestBuilder::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();
}
}

View File

@ -649,7 +649,7 @@ pub mod header_proof {
} }
fn note_outputs<F>(&self, mut note: F) where F: FnMut(usize, OutputKind) { fn note_outputs<F>(&self, mut note: F) where F: FnMut(usize, OutputKind) {
note(1, OutputKind::Hash); note(0, OutputKind::Hash);
} }
fn fill<F>(self, oracle: F) -> Result<Self::Complete, NoSuchOutput> fn fill<F>(self, oracle: F) -> Result<Self::Complete, NoSuchOutput>
@ -691,7 +691,7 @@ pub mod header_proof {
impl Response { impl Response {
/// Fill reusable outputs by providing them to the function. /// Fill reusable outputs by providing them to the function.
pub fn fill_outputs<F>(&self, mut f: F) where F: FnMut(usize, Output) { pub fn fill_outputs<F>(&self, mut f: F) where F: FnMut(usize, Output) {
f(1, Output::Hash(self.hash)); f(0, Output::Hash(self.hash));
} }
} }