Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar committed Jul 27, 2016
1 parent e4fee5f commit f553997
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
21 changes: 20 additions & 1 deletion sync/src/tests/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

use util::*;
use ethcore::client::{BlockChainClient, BlockID, EachBlockWith};
use ethcore::client::{TestBlockChainClient, BlockChainClient, BlockID, EachBlockWith};
use chain::{SyncState};
use super::helpers::*;

Expand Down Expand Up @@ -95,6 +95,25 @@ fn forked() {
assert_eq!(net.peer(2).chain.numbers.read().deref(), &peer1_chain);
}

#[test]
fn net_hard_fork() {
::env_logger::init().ok();
let ref_client = TestBlockChainClient::new();
ref_client.add_blocks(50, EachBlockWith::Uncle);
{
let mut net = TestNet::new_with_fork(2, Some((50, ref_client.block_hash(BlockID::Number(50)).unwrap())));
net.peer_mut(0).chain.add_blocks(100, EachBlockWith::Uncle);
net.sync();
assert_eq!(net.peer(1).chain.chain_info().best_block_number, 100);
}
{
let mut net = TestNet::new_with_fork(2, Some((50, ref_client.block_hash(BlockID::Number(50)).unwrap())));
net.peer_mut(0).chain.add_blocks(100, EachBlockWith::Nothing);
net.sync();
assert_eq!(net.peer(1).chain.chain_info().best_block_number, 0);
}
}

#[test]
fn restart() {
let mut net = TestNet::new(3);
Expand Down
10 changes: 8 additions & 2 deletions sync/src/tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use util::*;
use ethcore::client::{TestBlockChainClient, BlockChainClient};
use ethcore::header::BlockNumber;
use io::SyncIo;
use chain::ChainSync;
use ::SyncConfig;
Expand Down Expand Up @@ -89,13 +90,19 @@ pub struct TestNet {

impl TestNet {
pub fn new(n: usize) -> TestNet {
Self::new_with_fork(n, None)
}

pub fn new_with_fork(n: usize, fork: Option<(BlockNumber, H256)>) -> TestNet {
let mut net = TestNet {
peers: Vec::new(),
started: false,
};
for _ in 0..n {
let chain = TestBlockChainClient::new();
let sync = ChainSync::new(SyncConfig::default(), &chain);
let mut config = SyncConfig::default();
config.fork_block = fork;
let sync = ChainSync::new(config, &chain);
net.peers.push(TestPeer {
sync: RwLock::new(sync),
chain: chain,
Expand All @@ -104,7 +111,6 @@ impl TestNet {
}
net
}

pub fn peer(&self, i: usize) -> &TestPeer {
self.peers.get(i).unwrap()
}
Expand Down

0 comments on commit f553997

Please sign in to comment.