2016-01-26 18:05:25 +01:00
|
|
|
use client::{BlockChainClient,Client};
|
2016-01-26 11:55:12 +01:00
|
|
|
use super::test_common::*;
|
2016-01-27 11:50:48 +01:00
|
|
|
use super::helpers::*;
|
2016-01-26 11:39:49 +01:00
|
|
|
|
2016-01-26 14:33:22 +01:00
|
|
|
#[test]
|
|
|
|
fn created() {
|
2016-01-27 14:21:54 +01:00
|
|
|
let dir = RandomTempPath::new();
|
|
|
|
let client_result = Client::new(get_test_spec(), dir.as_path(), IoChannel::disconnected());
|
2016-01-26 11:39:49 +01:00
|
|
|
assert!(client_result.is_ok());
|
2016-01-26 14:33:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn imports_from_empty() {
|
2016-01-27 14:21:54 +01:00
|
|
|
let dir = RandomTempPath::new();
|
|
|
|
let client = Client::new(get_test_spec(), dir.as_path(), IoChannel::disconnected()).unwrap();
|
2016-01-26 14:33:22 +01:00
|
|
|
client.import_verified_blocks(&IoChannel::disconnected());
|
|
|
|
client.flush_queue();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn imports_good_block() {
|
2016-01-27 14:21:54 +01:00
|
|
|
let dir = RandomTempPath::new();
|
|
|
|
let client = Client::new(get_test_spec(), dir.as_path(), IoChannel::disconnected()).unwrap();
|
2016-01-26 14:33:22 +01:00
|
|
|
let good_block = get_good_dummy_block();
|
|
|
|
if let Err(_) = client.import_block(good_block) {
|
|
|
|
panic!("error importing block being good by definition");
|
|
|
|
}
|
|
|
|
client.flush_queue();
|
|
|
|
client.import_verified_blocks(&IoChannel::disconnected());
|
|
|
|
|
|
|
|
let block = client.block_header_at(1).unwrap();
|
|
|
|
assert!(!block.is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn query_none_block() {
|
2016-01-27 14:21:54 +01:00
|
|
|
let dir = RandomTempPath::new();
|
|
|
|
let client = Client::new(get_test_spec(), dir.as_path(), IoChannel::disconnected()).unwrap();
|
2016-01-26 14:33:22 +01:00
|
|
|
|
|
|
|
let non_existant = client.block_header_at(188);
|
2016-01-26 14:55:08 +01:00
|
|
|
assert!(non_existant.is_none());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn query_bad_block() {
|
2016-01-28 15:38:42 +01:00
|
|
|
let client_result = get_test_client_with_blocks(vec![get_bad_state_dummy_block()]);
|
|
|
|
let client = client_result.reference();
|
2016-01-26 14:55:08 +01:00
|
|
|
let bad_block:Option<Bytes> = client.block_header_at(1);
|
|
|
|
|
|
|
|
assert!(bad_block.is_none());
|
2016-01-26 18:05:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn returns_chain_info() {
|
|
|
|
let dummy_block = get_good_dummy_block();
|
2016-01-28 15:38:42 +01:00
|
|
|
let client_result = get_test_client_with_blocks(vec![dummy_block.clone()]);
|
|
|
|
let client = client_result.reference();
|
2016-01-26 18:05:25 +01:00
|
|
|
let block = BlockView::new(&dummy_block);
|
|
|
|
let info = client.chain_info();
|
|
|
|
assert_eq!(info.best_block_hash, block.header().hash());
|
2016-01-27 13:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn imports_block_sequence() {
|
2016-01-28 15:38:42 +01:00
|
|
|
let client_result = generate_dummy_client(6);
|
|
|
|
let client = client_result.reference();
|
2016-01-27 13:23:24 +01:00
|
|
|
let block = client.block_header_at(5).unwrap();
|
|
|
|
|
|
|
|
assert!(!block.is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn can_collect_garbage() {
|
2016-01-28 15:38:42 +01:00
|
|
|
let client_result = generate_dummy_client(100);
|
|
|
|
let client = client_result.reference();
|
2016-01-27 13:23:24 +01:00
|
|
|
client.tick();
|
|
|
|
assert!(client.cache_info().blocks < 100 * 1024);
|
2016-01-26 11:39:49 +01:00
|
|
|
}
|