Fixing all clippy lints
This commit is contained in:
parent
6ead6b7847
commit
c746f0e62c
@ -20,6 +20,7 @@ time = "0.1"
|
|||||||
evmjit = { path = "rust-evmjit", optional = true }
|
evmjit = { path = "rust-evmjit", optional = true }
|
||||||
ethash = { path = "ethash" }
|
ethash = { path = "ethash" }
|
||||||
num_cpus = "0.2"
|
num_cpus = "0.2"
|
||||||
|
clippy = "*"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
jit = ["evmjit"]
|
jit = ["evmjit"]
|
||||||
|
@ -248,8 +248,8 @@ mod tests {
|
|||||||
|
|
||||||
let a = Account::from_rlp(&rlp);
|
let a = Account::from_rlp(&rlp);
|
||||||
assert_eq!(a.storage_root().unwrap().hex(), "c57e1afb758b07f8d2c8f13a3b6e44fa5ff94ab266facc5a4fd3f062426e50b2");
|
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(&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(0x01u64))), H256::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -62,8 +62,8 @@ impl AccountDiff {
|
|||||||
code: Diff::new(pre.code.clone(), post.code.clone()),
|
code: Diff::new(pre.code.clone(), post.code.clone()),
|
||||||
storage: storage.into_iter().map(|k|
|
storage: storage.into_iter().map(|k|
|
||||||
(k.clone(), Diff::new(
|
(k.clone(), Diff::new(
|
||||||
pre.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(H256::new())
|
post.storage.get(&k).cloned().unwrap_or_else(H256::new)
|
||||||
))).collect(),
|
))).collect(),
|
||||||
};
|
};
|
||||||
if r.balance.is_same() && r.nonce.is_same() && r.code.is_same() && r.storage.is_empty() {
|
if r.balance.is_same() && r.nonce.is_same() && r.code.is_same() && r.storage.is_empty() {
|
||||||
|
@ -179,7 +179,7 @@ impl BlockProvider for BlockChain {
|
|||||||
|
|
||||||
const COLLECTION_QUEUE_SIZE: usize = 2;
|
const COLLECTION_QUEUE_SIZE: usize = 2;
|
||||||
const MIN_CACHE_SIZE: usize = 1;
|
const MIN_CACHE_SIZE: usize = 1;
|
||||||
const MAX_CACHE_SIZE: usize = 1024 * 1024 * 1;
|
const MAX_CACHE_SIZE: usize = 1024 * 1024;
|
||||||
|
|
||||||
impl BlockChain {
|
impl BlockChain {
|
||||||
/// Create new instance of blockchain from given Genesis
|
/// Create new instance of blockchain from given Genesis
|
||||||
@ -659,6 +659,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(cyclomatic_complexity)]
|
||||||
fn test_small_fork() {
|
fn test_small_fork() {
|
||||||
let genesis = "f901fcf901f7a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a07dba07d6b448a186e9612e5f737d1c909dce473e53199901a302c00646d523c1a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000080832fefd8808454c98c8142a059262c330941f3fe2a34d16d6e3c7b30d2ceb37c6a0e9a994c494ee1a61d2410885aa4c8bf8e56e264c0c0".from_hex().unwrap();
|
let genesis = "f901fcf901f7a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a07dba07d6b448a186e9612e5f737d1c909dce473e53199901a302c00646d523c1a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000080832fefd8808454c98c8142a059262c330941f3fe2a34d16d6e3c7b30d2ceb37c6a0e9a994c494ee1a61d2410885aa4c8bf8e56e264c0c0".from_hex().unwrap();
|
||||||
let b1 = "f90261f901f9a05716670833ec874362d65fea27a7cd35af5897d275b31a44944113111e4e96d2a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0cb52de543653d86ccd13ba3ddf8b052525b04231c6884a4db3188a184681d878a0e78628dd45a1f8dc495594d83b76c588a3ee67463260f8b7d4a42f574aeab29aa0e9244cf7503b79c03d3a099e07a80d2dbc77bb0b502d8a89d51ac0d68dd31313b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefd882520884562791e580a051b3ecba4e3f2b49c11d42dd0851ec514b1be3138080f72a2b6e83868275d98f8877671f479c414b47f862f86080018304cb2f94095e7baea6a6c7c4c2dfeb977efac326af552d870a801ca09e2709d7ec9bbe6b1bbbf0b2088828d14cd5e8642a1fee22dc74bfa89761a7f9a04bd8813dee4be989accdb708b1c2e325a7e9c695a8024e30e89d6c644e424747c0".from_hex().unwrap();
|
let b1 = "f90261f901f9a05716670833ec874362d65fea27a7cd35af5897d275b31a44944113111e4e96d2a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0cb52de543653d86ccd13ba3ddf8b052525b04231c6884a4db3188a184681d878a0e78628dd45a1f8dc495594d83b76c588a3ee67463260f8b7d4a42f574aeab29aa0e9244cf7503b79c03d3a099e07a80d2dbc77bb0b502d8a89d51ac0d68dd31313b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefd882520884562791e580a051b3ecba4e3f2b49c11d42dd0851ec514b1be3138080f72a2b6e83868275d98f8877671f479c414b47f862f86080018304cb2f94095e7baea6a6c7c4c2dfeb977efac326af552d870a801ca09e2709d7ec9bbe6b1bbbf0b2088828d14cd5e8642a1fee22dc74bfa89761a7f9a04bd8813dee4be989accdb708b1c2e325a7e9c695a8024e30e89d6c644e424747c0".from_hex().unwrap();
|
||||||
|
@ -718,7 +718,7 @@ impl Interpreter {
|
|||||||
let big_id = stack.pop_back();
|
let big_id = stack.pop_back();
|
||||||
let id = big_id.low_u64() as usize;
|
let id = big_id.low_u64() as usize;
|
||||||
let max = id.wrapping_add(32);
|
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);
|
let bound = cmp::min(data.len(), max);
|
||||||
if id < bound && big_id < U256::from(data.len()) {
|
if id < bound && big_id < U256::from(data.len()) {
|
||||||
let mut v = data[id..bound].to_vec();
|
let mut v = data[id..bound].to_vec();
|
||||||
@ -729,7 +729,7 @@ impl Interpreter {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
instructions::CALLDATASIZE => {
|
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 => {
|
instructions::CODESIZE => {
|
||||||
stack.push(U256::from(code.len()));
|
stack.push(U256::from(code.len()));
|
||||||
@ -740,10 +740,10 @@ impl Interpreter {
|
|||||||
stack.push(U256::from(len));
|
stack.push(U256::from(len));
|
||||||
},
|
},
|
||||||
instructions::CALLDATACOPY => {
|
instructions::CALLDATACOPY => {
|
||||||
self.copy_data_to_memory(mem, stack, ¶ms.data.clone().unwrap_or(vec![]));
|
self.copy_data_to_memory(mem, stack, ¶ms.data.clone().unwrap_or_else(|| vec![]));
|
||||||
},
|
},
|
||||||
instructions::CODECOPY => {
|
instructions::CODECOPY => {
|
||||||
self.copy_data_to_memory(mem, stack, ¶ms.code.clone().unwrap_or(vec![]));
|
self.copy_data_to_memory(mem, stack, ¶ms.code.clone().unwrap_or_else(|| vec![]));
|
||||||
},
|
},
|
||||||
instructions::EXTCODECOPY => {
|
instructions::EXTCODECOPY => {
|
||||||
let address = u256_to_address(&stack.pop_back());
|
let address = u256_to_address(&stack.pop_back());
|
||||||
|
@ -19,7 +19,7 @@ struct FakeExt {
|
|||||||
logs: Vec<FakeLogEntry>,
|
logs: Vec<FakeLogEntry>,
|
||||||
_suicides: HashSet<Address>,
|
_suicides: HashSet<Address>,
|
||||||
info: EnvInfo,
|
info: EnvInfo,
|
||||||
_schedule: Schedule
|
schedule: Schedule
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FakeExt {
|
impl FakeExt {
|
||||||
@ -89,7 +89,7 @@ impl Ext for FakeExt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn schedule(&self) -> &Schedule {
|
fn schedule(&self) -> &Schedule {
|
||||||
&self._schedule
|
&self.schedule
|
||||||
}
|
}
|
||||||
|
|
||||||
fn env_info(&self) -> &EnvInfo {
|
fn env_info(&self) -> &EnvInfo {
|
||||||
@ -122,7 +122,7 @@ fn test_stack_underflow() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
match err {
|
match err {
|
||||||
evm::Error::StackUnderflow {instruction: _, wanted, on_stack} => {
|
evm::Error::StackUnderflow {wanted, on_stack, ..} => {
|
||||||
assert_eq!(wanted, 2);
|
assert_eq!(wanted, 2);
|
||||||
assert_eq!(on_stack, 0);
|
assert_eq!(on_stack, 0);
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ impl<'a> Ext for Externalities<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn extcode(&self, address: &Address) -> Bytes {
|
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)]
|
#[allow(match_ref_pats)]
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#![feature(cell_extras)]
|
#![feature(cell_extras)]
|
||||||
#![feature(augmented_assignments)]
|
#![feature(augmented_assignments)]
|
||||||
//#![feature(plugin)]
|
#![feature(plugin)]
|
||||||
//#![plugin(interpolate_idents)]
|
//#![plugin(interpolate_idents)]
|
||||||
#![allow(match_bool, needless_range_loop)]
|
#![plugin(clippy)]
|
||||||
|
#![allow(needless_range_loop, match_bool)]
|
||||||
|
|
||||||
//! Ethcore's ethereum implementation
|
//! Ethcore's ethereum implementation
|
||||||
//!
|
//!
|
||||||
|
@ -25,10 +25,10 @@ impl FromJson for PodState {
|
|||||||
let code = acc.find("code").map(&Bytes::from_json);
|
let code = acc.find("code").map(&Bytes::from_json);
|
||||||
if balance.is_some() || nonce.is_some() || storage.is_some() || code.is_some() {
|
if balance.is_some() || nonce.is_some() || storage.is_some() || code.is_some() {
|
||||||
state.insert(address_from_hex(address), PodAccount{
|
state.insert(address_from_hex(address), PodAccount{
|
||||||
balance: balance.unwrap_or(U256::zero()),
|
balance: balance.unwrap_or_else(U256::zero),
|
||||||
nonce: nonce.unwrap_or(U256::zero()),
|
nonce: nonce.unwrap_or_else(U256::zero),
|
||||||
storage: storage.unwrap_or(BTreeMap::new()),
|
storage: storage.unwrap_or_else(BTreeMap::new),
|
||||||
code: code.unwrap_or(Vec::new())
|
code: code.unwrap_or_else(Vec::new)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
state
|
state
|
||||||
|
@ -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)};
|
// 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.
|
// TODO: handle code & data if they exist.
|
||||||
if balance.is_some() || nonce.is_some() {
|
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) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,6 +191,7 @@ impl<K, V> RangeCollection<K, V> for Vec<(K, Vec<V>)> where K: Ord + PartialEq +
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(cyclomatic_complexity)]
|
||||||
fn test_range() {
|
fn test_range() {
|
||||||
use std::cmp::{Ordering};
|
use std::cmp::{Ordering};
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ impl BlockChainClient for TestBlockChainClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn block(&self, h: &H256) -> Option<Bytes> {
|
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 {
|
fn block_status(&self, h: &H256) -> BlockStatus {
|
||||||
@ -208,7 +208,7 @@ impl<'p> SyncIo for TestIo<'p> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn chain<'a>(&'a mut self) -> &'a mut BlockChainClient {
|
fn chain(&mut self) -> &mut BlockChainClient {
|
||||||
self.chain
|
self.chain
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -265,14 +265,11 @@ impl TestNet {
|
|||||||
|
|
||||||
pub fn sync_step(&mut self) {
|
pub fn sync_step(&mut self) {
|
||||||
for peer in 0..self.peers.len() {
|
for peer in 0..self.peers.len() {
|
||||||
match self.peers[peer].queue.pop_front() {
|
if let Some(packet) = self.peers[peer].queue.pop_front() {
|
||||||
Some(packet) => {
|
let mut p = self.peers.get_mut(packet.recipient).unwrap();
|
||||||
let mut p = self.peers.get_mut(packet.recipient).unwrap();
|
trace!("--- {} -> {} ---", peer, packet.recipient);
|
||||||
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);
|
||||||
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!("----------------");
|
||||||
trace!("----------------");
|
|
||||||
},
|
|
||||||
None => {}
|
|
||||||
}
|
}
|
||||||
let mut p = self.peers.get_mut(peer).unwrap();
|
let mut p = self.peers.get_mut(peer).unwrap();
|
||||||
p.sync.maintain_sync(&mut TestIo::new(&mut p.chain, &mut p.queue, None));
|
p.sync.maintain_sync(&mut TestIo::new(&mut p.chain, &mut p.queue, None));
|
||||||
|
@ -168,7 +168,7 @@ fn do_json_test_for(vm: &VMType, json_data: &[u8]) -> Vec<String> {
|
|||||||
let mut fail = false;
|
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| if !cond && !fail { failed.push(name.to_string()); fail = true };
|
||||||
let mut fail_unless = |cond: bool, s: &str | if !cond && !fail {
|
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
|
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() {
|
test.find("post").map(|pre| for (addr, s) in pre.as_object().unwrap() {
|
||||||
let address = Address::from(addr.as_ref());
|
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.balance(&address) == xjson!(&s["balance"]), "balance is incorrect");
|
||||||
fail_unless(state.nonce(&address) == xjson!(&s["nonce"]), "nonce 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"));
|
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);
|
println!("FAILED: {:?}", f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
|||||||
let mut fail = false;
|
let mut fail = false;
|
||||||
{
|
{
|
||||||
let mut fail_unless = |cond: bool| if !cond && !fail {
|
let mut fail_unless = |cond: bool| if !cond && !fail {
|
||||||
failed.push(name.to_string());
|
failed.push(name.clone());
|
||||||
flush(format!("FAIL\n"));
|
flush(format!("FAIL\n"));
|
||||||
fail = true;
|
fail = true;
|
||||||
true
|
true
|
||||||
|
@ -6,7 +6,7 @@ macro_rules! declare_test {
|
|||||||
#[test]
|
#[test]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn $id() {
|
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]
|
#[ignore]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn $id() {
|
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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -9,13 +9,13 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
|||||||
let ot = RefCell::new(Transaction::new());
|
let ot = RefCell::new(Transaction::new());
|
||||||
for (name, test) in json.as_object().unwrap() {
|
for (name, test) in json.as_object().unwrap() {
|
||||||
let mut fail = false;
|
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")
|
let schedule = match test.find("blocknumber")
|
||||||
.and_then(|j| j.as_string())
|
.and_then(|j| j.as_string())
|
||||||
.and_then(|s| BlockNumber::from_str(s).ok())
|
.and_then(|s| BlockNumber::from_str(s).ok())
|
||||||
.unwrap_or(0) { x if x < 900000 => &old_schedule, _ => &new_schedule };
|
.unwrap_or(0) { x if x < 900000 => &old_schedule, _ => &new_schedule };
|
||||||
let rlp = Bytes::from_json(&test["rlp"]);
|
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());
|
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")) {
|
if let (Some(&Json::Object(ref tx)), Some(&Json::String(ref expect_sender))) = (test.find("transaction"), test.find("sender")) {
|
||||||
let t = res.unwrap();
|
let t = res.unwrap();
|
||||||
@ -30,11 +30,11 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
|||||||
fail_unless(to == &xjson!(&tx["to"]));
|
fail_unless(to == &xjson!(&tx["to"]));
|
||||||
} else {
|
} else {
|
||||||
*ot.borrow_mut() = t.clone();
|
*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);
|
println!("FAILED: {:?}", f);
|
||||||
}
|
}
|
||||||
failed
|
failed
|
||||||
|
@ -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.
|
/// 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 {
|
pub fn verify_block_family<BC>(header: &Header, bytes: &[u8], engine: &Engine, bc: &BC) -> Result<(), Error> where BC: BlockProvider {
|
||||||
// TODO: verify timestamp
|
// 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!(verify_parent(&header, &parent));
|
||||||
try!(engine.verify_block_family(&header, &parent, Some(bytes)));
|
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^7 -------------/
|
||||||
// cB.p^8
|
// cB.p^8
|
||||||
let mut expected_uncle_parent = header.parent_hash.clone();
|
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 {
|
for _ in 0..depth {
|
||||||
match bc.block_details(&expected_uncle_parent) {
|
match bc.block_details(&expected_uncle_parent) {
|
||||||
Some(details) => {
|
Some(details) => {
|
||||||
@ -284,7 +284,7 @@ mod tests {
|
|||||||
|
|
||||||
/// Get raw block data
|
/// Get raw block data
|
||||||
fn block(&self, hash: &H256) -> Option<Bytes> {
|
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.
|
/// Get the familial details concerning a block.
|
||||||
@ -302,7 +302,7 @@ mod tests {
|
|||||||
|
|
||||||
/// Get the hash of given block's number.
|
/// Get the hash of given block's number.
|
||||||
fn block_hash(&self, index: BlockNumber) -> Option<H256> {
|
fn block_hash(&self, index: BlockNumber) -> Option<H256> {
|
||||||
self.numbers.get(&index).map(|h| h.clone())
|
self.numbers.get(&index).cloned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ heapsize = "0.2"
|
|||||||
itertools = "0.4"
|
itertools = "0.4"
|
||||||
slab = { git = "https://github.com/arkpar/slab.git" }
|
slab = { git = "https://github.com/arkpar/slab.git" }
|
||||||
sha3 = { path = "sha3" }
|
sha3 = { path = "sha3" }
|
||||||
|
clippy = "*"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
json-tests = { path = "json-tests" }
|
json-tests = { path = "json-tests" }
|
||||||
|
@ -424,9 +424,9 @@ macro_rules! impl_hash {
|
|||||||
fn from(s: &'_ str) -> $from {
|
fn from(s: &'_ str) -> $from {
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
if s.len() % 2 == 1 {
|
if s.len() % 2 == 1 {
|
||||||
$from::from_str(&("0".to_owned() + &(clean_0x(s).to_owned()))[..]).unwrap_or($from::new())
|
$from::from_str(&("0".to_owned() + &(clean_0x(s).to_owned()))[..]).unwrap_or_else(|_| $from::new())
|
||||||
} else {
|
} else {
|
||||||
$from::from_str(clean_0x(s)).unwrap_or($from::new())
|
$from::from_str(clean_0x(s)).unwrap_or_else(|_| $from::new())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -545,6 +545,7 @@ mod tests {
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(eq_op)]
|
||||||
fn hash() {
|
fn hash() {
|
||||||
let h = H64([0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]);
|
let h = H64([0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]);
|
||||||
assert_eq!(H64::from_str("0123456789abcdef").unwrap(), h);
|
assert_eq!(H64::from_str("0123456789abcdef").unwrap(), h);
|
||||||
|
@ -96,7 +96,7 @@ impl JournalDB {
|
|||||||
})) {
|
})) {
|
||||||
let rlp = Rlp::new(&rlp_data);
|
let rlp = Rlp::new(&rlp_data);
|
||||||
let to_remove: Vec<H256> = rlp.val_at(if canon_id == rlp.val_at(0) {2} else {1});
|
let to_remove: Vec<H256> = rlp.val_at(if canon_id == rlp.val_at(0) {2} else {1});
|
||||||
for i in to_remove.iter() {
|
for i in &to_remove {
|
||||||
self.forward.remove(i);
|
self.forward.remove(i);
|
||||||
}
|
}
|
||||||
try!(self.backing.delete(&last));
|
try!(self.backing.delete(&last));
|
||||||
|
@ -10,9 +10,9 @@ pub fn clean(s: &str) -> &str {
|
|||||||
|
|
||||||
fn u256_from_str(s: &str) -> U256 {
|
fn u256_from_str(s: &str) -> U256 {
|
||||||
if s.len() >= 2 && &s[0..2] == "0x" {
|
if s.len() >= 2 && &s[0..2] == "0x" {
|
||||||
U256::from_str(&s[2..]).unwrap_or(U256::from(0))
|
U256::from_str(&s[2..]).unwrap_or_else(|_| U256::zero())
|
||||||
} else {
|
} else {
|
||||||
U256::from_dec_str(s).unwrap_or(U256::from(0))
|
U256::from_dec_str(s).unwrap_or_else(|_| U256::zero())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,8 +20,8 @@ impl FromJson for Bytes {
|
|||||||
fn from_json(json: &Json) -> Self {
|
fn from_json(json: &Json) -> Self {
|
||||||
match *json {
|
match *json {
|
||||||
Json::String(ref s) => match s.len() % 2 {
|
Json::String(ref s) => match s.len() % 2 {
|
||||||
0 => FromHex::from_hex(clean(s)).unwrap_or(vec![]),
|
0 => FromHex::from_hex(clean(s)).unwrap_or_else(|_| vec![]),
|
||||||
_ => FromHex::from_hex(&("0".to_owned() + &(clean(s).to_owned()))[..]).unwrap_or(vec![]),
|
_ => FromHex::from_hex(&("0".to_owned() + &(clean(s).to_owned()))[..]).unwrap_or_else(|_| vec![]),
|
||||||
},
|
},
|
||||||
_ => vec![],
|
_ => vec![],
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#![feature(op_assign_traits)]
|
#![feature(op_assign_traits)]
|
||||||
#![feature(augmented_assignments)]
|
#![feature(augmented_assignments)]
|
||||||
#![feature(associated_consts)]
|
#![feature(associated_consts)]
|
||||||
|
#![feature(plugin)]
|
||||||
|
#![plugin(clippy)]
|
||||||
#![allow(needless_range_loop, match_bool)]
|
#![allow(needless_range_loop, match_bool)]
|
||||||
//! Ethcore-util library
|
//! Ethcore-util library
|
||||||
//!
|
//!
|
||||||
|
@ -15,25 +15,25 @@ fn rlp_at() {
|
|||||||
assert!(rlp.is_list());
|
assert!(rlp.is_list());
|
||||||
//let animals = <Vec<String> as rlp::Decodable>::decode_untrusted(&rlp).unwrap();
|
//let animals = <Vec<String> as rlp::Decodable>::decode_untrusted(&rlp).unwrap();
|
||||||
let animals: Vec<String> = rlp.as_val().unwrap();
|
let animals: Vec<String> = rlp.as_val().unwrap();
|
||||||
assert_eq!(animals, vec!["cat".to_string(), "dog".to_string()]);
|
assert_eq!(animals, vec!["cat".to_owned(), "dog".to_owned()]);
|
||||||
|
|
||||||
let cat = rlp.at(0).unwrap();
|
let cat = rlp.at(0).unwrap();
|
||||||
assert!(cat.is_data());
|
assert!(cat.is_data());
|
||||||
assert_eq!(cat.as_raw(), &[0x83, b'c', b'a', b't']);
|
assert_eq!(cat.as_raw(), &[0x83, b'c', b'a', b't']);
|
||||||
//assert_eq!(String::decode_untrusted(&cat).unwrap(), "cat".to_string());
|
//assert_eq!(String::decode_untrusted(&cat).unwrap(), "cat".to_owned());
|
||||||
assert_eq!(cat.as_val::<String>().unwrap(), "cat".to_string());
|
assert_eq!(cat.as_val::<String>().unwrap(), "cat".to_owned());
|
||||||
|
|
||||||
let dog = rlp.at(1).unwrap();
|
let dog = rlp.at(1).unwrap();
|
||||||
assert!(dog.is_data());
|
assert!(dog.is_data());
|
||||||
assert_eq!(dog.as_raw(), &[0x83, b'd', b'o', b'g']);
|
assert_eq!(dog.as_raw(), &[0x83, b'd', b'o', b'g']);
|
||||||
//assert_eq!(String::decode_untrusted(&dog).unwrap(), "dog".to_string());
|
//assert_eq!(String::decode_untrusted(&dog).unwrap(), "dog".to_owned());
|
||||||
assert_eq!(dog.as_val::<String>().unwrap(), "dog".to_string());
|
assert_eq!(dog.as_val::<String>().unwrap(), "dog".to_owned());
|
||||||
|
|
||||||
let cat_again = rlp.at(0).unwrap();
|
let cat_again = rlp.at(0).unwrap();
|
||||||
assert!(cat_again.is_data());
|
assert!(cat_again.is_data());
|
||||||
assert_eq!(cat_again.as_raw(), &[0x83, b'c', b'a', b't']);
|
assert_eq!(cat_again.as_raw(), &[0x83, b'c', b'a', b't']);
|
||||||
//assert_eq!(String::decode_untrusted(&cat_again).unwrap(), "cat".to_string());
|
//assert_eq!(String::decode_untrusted(&cat_again).unwrap(), "cat".to_owned());
|
||||||
assert_eq!(cat_again.as_val::<String>().unwrap(), "cat".to_string());
|
assert_eq!(cat_again.as_val::<String>().unwrap(), "cat".to_owned());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,13 +268,13 @@ fn decode_untrusted_u256() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn decode_untrusted_str() {
|
fn decode_untrusted_str() {
|
||||||
let tests = vec![DTestPair("cat".to_string(), vec![0x83, b'c', b'a', b't']),
|
let tests = vec![DTestPair("cat".to_owned(), vec![0x83, b'c', b'a', b't']),
|
||||||
DTestPair("dog".to_string(), vec![0x83, b'd', b'o', b'g']),
|
DTestPair("dog".to_owned(), vec![0x83, b'd', b'o', b'g']),
|
||||||
DTestPair("Marek".to_string(),
|
DTestPair("Marek".to_owned(),
|
||||||
vec![0x85, b'M', b'a', b'r', b'e', b'k']),
|
vec![0x85, b'M', b'a', b'r', b'e', b'k']),
|
||||||
DTestPair("".to_string(), vec![0x80]),
|
DTestPair("".to_owned(), vec![0x80]),
|
||||||
DTestPair("Lorem ipsum dolor sit amet, consectetur adipisicing elit"
|
DTestPair("Lorem ipsum dolor sit amet, consectetur adipisicing elit"
|
||||||
.to_string(),
|
.to_owned(),
|
||||||
vec![0xb8, 0x38, b'L', b'o', b'r', b'e', b'm', b' ', b'i',
|
vec![0xb8, 0x38, b'L', b'o', b'r', b'e', b'm', b' ', b'i',
|
||||||
b'p', b's', b'u', b'm', b' ', b'd', b'o', b'l', b'o',
|
b'p', b's', b'u', b'm', b' ', b'd', b'o', b'l', b'o',
|
||||||
b'r', b' ', b's', b'i', b't', b' ', b'a', b'm', b'e',
|
b'r', b' ', b's', b'i', b't', b' ', b'a', b'm', b'e',
|
||||||
@ -311,14 +311,14 @@ fn decode_untrusted_vector_u64() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn decode_untrusted_vector_str() {
|
fn decode_untrusted_vector_str() {
|
||||||
let tests = vec![DTestPair(vec!["cat".to_string(), "dog".to_string()],
|
let tests = vec![DTestPair(vec!["cat".to_owned(), "dog".to_owned()],
|
||||||
vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g'])];
|
vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g'])];
|
||||||
run_decode_tests(tests);
|
run_decode_tests(tests);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn decode_untrusted_vector_of_vectors_str() {
|
fn decode_untrusted_vector_of_vectors_str() {
|
||||||
let tests = vec![DTestPair(vec![vec!["cat".to_string()]],
|
let tests = vec![DTestPair(vec![vec!["cat".to_owned()]],
|
||||||
vec![0xc5, 0xc4, 0x83, b'c', b'a', b't'])];
|
vec![0xc5, 0xc4, 0x83, b'c', b'a', b't'])];
|
||||||
run_decode_tests(tests);
|
run_decode_tests(tests);
|
||||||
}
|
}
|
||||||
|
@ -692,7 +692,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn populate_trie<'db>(db: &'db mut HashDB, root: &'db mut H256, v: &Vec<(Vec<u8>, Vec<u8>)>) -> TrieDBMut<'db> {
|
fn populate_trie<'db>(db: &'db mut HashDB, root: &'db mut H256, v: &[(Vec<u8>, Vec<u8>)]) -> TrieDBMut<'db> {
|
||||||
let mut t = TrieDBMut::new(db, root);
|
let mut t = TrieDBMut::new(db, root);
|
||||||
for i in 0..v.len() {
|
for i in 0..v.len() {
|
||||||
let key: &[u8]= &v[i].0;
|
let key: &[u8]= &v[i].0;
|
||||||
@ -702,8 +702,8 @@ mod tests {
|
|||||||
t
|
t
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unpopulate_trie<'a, 'db>(t: &mut TrieDBMut<'db>, v: &Vec<(Vec<u8>, Vec<u8>)>) {
|
fn unpopulate_trie<'db>(t: &mut TrieDBMut<'db>, v: &[(Vec<u8>, Vec<u8>)]) {
|
||||||
for i in &v {
|
for i in v {
|
||||||
let key: &[u8]= &i.0;
|
let key: &[u8]= &i.0;
|
||||||
t.remove(&key);
|
t.remove(&key);
|
||||||
}
|
}
|
||||||
@ -759,7 +759,7 @@ mod tests {
|
|||||||
println!("TRIE MISMATCH");
|
println!("TRIE MISMATCH");
|
||||||
println!("");
|
println!("");
|
||||||
println!("{:?} vs {:?}", memtrie.root(), real);
|
println!("{:?} vs {:?}", memtrie.root(), real);
|
||||||
for i in x.iter() {
|
for i in &x {
|
||||||
println!("{:?} -> {:?}", i.0.pretty(), i.1.pretty());
|
println!("{:?} -> {:?}", i.0.pretty(), i.1.pretty());
|
||||||
}
|
}
|
||||||
println!("{:?}", memtrie);
|
println!("{:?}", memtrie);
|
||||||
@ -772,7 +772,7 @@ mod tests {
|
|||||||
println!("");
|
println!("");
|
||||||
println!("remaining: {:?}", memtrie.db_items_remaining());
|
println!("remaining: {:?}", memtrie.db_items_remaining());
|
||||||
println!("{:?} vs {:?}", memtrie.root(), real);
|
println!("{:?} vs {:?}", memtrie.root(), real);
|
||||||
for i in x.iter() {
|
for i in &x {
|
||||||
println!("{:?} -> {:?}", i.0.pretty(), i.1.pretty());
|
println!("{:?} -> {:?}", i.0.pretty(), i.1.pretty());
|
||||||
}
|
}
|
||||||
println!("{:?}", memtrie);
|
println!("{:?}", memtrie);
|
||||||
@ -1049,12 +1049,12 @@ mod tests {
|
|||||||
println!("TRIE MISMATCH");
|
println!("TRIE MISMATCH");
|
||||||
println!("");
|
println!("");
|
||||||
println!("ORIGINAL... {:?}", memtrie.root());
|
println!("ORIGINAL... {:?}", memtrie.root());
|
||||||
for i in x.iter() {
|
for i in &x {
|
||||||
println!("{:?} -> {:?}", i.0.pretty(), i.1.pretty());
|
println!("{:?} -> {:?}", i.0.pretty(), i.1.pretty());
|
||||||
}
|
}
|
||||||
println!("{:?}", memtrie);
|
println!("{:?}", memtrie);
|
||||||
println!("SORTED... {:?}", memtrie_sorted.root());
|
println!("SORTED... {:?}", memtrie_sorted.root());
|
||||||
for i in y.iter() {
|
for i in &y {
|
||||||
println!("{:?} -> {:?}", i.0.pretty(), i.1.pretty());
|
println!("{:?} -> {:?}", i.0.pretty(), i.1.pretty());
|
||||||
}
|
}
|
||||||
println!("{:?}", memtrie_sorted);
|
println!("{:?}", memtrie_sorted);
|
||||||
|
@ -437,9 +437,9 @@ macro_rules! construct_uint {
|
|||||||
match *json {
|
match *json {
|
||||||
Json::String(ref s) => {
|
Json::String(ref s) => {
|
||||||
if s.len() >= 2 && &s[0..2] == "0x" {
|
if s.len() >= 2 && &s[0..2] == "0x" {
|
||||||
FromStr::from_str(&s[2..]).unwrap_or(Default::default())
|
FromStr::from_str(&s[2..]).unwrap_or_else(|_| Default::default())
|
||||||
} else {
|
} else {
|
||||||
Uint::from_dec_str(s).unwrap_or(Default::default())
|
Uint::from_dec_str(s).unwrap_or_else(|_| Default::default())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Json::U64(u) => From::from(u),
|
Json::U64(u) => From::from(u),
|
||||||
@ -1046,6 +1046,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(eq_op)]
|
||||||
pub fn uint256_comp_test() {
|
pub fn uint256_comp_test() {
|
||||||
let small = U256([10u64, 0, 0, 0]);
|
let small = U256([10u64, 0, 0, 0]);
|
||||||
let big = U256([0x8C8C3EE70C644118u64, 0x0209E7378231E632, 0, 0]);
|
let big = U256([0x8C8C3EE70C644118u64, 0x0209E7378231E632, 0, 0]);
|
||||||
|
Loading…
Reference in New Issue
Block a user