Merge pull request #406 from ethcore/net

Fixed block_bodies not returning a list
This commit is contained in:
Nikolay Volf 2016-02-11 04:32:19 +03:00
commit 50a6e90e3d
2 changed files with 14 additions and 1 deletions

View File

@ -350,7 +350,7 @@ impl BlockChainClient for Client {
fn block_body(&self, hash: &H256) -> Option<Bytes> { fn block_body(&self, hash: &H256) -> Option<Bytes> {
self.chain.read().unwrap().block(hash).map(|bytes| { self.chain.read().unwrap().block(hash).map(|bytes| {
let rlp = Rlp::new(&bytes); let rlp = Rlp::new(&bytes);
let mut body = RlpStream::new(); let mut body = RlpStream::new_list(2);
body.append_raw(rlp.at(1).as_raw(), 1); body.append_raw(rlp.at(1).as_raw(), 1);
body.append_raw(rlp.at(2).as_raw(), 1); body.append_raw(rlp.at(2).as_raw(), 1);
body.out() body.out()

View File

@ -76,6 +76,19 @@ fn returns_chain_info() {
assert_eq!(info.best_block_hash, block.header().hash()); assert_eq!(info.best_block_hash, block.header().hash());
} }
#[test]
fn returns_block_body() {
let dummy_block = get_good_dummy_block();
let client_result = get_test_client_with_blocks(vec![dummy_block.clone()]);
let client = client_result.reference();
let block = BlockView::new(&dummy_block);
let body = client.block_body(&block.header().hash()).unwrap();
let body = Rlp::new(&body);
assert_eq!(body.item_count(), 2);
assert_eq!(body.at(0).as_raw()[..], block.rlp().at(1).as_raw()[..]);
assert_eq!(body.at(1).as_raw()[..], block.rlp().at(2).as_raw()[..]);
}
#[test] #[test]
fn imports_block_sequence() { fn imports_block_sequence() {
let client_result = generate_dummy_client(6); let client_result = generate_dummy_client(6);