From 965dde822315a2b2555434967f3171b1e0e12b4f Mon Sep 17 00:00:00 2001 From: keorn Date: Fri, 9 Sep 2016 11:49:03 +0200 Subject: [PATCH] enable TestNet with custom spec --- ethcore/src/client/test_client.rs | 5 +++++ sync/src/tests/helpers.rs | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index b235b4b78..33a597745 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -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()), diff --git a/sync/src/tests/helpers.rs b/sync/src/tests/helpers.rs index cbed49eff..dd34ca276 100644 --- a/sync/src/tests/helpers.rs +++ b/sync/src/tests/helpers.rs @@ -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(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() }