Improve eth_getWork timeout test rpc_get_work_should_timeout (#1992)

This commit is contained in:
Nipunn Koorapati 2016-08-24 04:20:15 -07:00 committed by Gav Wood
parent 124a5da75e
commit 3dd1bdda50

View File

@ -861,7 +861,7 @@ fn rpc_get_work_should_timeout() {
eth_tester.client.set_latest_block_timestamp(get_time().sec as u64 - 1000); // Set latest block to 1000 seconds ago eth_tester.client.set_latest_block_timestamp(get_time().sec as u64 - 1000); // Set latest block to 1000 seconds ago
let hash = eth_tester.miner.map_sealing_work(&*eth_tester.client, |b| b.hash()).unwrap(); let hash = eth_tester.miner.map_sealing_work(&*eth_tester.client, |b| b.hash()).unwrap();
// Request with timeout of 0 seconds. This should work since we're disabling timeout. // Request without providing timeout. This should work since we're disabling timeout.
let request = r#"{"jsonrpc": "2.0", "method": "eth_getWork", "params": [], "id": 1}"#; let request = r#"{"jsonrpc": "2.0", "method": "eth_getWork", "params": [], "id": 1}"#;
let work_response = format!( let work_response = format!(
r#"{{"jsonrpc":"2.0","result":["0x{:?}","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000800000000000000000000000000000000000000000000000000000000000","0x01"],"id":1}}"#, r#"{{"jsonrpc":"2.0","result":["0x{:?}","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000800000000000000000000000000000000000000000000000000000000000","0x01"],"id":1}}"#,
@ -869,6 +869,14 @@ fn rpc_get_work_should_timeout() {
); );
assert_eq!(eth_tester.io.handle_request(request), Some(work_response.to_owned())); assert_eq!(eth_tester.io.handle_request(request), Some(work_response.to_owned()));
// Request with timeout of 0 seconds. This should work since we're disabling timeout.
let request = r#"{"jsonrpc": "2.0", "method": "eth_getWork", "params": ["0"], "id": 1}"#;
let work_response = format!(
r#"{{"jsonrpc":"2.0","result":["0x{:?}","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000800000000000000000000000000000000000000000000000000000000000","0x01"],"id":1}}"#,
hash,
);
assert_eq!(eth_tester.io.handle_request(request), Some(work_response.to_owned()));
// Request with timeout of 10K seconds. This should work. // Request with timeout of 10K seconds. This should work.
let request = r#"{"jsonrpc": "2.0", "method": "eth_getWork", "params": ["10000"], "id": 1}"#; let request = r#"{"jsonrpc": "2.0", "method": "eth_getWork", "params": ["10000"], "id": 1}"#;
assert_eq!(eth_tester.io.handle_request(request), Some(work_response.to_owned())); assert_eq!(eth_tester.io.handle_request(request), Some(work_response.to_owned()));