Size for blocks (#1668)

* Add size field for blocks.

* Ignore invalid test.
This commit is contained in:
Gav Wood 2016-07-19 20:40:18 +02:00 committed by Arkadiy Paronyan
parent 3cc3dbef66
commit 861c8d0701
3 changed files with 16 additions and 13 deletions

View File

@ -91,6 +91,7 @@ impl<C, S: ?Sized, M, EM> EthClient<C, S, M, EM> where
let view = block_view.header_view(); let view = block_view.header_view();
let block = Block { let block = Block {
hash: Some(view.sha3().into()), hash: Some(view.sha3().into()),
size: Some(bytes.len()),
parent_hash: view.parent_hash().into(), parent_hash: view.parent_hash().into(),
uncles_hash: view.uncles_hash().into(), uncles_hash: view.uncles_hash().into(),
author: view.author().into(), author: view.author().into(),
@ -107,12 +108,9 @@ impl<C, S: ?Sized, M, EM> EthClient<C, S, M, EM> where
total_difficulty: total_difficulty.into(), total_difficulty: total_difficulty.into(),
seal_fields: view.seal().into_iter().map(|f| decode(&f)).map(Bytes::new).collect(), seal_fields: view.seal().into_iter().map(|f| decode(&f)).map(Bytes::new).collect(),
uncles: block_view.uncle_hashes().into_iter().map(Into::into).collect(), uncles: block_view.uncle_hashes().into_iter().map(Into::into).collect(),
transactions: { transactions: match include_txs {
if include_txs { true => BlockTransactions::Full(block_view.localized_transactions().into_iter().map(Into::into).collect()),
BlockTransactions::Full(block_view.localized_transactions().into_iter().map(Into::into).collect()) false => BlockTransactions::Hashes(block_view.transaction_hashes().into_iter().map(Into::into).collect()),
} else {
BlockTransactions::Hashes(block_view.transaction_hashes().into_iter().map(Into::into).collect())
}
}, },
extra_data: Bytes::new(view.extra_data()) extra_data: Bytes::new(view.extra_data())
}; };
@ -142,6 +140,7 @@ impl<C, S: ?Sized, M, EM> EthClient<C, S, M, EM> where
let block = Block { let block = Block {
hash: Some(uncle.hash().into()), hash: Some(uncle.hash().into()),
size: None,
parent_hash: uncle.parent_hash.into(), parent_hash: uncle.parent_hash.into(),
uncles_hash: uncle.uncles_hash.into(), uncles_hash: uncle.uncles_hash.into(),
author: uncle.author.into(), author: uncle.author.into(),

View File

@ -699,6 +699,11 @@ fn rpc_eth_transaction_receipt_null() {
assert_eq!(tester.io.handle_request(request), Some(response.to_owned())); assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
} }
// These tests are incorrect: their output is undefined as long as eth_getCompilers is [].
// Will ignore for now, but should probably be replaced by more substantial tests which check
// the output of eth_getCompilers to determine whether to test. CI systems can then be preinstalled
// with solc/serpent/lllc and they'll be proper again.
#[ignore]
#[test] #[test]
fn rpc_eth_compilers() { fn rpc_eth_compilers() {
let request = r#"{"jsonrpc": "2.0", "method": "eth_getCompilers", "params": [], "id": 1}"#; let request = r#"{"jsonrpc": "2.0", "method": "eth_getCompilers", "params": [], "id": 1}"#;
@ -707,10 +712,6 @@ fn rpc_eth_compilers() {
assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned())); assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned()));
} }
// These tests are incorrect: their output is undefined as long as eth_getCompilers is [].
// Will ignore for now, but should probably be replaced by more substantial tests which check
// the output of eth_getCompilers to determine whether to test. CI systems can then be preinstalled
// with solc/serpent/lllc and they'll be proper again.
#[ignore] #[ignore]
#[test] #[test]
fn rpc_eth_compile_lll() { fn rpc_eth_compile_lll() {

View File

@ -88,7 +88,9 @@ pub struct Block {
/// Uncles' hashes /// Uncles' hashes
pub uncles: Vec<H256>, pub uncles: Vec<H256>,
/// Transactions /// Transactions
pub transactions: BlockTransactions pub transactions: BlockTransactions,
/// Size in bytes
pub size: Option<usize>,
} }
#[cfg(test)] #[cfg(test)]
@ -129,10 +131,11 @@ mod tests {
total_difficulty: U256::default(), total_difficulty: U256::default(),
seal_fields: vec![Bytes::default(), Bytes::default()], seal_fields: vec![Bytes::default(), Bytes::default()],
uncles: vec![], uncles: vec![],
transactions: BlockTransactions::Hashes(vec![].into()) transactions: BlockTransactions::Hashes(vec![].into()),
size: Some(69usize),
}; };
let serialized = serde_json::to_string(&block).unwrap(); let serialized = serde_json::to_string(&block).unwrap();
assert_eq!(serialized, r#"{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","sha3Uncles":"0x0000000000000000000000000000000000000000000000000000000000000000","author":"0x0000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","number":"0x00","gasUsed":"0x00","gasLimit":"0x00","extraData":"0x","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","timestamp":"0x00","difficulty":"0x00","totalDifficulty":"0x00","sealFields":["0x","0x"],"uncles":[],"transactions":[]}"#); assert_eq!(serialized, r#"{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","sha3Uncles":"0x0000000000000000000000000000000000000000000000000000000000000000","author":"0x0000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","number":"0x00","gasUsed":"0x00","gasLimit":"0x00","extraData":"0x","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","timestamp":"0x00","difficulty":"0x00","totalDifficulty":"0x00","sealFields":["0x","0x"],"uncles":[],"transactions":[],"size":69}"#);
} }
} }