From c30d2bb3e7f7e707d177be994fdd7d3b6837fe2d Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 27 Jan 2016 17:24:11 +0100 Subject: [PATCH] Add homestead & random tests. --- src/tests/chain.rs | 3 ++ src/tests/homestead_chain.rs | 67 ++++++++++++++++++++++++++++++++++++ src/tests/mod.rs | 1 + 3 files changed, 71 insertions(+) create mode 100644 src/tests/homestead_chain.rs diff --git a/src/tests/chain.rs b/src/tests/chain.rs index 42b4ee78a..613d9f6ff 100644 --- a/src/tests/chain.rs +++ b/src/tests/chain.rs @@ -67,3 +67,6 @@ declare_test!{BlockchainTests_bcUncleHeaderValiditiy, "BlockchainTests/bcUncleHe declare_test!{BlockchainTests_bcUncleTest, "BlockchainTests/bcUncleTest"} declare_test!{BlockchainTests_bcValidBlockTest, "BlockchainTests/bcValidBlockTest"} declare_test!{BlockchainTests_bcWalletTest, "BlockchainTests/bcWalletTest"} + +declare_test!{BlockchainTests_RandomTests_bl10251623GO, "BlockchainTests/RandomTests/bl10251623GO"} +declare_test!{BlockchainTests_RandomTests_bl201507071825GO, "BlockchainTests/RandomTests/bl201507071825GO"} diff --git a/src/tests/homestead_chain.rs b/src/tests/homestead_chain.rs new file mode 100644 index 000000000..5d090aefb --- /dev/null +++ b/src/tests/homestead_chain.rs @@ -0,0 +1,67 @@ +use std::env; +use super::test_common::*; +use client::{BlockChainClient,Client}; +use pod_state::*; +use block::Block; +use ethereum; + +fn do_json_test(json_data: &[u8]) -> Vec { + let json = Json::from_str(::std::str::from_utf8(json_data).unwrap()).expect("Json is invalid"); + let mut failed = Vec::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.clone()); + flush(format!("FAIL\n")); + fail = true; + true + } else {false}; + + flush(format!(" - {}...", name)); + + let blocks: Vec<(Bytes, bool)> = test["blocks"].as_array().unwrap().iter().map(|e| (xjson!(&e["rlp"]), e.find("blockHeader").is_some())).collect(); + let mut spec = ethereum::new_homestead_test(); + let s = PodState::from_json(test.find("pre").unwrap()); + spec.set_genesis_state(s); + spec.overwrite_genesis(test.find("genesisBlockHeader").unwrap()); + assert!(spec.is_state_root_valid()); + + let mut dir = env::temp_dir(); + dir.push(H32::random().hex()); + { + let client = Client::new(spec, &dir, IoChannel::disconnected()).unwrap(); + for (b, is_valid) in blocks.into_iter() { + if Block::is_good(&b) { + let _ = client.import_block(b.clone()); + } + client.flush_queue(); + let imported_ok = client.import_verified_blocks(&IoChannel::disconnected()) > 0; + assert_eq!(imported_ok, is_valid); + } + fail_unless(client.chain_info().best_block_hash == H256::from_json(&test["lastblockhash"])); + } + fs::remove_dir_all(&dir).unwrap(); + } + if !fail { + flush(format!("ok\n")); + } + } + println!("!!! {:?} tests from failed.", failed.len()); + failed +} + +declare_test!{BlockchainTests_Homestead_bcBlockGasLimitTest, "BlockchainTests/Homestead/bcBlockGasLimitTest"} +declare_test!{BlockchainTests_Homestead_bcForkStressTest, "BlockchainTests/Homestead/bcForkStressTest"} +declare_test!{BlockchainTests_Homestead_bcGasPricerTest, "BlockchainTests/Homestead/bcGasPricerTest"} +declare_test!{BlockchainTests_Homestead_bcInvalidHeaderTest, "BlockchainTests/Homestead/bcInvalidHeaderTest"} +declare_test!{BlockchainTests_Homestead_bcInvalidRLPTest, "BlockchainTests/Homestead/bcInvalidRLPTest"} +declare_test!{BlockchainTests_Homestead_bcMultiChainTest, "BlockchainTests/Homestead/bcMultiChainTest"} +declare_test!{BlockchainTests_Homestead_bcRPC_API_Test, "BlockchainTests/Homestead/bcRPC_API_Test"} +declare_test!{BlockchainTests_Homestead_bcStateTest, "BlockchainTests/Homestead/bcStateTest"} +declare_test!{BlockchainTests_Homestead_bcTotalDifficultyTest, "BlockchainTests/Homestead/bcTotalDifficultyTest"} +declare_test!{BlockchainTests_Homestead_bcUncleHeaderValiditiy, "BlockchainTests/Homestead/bcUncleHeaderValiditiy"} +declare_test!{BlockchainTests_Homestead_bcUncleTest, "BlockchainTests/Homestead/bcUncleTest"} +declare_test!{BlockchainTests_Homestead_bcValidBlockTest, "BlockchainTests/Homestead/bcValidBlockTest"} +declare_test!{BlockchainTests_Homestead_bcWalletTest, "BlockchainTests/Homestead/bcWalletTest"} diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 17da72d77..73dc6ef9a 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -6,4 +6,5 @@ mod executive; mod state; mod client; mod chain; +mod homestead_chain; mod helpers; \ No newline at end of file