From b0cba757d6f6a71a5529e5a0656ac0a88c80e4ab Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Fri, 5 Feb 2016 02:57:51 +0300 Subject: [PATCH] test effort --- sync/src/chain.rs | 27 +++++++++++++++++++++++++++ sync/src/tests/helpers.rs | 9 ++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 62bb4b4de..869b19bf5 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -1077,7 +1077,34 @@ mod tests { let mut sync = ChainSync::new(); io.sender = Some(2usize); sync.on_packet(&mut io, 1usize, super::GET_RECEIPTS_PACKET, &receipts_request); + assert_eq!(1, io.queue.len()); } + #[test] + fn return_nodes() { + let mut client = TestBlockChainClient::new(); + let mut queue = VecDeque::new(); + let mut io = TestIo::new(&mut client, &mut queue, None); + let mut node_list = RlpStream::new_list(3); + node_list.append(&H256::from("0000000000000000000000000000000000000000000000005555555555555555")); + node_list.append(&H256::from("ffffffffffffffffffffffffffffffffffffffffffffaaaaaaaaaaaaaaaaaaaa")); + node_list.append(&H256::from("aff0000000000000000000000000000000000000000000000000000000000000")); + + let node_request = node_list.out(); + // it returns rlp ONLY for hashes started with "f" + let result = ChainSync::return_node_data(&io, &UntrustedRlp::new(&node_request.clone())); + + assert!(result.is_ok()); + let rlp_result = result.unwrap(); + assert!(rlp_result.is_some()); + + // the length of one rlp-encoded hashe + assert_eq!(34, rlp_result.unwrap().1.out().len()); + + let mut sync = ChainSync::new(); + io.sender = Some(2usize); + sync.on_packet(&mut io, 1usize, super::GET_NODE_DATA_PACKET, &node_request); + assert_eq!(1, io.queue.len()); + } } \ No newline at end of file diff --git a/sync/src/tests/helpers.rs b/sync/src/tests/helpers.rs index ce3560d63..c4a4d80cb 100644 --- a/sync/src/tests/helpers.rs +++ b/sync/src/tests/helpers.rs @@ -117,7 +117,14 @@ impl BlockChainClient for TestBlockChainClient { }) } - fn state_data(&self, _h: &H256) -> Option { + // TODO: returns just hashes instead of node state rlp(?) + fn state_data(&self, hash: &H256) -> Option { + // starts with 'f' ? + if *hash > H256::from("f000000000000000000000000000000000000000000000000000000000000000") { + let mut rlp = RlpStream::new(); + rlp.append(&hash.clone()); + return Some(rlp.out()); + } None }