Fixing all clippy lints

This commit is contained in:
Tomusdrw
2016-01-19 13:47:30 +01:00
parent 6ead6b7847
commit c746f0e62c
25 changed files with 80 additions and 74 deletions

View File

@@ -248,8 +248,8 @@ mod tests {
let a = Account::from_rlp(&rlp);
assert_eq!(a.storage_root().unwrap().hex(), "c57e1afb758b07f8d2c8f13a3b6e44fa5ff94ab266facc5a4fd3f062426e50b2");
assert_eq!(a.storage_at(&mut db, &H256::from(&U256::from(0x00u64))), H256::from(&U256::from(0x1234u64)));
assert_eq!(a.storage_at(&mut db, &H256::from(&U256::from(0x01u64))), H256::new());
assert_eq!(a.storage_at(&db, &H256::from(&U256::from(0x00u64))), H256::from(&U256::from(0x1234u64)));
assert_eq!(a.storage_at(&db, &H256::from(&U256::from(0x01u64))), H256::new());
}
#[test]

View File

@@ -62,8 +62,8 @@ impl AccountDiff {
code: Diff::new(pre.code.clone(), post.code.clone()),
storage: storage.into_iter().map(|k|
(k.clone(), Diff::new(
pre.storage.get(&k).cloned().unwrap_or(H256::new()),
post.storage.get(&k).cloned().unwrap_or(H256::new())
pre.storage.get(&k).cloned().unwrap_or_else(H256::new),
post.storage.get(&k).cloned().unwrap_or_else(H256::new)
))).collect(),
};
if r.balance.is_same() && r.nonce.is_same() && r.code.is_same() && r.storage.is_empty() {

View File

@@ -179,7 +179,7 @@ impl BlockProvider for BlockChain {
const COLLECTION_QUEUE_SIZE: usize = 2;
const MIN_CACHE_SIZE: usize = 1;
const MAX_CACHE_SIZE: usize = 1024 * 1024 * 1;
const MAX_CACHE_SIZE: usize = 1024 * 1024;
impl BlockChain {
/// Create new instance of blockchain from given Genesis
@@ -659,6 +659,7 @@ mod tests {
}
#[test]
#[allow(cyclomatic_complexity)]
fn test_small_fork() {
let genesis = "f901fcf901f7a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a07dba07d6b448a186e9612e5f737d1c909dce473e53199901a302c00646d523c1a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000080832fefd8808454c98c8142a059262c330941f3fe2a34d16d6e3c7b30d2ceb37c6a0e9a994c494ee1a61d2410885aa4c8bf8e56e264c0c0".from_hex().unwrap();
let b1 = "f90261f901f9a05716670833ec874362d65fea27a7cd35af5897d275b31a44944113111e4e96d2a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0cb52de543653d86ccd13ba3ddf8b052525b04231c6884a4db3188a184681d878a0e78628dd45a1f8dc495594d83b76c588a3ee67463260f8b7d4a42f574aeab29aa0e9244cf7503b79c03d3a099e07a80d2dbc77bb0b502d8a89d51ac0d68dd31313b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefd882520884562791e580a051b3ecba4e3f2b49c11d42dd0851ec514b1be3138080f72a2b6e83868275d98f8877671f479c414b47f862f86080018304cb2f94095e7baea6a6c7c4c2dfeb977efac326af552d870a801ca09e2709d7ec9bbe6b1bbbf0b2088828d14cd5e8642a1fee22dc74bfa89761a7f9a04bd8813dee4be989accdb708b1c2e325a7e9c695a8024e30e89d6c644e424747c0".from_hex().unwrap();

View File

@@ -718,7 +718,7 @@ impl Interpreter {
let big_id = stack.pop_back();
let id = big_id.low_u64() as usize;
let max = id.wrapping_add(32);
let data = params.data.clone().unwrap_or(vec![]);
let data = params.data.clone().unwrap_or_else(|| vec![]);
let bound = cmp::min(data.len(), max);
if id < bound && big_id < U256::from(data.len()) {
let mut v = data[id..bound].to_vec();
@@ -729,7 +729,7 @@ impl Interpreter {
}
},
instructions::CALLDATASIZE => {
stack.push(U256::from(params.data.clone().unwrap_or(vec![]).len()));
stack.push(U256::from(params.data.clone().map_or(0, |l| l.len())));
},
instructions::CODESIZE => {
stack.push(U256::from(code.len()));
@@ -740,10 +740,10 @@ impl Interpreter {
stack.push(U256::from(len));
},
instructions::CALLDATACOPY => {
self.copy_data_to_memory(mem, stack, &params.data.clone().unwrap_or(vec![]));
self.copy_data_to_memory(mem, stack, &params.data.clone().unwrap_or_else(|| vec![]));
},
instructions::CODECOPY => {
self.copy_data_to_memory(mem, stack, &params.code.clone().unwrap_or(vec![]));
self.copy_data_to_memory(mem, stack, &params.code.clone().unwrap_or_else(|| vec![]));
},
instructions::EXTCODECOPY => {
let address = u256_to_address(&stack.pop_back());

View File

@@ -19,7 +19,7 @@ struct FakeExt {
logs: Vec<FakeLogEntry>,
_suicides: HashSet<Address>,
info: EnvInfo,
_schedule: Schedule
schedule: Schedule
}
impl FakeExt {
@@ -89,7 +89,7 @@ impl Ext for FakeExt {
}
fn schedule(&self) -> &Schedule {
&self._schedule
&self.schedule
}
fn env_info(&self) -> &EnvInfo {
@@ -122,7 +122,7 @@ fn test_stack_underflow() {
};
match err {
evm::Error::StackUnderflow {instruction: _, wanted, on_stack} => {
evm::Error::StackUnderflow {wanted, on_stack, ..} => {
assert_eq!(wanted, 2);
assert_eq!(on_stack, 0);
}

View File

@@ -158,7 +158,7 @@ impl<'a> Ext for Externalities<'a> {
}
fn extcode(&self, address: &Address) -> Bytes {
self.state.code(address).unwrap_or(vec![])
self.state.code(address).unwrap_or_else(|| vec![])
}
#[allow(match_ref_pats)]

View File

@@ -1,8 +1,9 @@
#![feature(cell_extras)]
#![feature(augmented_assignments)]
//#![feature(plugin)]
#![feature(plugin)]
//#![plugin(interpolate_idents)]
#![allow(match_bool, needless_range_loop)]
#![plugin(clippy)]
#![allow(needless_range_loop, match_bool)]
//! Ethcore's ethereum implementation
//!

View File

@@ -25,10 +25,10 @@ impl FromJson for PodState {
let code = acc.find("code").map(&Bytes::from_json);
if balance.is_some() || nonce.is_some() || storage.is_some() || code.is_some() {
state.insert(address_from_hex(address), PodAccount{
balance: balance.unwrap_or(U256::zero()),
nonce: nonce.unwrap_or(U256::zero()),
storage: storage.unwrap_or(BTreeMap::new()),
code: code.unwrap_or(Vec::new())
balance: balance.unwrap_or_else(U256::zero),
nonce: nonce.unwrap_or_else(U256::zero),
storage: storage.unwrap_or_else(BTreeMap::new),
code: code.unwrap_or_else(Vec::new)
});
}
state

View File

@@ -176,7 +176,7 @@ impl FromJson for Spec {
// let nonce = if let Some(&Json::String(ref n)) = acc.find("nonce") {U256::from_dec_str(n).unwrap_or(U256::from(0))} else {U256::from(0)};
// TODO: handle code & data if they exist.
if balance.is_some() || nonce.is_some() {
state.insert(addr, GenesisAccount { balance: balance.unwrap_or(U256::from(0)), nonce: nonce.unwrap_or(U256::from(0)) });
state.insert(addr, GenesisAccount { balance: balance.unwrap_or_else(U256::zero), nonce: nonce.unwrap_or_else(U256::zero) });
}
}
}

View File

@@ -191,6 +191,7 @@ impl<K, V> RangeCollection<K, V> for Vec<(K, Vec<V>)> where K: Ord + PartialEq +
}
#[test]
#[allow(cyclomatic_complexity)]
fn test_range() {
use std::cmp::{Ordering};

View File

@@ -64,7 +64,7 @@ impl BlockChainClient for TestBlockChainClient {
}
fn block(&self, h: &H256) -> Option<Bytes> {
self.blocks.get(h).map(|b| b.clone())
self.blocks.get(h).cloned()
}
fn block_status(&self, h: &H256) -> BlockStatus {
@@ -208,7 +208,7 @@ impl<'p> SyncIo for TestIo<'p> {
Ok(())
}
fn chain<'a>(&'a mut self) -> &'a mut BlockChainClient {
fn chain(&mut self) -> &mut BlockChainClient {
self.chain
}
}
@@ -265,14 +265,11 @@ impl TestNet {
pub fn sync_step(&mut self) {
for peer in 0..self.peers.len() {
match self.peers[peer].queue.pop_front() {
Some(packet) => {
let mut p = self.peers.get_mut(packet.recipient).unwrap();
trace!("--- {} -> {} ---", peer, packet.recipient);
p.sync.on_packet(&mut TestIo::new(&mut p.chain, &mut p.queue, Some(peer as PeerId)), peer as PeerId, packet.packet_id, &packet.data);
trace!("----------------");
},
None => {}
if let Some(packet) = self.peers[peer].queue.pop_front() {
let mut p = self.peers.get_mut(packet.recipient).unwrap();
trace!("--- {} -> {} ---", peer, packet.recipient);
p.sync.on_packet(&mut TestIo::new(&mut p.chain, &mut p.queue, Some(peer as PeerId)), peer as PeerId, packet.packet_id, &packet.data);
trace!("----------------");
}
let mut p = self.peers.get_mut(peer).unwrap();
p.sync.maintain_sync(&mut TestIo::new(&mut p.chain, &mut p.queue, None));

View File

@@ -168,7 +168,7 @@ fn do_json_test_for(vm: &VMType, json_data: &[u8]) -> Vec<String> {
let mut fail = false;
//let mut fail_unless = |cond: bool| if !cond && !fail { failed.push(name.to_string()); fail = true };
let mut fail_unless = |cond: bool, s: &str | if !cond && !fail {
failed.push(format!("[{}] {}: {}", vm, name.to_string(), s));
failed.push(format!("[{}] {}: {}", vm, name, s));
fail = true
};
@@ -245,7 +245,7 @@ fn do_json_test_for(vm: &VMType, json_data: &[u8]) -> Vec<String> {
test.find("post").map(|pre| for (addr, s) in pre.as_object().unwrap() {
let address = Address::from(addr.as_ref());
fail_unless(state.code(&address).unwrap_or(vec![]) == Bytes::from_json(&s["code"]), "code is incorrect");
fail_unless(state.code(&address).unwrap_or_else(|| vec![]) == Bytes::from_json(&s["code"]), "code is incorrect");
fail_unless(state.balance(&address) == xjson!(&s["balance"]), "balance is incorrect");
fail_unless(state.nonce(&address) == xjson!(&s["nonce"]), "nonce is incorrect");
BTreeMap::from_json(&s["storage"]).iter().foreach(|(k, v)| fail_unless(&state.storage_at(&address, &k) == v, "storage is incorrect"));
@@ -266,7 +266,7 @@ fn do_json_test_for(vm: &VMType, json_data: &[u8]) -> Vec<String> {
}
for f in failed.iter() {
for f in &failed {
println!("FAILED: {:?}", f);
}

View File

@@ -15,7 +15,7 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
let mut fail = false;
{
let mut fail_unless = |cond: bool| if !cond && !fail {
failed.push(name.to_string());
failed.push(name.clone());
flush(format!("FAIL\n"));
fail = true;
true

View File

@@ -6,7 +6,7 @@ macro_rules! declare_test {
#[test]
#[allow(non_snake_case)]
fn $id() {
assert!(do_json_test(include_bytes!(concat!("../../res/ethereum/tests/", $name, ".json"))).len() == 0);
assert!(do_json_test(include_bytes!(concat!("../../res/ethereum/tests/", $name, ".json"))).is_empty());
}
};
}
@@ -18,7 +18,7 @@ macro_rules! declare_test_ignore {
#[ignore]
#[allow(non_snake_case)]
fn $id() {
assert!(do_json_test(include_bytes!(concat!("../../res/ethereum/tests/", $name, ".json"))).len() == 0);
assert!(do_json_test(include_bytes!(concat!("../../res/ethereum/tests/", $name, ".json"))).is_empty());
}
};
}

View File

@@ -9,13 +9,13 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
let ot = RefCell::new(Transaction::new());
for (name, test) in json.as_object().unwrap() {
let mut fail = false;
let mut fail_unless = |cond: bool| if !cond && !fail { failed.push(name.to_string()); println!("Transaction: {:?}", ot.borrow()); fail = true };
let mut fail_unless = |cond: bool| if !cond && !fail { failed.push(name.clone()); println!("Transaction: {:?}", ot.borrow()); fail = true };
let schedule = match test.find("blocknumber")
.and_then(|j| j.as_string())
.and_then(|s| BlockNumber::from_str(s).ok())
.unwrap_or(0) { x if x < 900000 => &old_schedule, _ => &new_schedule };
let rlp = Bytes::from_json(&test["rlp"]);
let res = UntrustedRlp::new(&rlp).as_val().map_err(|e| From::from(e)).and_then(|t: Transaction| t.validate(schedule, schedule.have_delegate_call));
let res = UntrustedRlp::new(&rlp).as_val().map_err(From::from).and_then(|t: Transaction| t.validate(schedule, schedule.have_delegate_call));
fail_unless(test.find("transaction").is_none() == res.is_err());
if let (Some(&Json::Object(ref tx)), Some(&Json::String(ref expect_sender))) = (test.find("transaction"), test.find("sender")) {
let t = res.unwrap();
@@ -30,11 +30,11 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
fail_unless(to == &xjson!(&tx["to"]));
} else {
*ot.borrow_mut() = t.clone();
fail_unless(Bytes::from_json(&tx["to"]).len() == 0);
fail_unless(Bytes::from_json(&tx["to"]).is_empty());
}
}
}
for f in failed.iter() {
for f in &failed {
println!("FAILED: {:?}", f);
}
failed

View File

@@ -64,7 +64,7 @@ pub fn verify_block_unordered(header: Header, bytes: Bytes, engine: &Engine) ->
/// Phase 3 verification. Check block information against parent and uncles.
pub fn verify_block_family<BC>(header: &Header, bytes: &[u8], engine: &Engine, bc: &BC) -> Result<(), Error> where BC: BlockProvider {
// TODO: verify timestamp
let parent = try!(bc.block_header(&header.parent_hash).ok_or::<Error>(From::from(BlockError::UnknownParent(header.parent_hash.clone()))));
let parent = try!(bc.block_header(&header.parent_hash).ok_or_else(|| Error::from(BlockError::UnknownParent(header.parent_hash.clone()))));
try!(verify_parent(&header, &parent));
try!(engine.verify_block_family(&header, &parent, Some(bytes)));
@@ -122,7 +122,7 @@ pub fn verify_block_family<BC>(header: &Header, bytes: &[u8], engine: &Engine, b
// cB.p^7 -------------/
// cB.p^8
let mut expected_uncle_parent = header.parent_hash.clone();
let uncle_parent = try!(bc.block_header(&uncle.parent_hash).ok_or::<Error>(From::from(BlockError::UnknownUncleParent(uncle.parent_hash.clone()))));
let uncle_parent = try!(bc.block_header(&uncle.parent_hash).ok_or_else(|| Error::from(BlockError::UnknownUncleParent(uncle.parent_hash.clone()))));
for _ in 0..depth {
match bc.block_details(&expected_uncle_parent) {
Some(details) => {
@@ -284,7 +284,7 @@ mod tests {
/// Get raw block data
fn block(&self, hash: &H256) -> Option<Bytes> {
self.blocks.get(hash).map(|b| b.clone())
self.blocks.get(hash).cloned()
}
/// Get the familial details concerning a block.
@@ -302,7 +302,7 @@ mod tests {
/// Get the hash of given block's number.
fn block_hash(&self, index: BlockNumber) -> Option<H256> {
self.numbers.get(&index).map(|h| h.clone())
self.numbers.get(&index).cloned()
}
}