Skip to content
Snippets Groups Projects
Commit 506ca48d authored by Bastian Köcher's avatar Bastian Köcher Committed by GitHub
Browse files

Offchain testing: Fix reading response (#10294)

parent f0376517
No related merge requests found
......@@ -341,7 +341,7 @@ impl offchain::Externalities for TestOffchainExt {
Ok(0)
} else {
let read = std::cmp::min(buffer.len(), response[req.read..].len());
buffer[0..read].copy_from_slice(&response[req.read..read]);
buffer[0..read].copy_from_slice(&response[req.read..req.read + read]);
req.read += read;
Ok(read)
}
......
......@@ -535,6 +535,38 @@ mod tests {
})
}
#[test]
fn should_send_huge_response() {
let (offchain, state) = testing::TestOffchainExt::new();
let mut t = TestExternalities::default();
t.register_extension(OffchainWorkerExt::new(offchain));
t.execute_with(|| {
let request: Request = Request::get("http://localhost:1234");
let pending = request.add_header("X-Auth", "hunter2").send().unwrap();
// make sure it's sent correctly
state.write().fulfill_pending_request(
0,
testing::PendingRequest {
method: "GET".into(),
uri: "http://localhost:1234".into(),
headers: vec![("X-Auth".into(), "hunter2".into())],
sent: true,
..Default::default()
},
vec![0; 5923],
None,
);
// wait
let response = pending.wait().unwrap();
let body = response.body();
assert_eq!(body.clone().collect::<Vec<_>>(), vec![0; 5923]);
assert_eq!(body.error(), &None);
})
}
#[test]
fn should_send_a_post_request() {
let (offchain, state) = testing::TestOffchainExt::new();
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment