Merge pull request #3431 from ethcore/state-tests-indentation

indent state tests
This commit is contained in:
Robert Habermeier 2016-12-02 09:09:35 +01:00 committed by GitHub
commit 3837114eb2

View File

@ -790,22 +790,22 @@ impl Clone for State {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::sync::Arc; use std::sync::Arc;
use std::str::FromStr; use std::str::FromStr;
use rustc_serialize::hex::FromHex; use rustc_serialize::hex::FromHex;
use super::*; use super::*;
use util::{U256, H256, FixedHash, Address, Hashable}; use util::{U256, H256, FixedHash, Address, Hashable};
use tests::helpers::*; use tests::helpers::*;
use devtools::*; use devtools::*;
use env_info::EnvInfo; use env_info::EnvInfo;
use spec::*; use spec::*;
use transaction::*; use transaction::*;
use util::log::init_log; use util::log::init_log;
use trace::{FlatTrace, TraceError, trace}; use trace::{FlatTrace, TraceError, trace};
use types::executed::CallType; use types::executed::CallType;
#[test] #[test]
fn should_apply_create_transaction() { fn should_apply_create_transaction() {
init_log(); init_log();
let temp = RandomTempPath::new(); let temp = RandomTempPath::new();
@ -843,10 +843,10 @@ fn should_apply_create_transaction() {
}]; }];
assert_eq!(result.trace, expected_trace); assert_eq!(result.trace, expected_trace);
} }
#[test] #[test]
fn should_work_when_cloned() { fn should_work_when_cloned() {
init_log(); init_log();
let a = Address::zero(); let a = Address::zero();
@ -862,10 +862,10 @@ fn should_work_when_cloned() {
state.inc_nonce(&a); state.inc_nonce(&a);
state.commit().unwrap(); state.commit().unwrap();
} }
#[test] #[test]
fn should_trace_failed_create_transaction() { fn should_trace_failed_create_transaction() {
init_log(); init_log();
let temp = RandomTempPath::new(); let temp = RandomTempPath::new();
@ -899,10 +899,10 @@ fn should_trace_failed_create_transaction() {
}]; }];
assert_eq!(result.trace, expected_trace); assert_eq!(result.trace, expected_trace);
} }
#[test] #[test]
fn should_trace_call_transaction() { fn should_trace_call_transaction() {
init_log(); init_log();
let temp = RandomTempPath::new(); let temp = RandomTempPath::new();
@ -942,10 +942,10 @@ fn should_trace_call_transaction() {
}]; }];
assert_eq!(result.trace, expected_trace); assert_eq!(result.trace, expected_trace);
} }
#[test] #[test]
fn should_trace_basic_call_transaction() { fn should_trace_basic_call_transaction() {
init_log(); init_log();
let temp = RandomTempPath::new(); let temp = RandomTempPath::new();
@ -984,10 +984,10 @@ fn should_trace_basic_call_transaction() {
}]; }];
assert_eq!(result.trace, expected_trace); assert_eq!(result.trace, expected_trace);
} }
#[test] #[test]
fn should_trace_call_transaction_to_builtin() { fn should_trace_call_transaction_to_builtin() {
init_log(); init_log();
let temp = RandomTempPath::new(); let temp = RandomTempPath::new();
@ -1026,10 +1026,10 @@ fn should_trace_call_transaction_to_builtin() {
}]; }];
assert_eq!(result.trace, expected_trace); assert_eq!(result.trace, expected_trace);
} }
#[test] #[test]
fn should_not_trace_subcall_transaction_to_builtin() { fn should_not_trace_subcall_transaction_to_builtin() {
init_log(); init_log();
let temp = RandomTempPath::new(); let temp = RandomTempPath::new();
@ -1069,10 +1069,10 @@ fn should_not_trace_subcall_transaction_to_builtin() {
}]; }];
assert_eq!(result.trace, expected_trace); assert_eq!(result.trace, expected_trace);
} }
#[test] #[test]
fn should_not_trace_callcode() { fn should_not_trace_callcode() {
init_log(); init_log();
let temp = RandomTempPath::new(); let temp = RandomTempPath::new();
@ -1128,10 +1128,10 @@ fn should_not_trace_callcode() {
}]; }];
assert_eq!(result.trace, expected_trace); assert_eq!(result.trace, expected_trace);
} }
#[test] #[test]
fn should_not_trace_delegatecall() { fn should_not_trace_delegatecall() {
init_log(); init_log();
let temp = RandomTempPath::new(); let temp = RandomTempPath::new();
@ -1190,10 +1190,10 @@ fn should_not_trace_delegatecall() {
}]; }];
assert_eq!(result.trace, expected_trace); assert_eq!(result.trace, expected_trace);
} }
#[test] #[test]
fn should_trace_failed_call_transaction() { fn should_trace_failed_call_transaction() {
init_log(); init_log();
let temp = RandomTempPath::new(); let temp = RandomTempPath::new();
@ -1230,10 +1230,10 @@ fn should_trace_failed_call_transaction() {
}]; }];
assert_eq!(result.trace, expected_trace); assert_eq!(result.trace, expected_trace);
} }
#[test] #[test]
fn should_trace_call_with_subcall_transaction() { fn should_trace_call_with_subcall_transaction() {
init_log(); init_log();
let temp = RandomTempPath::new(); let temp = RandomTempPath::new();
@ -1290,10 +1290,10 @@ fn should_trace_call_with_subcall_transaction() {
}]; }];
assert_eq!(result.trace, expected_trace); assert_eq!(result.trace, expected_trace);
} }
#[test] #[test]
fn should_trace_call_with_basic_subcall_transaction() { fn should_trace_call_with_basic_subcall_transaction() {
init_log(); init_log();
let temp = RandomTempPath::new(); let temp = RandomTempPath::new();
@ -1345,10 +1345,10 @@ fn should_trace_call_with_basic_subcall_transaction() {
}]; }];
assert_eq!(result.trace, expected_trace); assert_eq!(result.trace, expected_trace);
} }
#[test] #[test]
fn should_not_trace_call_with_invalid_basic_subcall_transaction() { fn should_not_trace_call_with_invalid_basic_subcall_transaction() {
init_log(); init_log();
let temp = RandomTempPath::new(); let temp = RandomTempPath::new();
@ -1388,10 +1388,10 @@ fn should_not_trace_call_with_invalid_basic_subcall_transaction() {
}]; }];
assert_eq!(result.trace, expected_trace); assert_eq!(result.trace, expected_trace);
} }
#[test] #[test]
fn should_trace_failed_subcall_transaction() { fn should_trace_failed_subcall_transaction() {
init_log(); init_log();
let temp = RandomTempPath::new(); let temp = RandomTempPath::new();
@ -1444,10 +1444,10 @@ fn should_trace_failed_subcall_transaction() {
}]; }];
assert_eq!(result.trace, expected_trace); assert_eq!(result.trace, expected_trace);
} }
#[test] #[test]
fn should_trace_call_with_subcall_with_subcall_transaction() { fn should_trace_call_with_subcall_with_subcall_transaction() {
init_log(); init_log();
let temp = RandomTempPath::new(); let temp = RandomTempPath::new();
@ -1519,10 +1519,10 @@ fn should_trace_call_with_subcall_with_subcall_transaction() {
}]; }];
assert_eq!(result.trace, expected_trace); assert_eq!(result.trace, expected_trace);
} }
#[test] #[test]
fn should_trace_failed_subcall_with_subcall_transaction() { fn should_trace_failed_subcall_with_subcall_transaction() {
init_log(); init_log();
let temp = RandomTempPath::new(); let temp = RandomTempPath::new();
@ -1592,10 +1592,10 @@ fn should_trace_failed_subcall_with_subcall_transaction() {
}]; }];
assert_eq!(result.trace, expected_trace); assert_eq!(result.trace, expected_trace);
} }
#[test] #[test]
fn should_trace_suicide() { fn should_trace_suicide() {
init_log(); init_log();
let temp = RandomTempPath::new(); let temp = RandomTempPath::new();
@ -1645,10 +1645,10 @@ fn should_trace_suicide() {
}]; }];
assert_eq!(result.trace, expected_trace); assert_eq!(result.trace, expected_trace);
} }
#[test] #[test]
fn code_from_database() { fn code_from_database() {
let a = Address::zero(); let a = Address::zero();
let temp = RandomTempPath::new(); let temp = RandomTempPath::new();
let (root, db) = { let (root, db) = {
@ -1663,10 +1663,10 @@ fn code_from_database() {
let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap(); let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
assert_eq!(state.code(&a), Some(Arc::new([1u8, 2, 3].to_vec()))); assert_eq!(state.code(&a), Some(Arc::new([1u8, 2, 3].to_vec())));
} }
#[test] #[test]
fn storage_at_from_database() { fn storage_at_from_database() {
let a = Address::zero(); let a = Address::zero();
let temp = RandomTempPath::new(); let temp = RandomTempPath::new();
let (root, db) = { let (root, db) = {
@ -1678,10 +1678,10 @@ fn storage_at_from_database() {
let s = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap(); let s = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
assert_eq!(s.storage_at(&a, &H256::from(&U256::from(1u64))), H256::from(&U256::from(69u64))); assert_eq!(s.storage_at(&a, &H256::from(&U256::from(1u64))), H256::from(&U256::from(69u64)));
} }
#[test] #[test]
fn get_from_database() { fn get_from_database() {
let a = Address::zero(); let a = Address::zero();
let temp = RandomTempPath::new(); let temp = RandomTempPath::new();
let (root, db) = { let (root, db) = {
@ -1696,10 +1696,10 @@ fn get_from_database() {
let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap(); let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
assert_eq!(state.balance(&a), U256::from(69u64)); assert_eq!(state.balance(&a), U256::from(69u64));
assert_eq!(state.nonce(&a), U256::from(1u64)); assert_eq!(state.nonce(&a), U256::from(1u64));
} }
#[test] #[test]
fn remove() { fn remove() {
let a = Address::zero(); let a = Address::zero();
let mut state_result = get_temp_state(); let mut state_result = get_temp_state();
let mut state = state_result.reference_mut(); let mut state = state_result.reference_mut();
@ -1713,10 +1713,10 @@ fn remove() {
assert_eq!(state.exists(&a), false); assert_eq!(state.exists(&a), false);
assert_eq!(state.exists_and_not_null(&a), false); assert_eq!(state.exists_and_not_null(&a), false);
assert_eq!(state.nonce(&a), U256::from(0u64)); assert_eq!(state.nonce(&a), U256::from(0u64));
} }
#[test] #[test]
fn empty_account_is_not_created() { fn empty_account_is_not_created() {
let a = Address::zero(); let a = Address::zero();
let path = RandomTempPath::new(); let path = RandomTempPath::new();
let db = get_temp_state_db_in(path.as_path()); let db = get_temp_state_db_in(path.as_path());
@ -1729,10 +1729,10 @@ fn empty_account_is_not_created() {
let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap(); let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
assert!(!state.exists(&a)); assert!(!state.exists(&a));
assert!(!state.exists_and_not_null(&a)); assert!(!state.exists_and_not_null(&a));
} }
#[test] #[test]
fn empty_account_exists_when_creation_forced() { fn empty_account_exists_when_creation_forced() {
let a = Address::zero(); let a = Address::zero();
let path = RandomTempPath::new(); let path = RandomTempPath::new();
let db = get_temp_state_db_in(path.as_path()); let db = get_temp_state_db_in(path.as_path());
@ -1745,10 +1745,10 @@ fn empty_account_exists_when_creation_forced() {
let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap(); let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
assert!(state.exists(&a)); assert!(state.exists(&a));
assert!(!state.exists_and_not_null(&a)); assert!(!state.exists_and_not_null(&a));
} }
#[test] #[test]
fn remove_from_database() { fn remove_from_database() {
let a = Address::zero(); let a = Address::zero();
let temp = RandomTempPath::new(); let temp = RandomTempPath::new();
let (root, db) = { let (root, db) = {
@ -1774,10 +1774,10 @@ fn remove_from_database() {
let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap(); let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
assert_eq!(state.exists(&a), false); assert_eq!(state.exists(&a), false);
assert_eq!(state.nonce(&a), U256::from(0u64)); assert_eq!(state.nonce(&a), U256::from(0u64));
} }
#[test] #[test]
fn alter_balance() { fn alter_balance() {
let mut state_result = get_temp_state(); let mut state_result = get_temp_state();
let mut state = state_result.reference_mut(); let mut state = state_result.reference_mut();
let a = Address::zero(); let a = Address::zero();
@ -1796,10 +1796,10 @@ fn alter_balance() {
state.commit().unwrap(); state.commit().unwrap();
assert_eq!(state.balance(&a), U256::from(9u64)); assert_eq!(state.balance(&a), U256::from(9u64));
assert_eq!(state.balance(&b), U256::from(18u64)); assert_eq!(state.balance(&b), U256::from(18u64));
} }
#[test] #[test]
fn alter_nonce() { fn alter_nonce() {
let mut state_result = get_temp_state(); let mut state_result = get_temp_state();
let mut state = state_result.reference_mut(); let mut state = state_result.reference_mut();
let a = Address::zero(); let a = Address::zero();
@ -1813,10 +1813,10 @@ fn alter_nonce() {
assert_eq!(state.nonce(&a), U256::from(3u64)); assert_eq!(state.nonce(&a), U256::from(3u64));
state.commit().unwrap(); state.commit().unwrap();
assert_eq!(state.nonce(&a), U256::from(3u64)); assert_eq!(state.nonce(&a), U256::from(3u64));
} }
#[test] #[test]
fn balance_nonce() { fn balance_nonce() {
let mut state_result = get_temp_state(); let mut state_result = get_temp_state();
let mut state = state_result.reference_mut(); let mut state = state_result.reference_mut();
let a = Address::zero(); let a = Address::zero();
@ -1825,20 +1825,20 @@ fn balance_nonce() {
state.commit().unwrap(); state.commit().unwrap();
assert_eq!(state.balance(&a), U256::from(0u64)); assert_eq!(state.balance(&a), U256::from(0u64));
assert_eq!(state.nonce(&a), U256::from(0u64)); assert_eq!(state.nonce(&a), U256::from(0u64));
} }
#[test] #[test]
fn ensure_cached() { fn ensure_cached() {
let mut state_result = get_temp_state(); let mut state_result = get_temp_state();
let mut state = state_result.reference_mut(); let mut state = state_result.reference_mut();
let a = Address::zero(); let a = Address::zero();
state.require(&a, false); state.require(&a, false);
state.commit().unwrap(); state.commit().unwrap();
assert_eq!(state.root().hex(), "0ce23f3c809de377b008a4a3ee94a0834aac8bec1f86e28ffe4fdb5a15b0c785"); assert_eq!(state.root().hex(), "0ce23f3c809de377b008a4a3ee94a0834aac8bec1f86e28ffe4fdb5a15b0c785");
} }
#[test] #[test]
fn checkpoint_basic() { fn checkpoint_basic() {
let mut state_result = get_temp_state(); let mut state_result = get_temp_state();
let mut state = state_result.reference_mut(); let mut state = state_result.reference_mut();
let a = Address::zero(); let a = Address::zero();
@ -1852,10 +1852,10 @@ fn checkpoint_basic() {
assert_eq!(state.balance(&a), U256::from(70u64)); assert_eq!(state.balance(&a), U256::from(70u64));
state.revert_to_checkpoint(); state.revert_to_checkpoint();
assert_eq!(state.balance(&a), U256::from(69u64)); assert_eq!(state.balance(&a), U256::from(69u64));
} }
#[test] #[test]
fn checkpoint_nested() { fn checkpoint_nested() {
let mut state_result = get_temp_state(); let mut state_result = get_temp_state();
let mut state = state_result.reference_mut(); let mut state = state_result.reference_mut();
let a = Address::zero(); let a = Address::zero();
@ -1867,18 +1867,18 @@ fn checkpoint_nested() {
assert_eq!(state.balance(&a), U256::from(69u64)); assert_eq!(state.balance(&a), U256::from(69u64));
state.revert_to_checkpoint(); state.revert_to_checkpoint();
assert_eq!(state.balance(&a), U256::from(0)); assert_eq!(state.balance(&a), U256::from(0));
} }
#[test] #[test]
fn create_empty() { fn create_empty() {
let mut state_result = get_temp_state(); let mut state_result = get_temp_state();
let mut state = state_result.reference_mut(); let mut state = state_result.reference_mut();
state.commit().unwrap(); state.commit().unwrap();
assert_eq!(state.root().hex(), "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"); assert_eq!(state.root().hex(), "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421");
} }
#[test] #[test]
fn should_not_panic_on_state_diff_with_storage() { fn should_not_panic_on_state_diff_with_storage() {
let state = get_temp_state(); let state = get_temp_state();
let mut state = state.reference().clone(); let mut state = state.reference().clone();
@ -1891,6 +1891,6 @@ fn should_not_panic_on_state_diff_with_storage() {
new_state.set_storage(&a, 0xb.into(), 0xd.into()); new_state.set_storage(&a, 0xb.into(), 0xd.into());
new_state.diff_from(state); new_state.diff_from(state);
} }
} }