Merge pull request #246 from ethcore/temp-dir-refact

temp dir spawn refactoring
This commit is contained in:
Gav Wood 2016-01-28 17:17:13 +01:00
commit d9e8a59cd2
4 changed files with 14 additions and 22 deletions

@ -1 +1 @@
Subproject commit c670b1d8c9f09593a6758ab2c099360e16c7c25b Subproject commit e838fd90998fc5502d0b7c9427a4c231f9a6953d

View File

@ -618,20 +618,18 @@ impl BlockChain {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::env;
use std::str::FromStr; use std::str::FromStr;
use rustc_serialize::hex::FromHex; use rustc_serialize::hex::FromHex;
use util::hash::*; use util::hash::*;
use blockchain::*; use blockchain::*;
use tests::helpers::*;
#[test] #[test]
fn valid_tests_extra32() { fn valid_tests_extra32() {
let genesis = "f901fcf901f7a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0925002c3260b44e44c3edebad1cc442142b03020209df1ab8bb86752edbd2cd7a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000080832fefd8808454c98c8142a0363659b251bf8b819179874c8cce7b9b983d7f3704cbb58a3b334431f7032871889032d09c281e1236c0c0".from_hex().unwrap(); let genesis = "f901fcf901f7a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0925002c3260b44e44c3edebad1cc442142b03020209df1ab8bb86752edbd2cd7a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000080832fefd8808454c98c8142a0363659b251bf8b819179874c8cce7b9b983d7f3704cbb58a3b334431f7032871889032d09c281e1236c0c0".from_hex().unwrap();
let mut dir = env::temp_dir(); let temp = RandomTempPath::new();
dir.push(H32::random().hex()); let bc = BlockChain::new(&genesis, temp.as_path());
let bc = BlockChain::new(&genesis, &dir);
let genesis_hash = H256::from_str("3caa2203f3d7c136c0295ed128a7d31cea520b1ca5e27afe17d0853331798942").unwrap(); let genesis_hash = H256::from_str("3caa2203f3d7c136c0295ed128a7d31cea520b1ca5e27afe17d0853331798942").unwrap();
@ -674,10 +672,8 @@ mod tests {
// b3a is a part of canon chain, whereas b3b is part of sidechain // b3a is a part of canon chain, whereas b3b is part of sidechain
let best_block_hash = H256::from_str("c208f88c9f5bf7e00840439742c12e5226d9752981f3ec0521bdcb6dd08af277").unwrap(); let best_block_hash = H256::from_str("c208f88c9f5bf7e00840439742c12e5226d9752981f3ec0521bdcb6dd08af277").unwrap();
let mut dir = env::temp_dir(); let temp = RandomTempPath::new();
dir.push(H32::random().hex()); let bc = BlockChain::new(&genesis, temp.as_path());
let bc = BlockChain::new(&genesis, &dir);
bc.insert_block(&b1); bc.insert_block(&b1);
bc.insert_block(&b2); bc.insert_block(&b2);
bc.insert_block(&b3a); bc.insert_block(&b3a);
@ -754,18 +750,16 @@ mod tests {
let genesis_hash = H256::from_str("5716670833ec874362d65fea27a7cd35af5897d275b31a44944113111e4e96d2").unwrap(); let genesis_hash = H256::from_str("5716670833ec874362d65fea27a7cd35af5897d275b31a44944113111e4e96d2").unwrap();
let b1_hash = H256::from_str("437e51676ff10756fcfee5edd9159fa41dbcb1b2c592850450371cbecd54ee4f").unwrap(); let b1_hash = H256::from_str("437e51676ff10756fcfee5edd9159fa41dbcb1b2c592850450371cbecd54ee4f").unwrap();
let mut dir = env::temp_dir(); let temp = RandomTempPath::new();
dir.push(H32::random().hex());
{ {
let bc = BlockChain::new(&genesis, &dir); let bc = BlockChain::new(&genesis, temp.as_path());
assert_eq!(bc.best_block_hash(), genesis_hash); assert_eq!(bc.best_block_hash(), genesis_hash);
bc.insert_block(&b1); bc.insert_block(&b1);
assert_eq!(bc.best_block_hash(), b1_hash); assert_eq!(bc.best_block_hash(), b1_hash);
} }
{ {
let bc = BlockChain::new(&genesis, &dir); let bc = BlockChain::new(&genesis, temp.as_path());
assert_eq!(bc.best_block_hash(), b1_hash); assert_eq!(bc.best_block_hash(), b1_hash);
} }
} }

View File

@ -1,9 +1,9 @@
use std::env;
use super::test_common::*; use super::test_common::*;
use client::{BlockChainClient,Client}; use client::{BlockChainClient,Client};
use pod_state::*; use pod_state::*;
use block::Block; use block::Block;
use ethereum; use ethereum;
use super::helpers::*;
pub enum ChainEra { pub enum ChainEra {
Frontier, Frontier,
@ -36,10 +36,9 @@ pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
spec.overwrite_genesis(test.find("genesisBlockHeader").unwrap()); spec.overwrite_genesis(test.find("genesisBlockHeader").unwrap());
assert!(spec.is_state_root_valid()); assert!(spec.is_state_root_valid());
let mut dir = env::temp_dir(); let temp = RandomTempPath::new();
dir.push(H32::random().hex());
{ {
let client = Client::new(spec, &dir, IoChannel::disconnected()).unwrap(); let client = Client::new(spec, temp.as_path(), IoChannel::disconnected()).unwrap();
for (b, is_valid) in blocks.into_iter() { for (b, is_valid) in blocks.into_iter() {
if Block::is_good(&b) { if Block::is_good(&b) {
let _ = client.import_block(b.clone()); let _ = client.import_block(b.clone());
@ -50,7 +49,6 @@ pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
} }
fail_unless(client.chain_info().best_block_hash == H256::from_json(&test["lastblockhash"])); fail_unless(client.chain_info().best_block_hash == H256::from_json(&test["lastblockhash"]));
} }
fs::remove_dir_all(&dir).unwrap();
} }
if !fail { if !fail {
flush(format!("ok\n")); flush(format!("ok\n"));

View File

@ -6,5 +6,5 @@ mod executive;
mod state; mod state;
mod client; mod client;
mod chain; mod chain;
mod homestead_chain; pub mod helpers;
mod helpers; mod homestead_chain;