enable TestNet with custom spec

This commit is contained in:
keorn 2016-09-09 11:49:03 +02:00
parent fc3d01ec71
commit 965dde8223
2 changed files with 24 additions and 0 deletions

View File

@ -102,6 +102,11 @@ impl TestBlockChainClient {
/// Creates new test client.
pub fn new() -> Self {
let spec = Spec::new_test();
TestBlockChainClient::new_with_spec(spec)
}
/// Create test client with custom spec.
pub fn new_with_spec(spec: Spec) -> Self {
let mut client = TestBlockChainClient {
blocks: RwLock::new(HashMap::new()),
numbers: RwLock::new(HashMap::new()),

View File

@ -19,6 +19,7 @@ use network::*;
use tests::snapshot::*;
use ethcore::client::{TestBlockChainClient, BlockChainClient};
use ethcore::header::BlockNumber;
use ethcore::spec::Spec;
use ethcore::snapshot::SnapshotService;
use sync_io::SyncIo;
use chain::ChainSync;
@ -128,6 +129,24 @@ impl TestNet {
net
}
pub fn new_with_spec_file<R>(n: usize, reader: R) -> TestNet where R: Read + Clone {
let mut net = TestNet {
peers: Vec::new(),
started: false,
};
for _ in 0..n {
let chain = TestBlockChainClient::new_with_spec(Spec::load(reader.clone()).expect("Invalid spec file."));
let sync = ChainSync::new(SyncConfig::default(), &chain);
net.peers.push(TestPeer {
sync: RwLock::new(sync),
snapshot_service: Arc::new(TestSnapshotService::new()),
chain: chain,
queue: VecDeque::new(),
});
}
net
}
pub fn peer(&self, i: usize) -> &TestPeer {
self.peers.get(i).unwrap()
}