2016-02-05 13:40:41 +01:00
|
|
|
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-01-25 18:56:36 +01:00
|
|
|
use super::test_common::*;
|
2016-02-25 17:48:23 +01:00
|
|
|
use client::{BlockChainClient, Client, ClientConfig};
|
2016-01-26 19:18:22 +01:00
|
|
|
use block::Block;
|
2016-01-25 18:56:36 +01:00
|
|
|
use ethereum;
|
2016-02-02 22:50:41 +01:00
|
|
|
use tests::helpers::*;
|
2016-02-19 15:18:20 +01:00
|
|
|
use devtools::*;
|
2016-03-19 18:13:14 +01:00
|
|
|
use spec::Genesis;
|
2016-03-19 18:38:02 +01:00
|
|
|
use ethjson;
|
2016-01-25 18:56:36 +01:00
|
|
|
|
2016-01-27 17:32:12 +01:00
|
|
|
pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
|
2016-01-29 15:01:39 +01:00
|
|
|
init_log();
|
2016-03-19 18:38:02 +01:00
|
|
|
let tests = ethjson::blockchain::Test::load(json_data).unwrap();
|
2016-01-25 18:56:36 +01:00
|
|
|
let mut failed = Vec::new();
|
|
|
|
|
2016-03-24 01:25:59 +01:00
|
|
|
for (name, blockchain) in tests.into_iter() {
|
2016-01-25 18:56:36 +01:00
|
|
|
let mut fail = false;
|
|
|
|
{
|
|
|
|
let mut fail_unless = |cond: bool| if !cond && !fail {
|
|
|
|
failed.push(name.clone());
|
2016-02-03 13:20:32 +01:00
|
|
|
flushln!("FAIL");
|
2016-01-25 18:56:36 +01:00
|
|
|
fail = true;
|
|
|
|
true
|
|
|
|
} else {false};
|
|
|
|
|
2016-02-03 13:20:32 +01:00
|
|
|
flush!(" - {}...", name);
|
2016-01-25 18:56:36 +01:00
|
|
|
|
2016-01-27 17:32:12 +01:00
|
|
|
let mut spec = match era {
|
|
|
|
ChainEra::Frontier => ethereum::new_frontier_test(),
|
|
|
|
ChainEra::Homestead => ethereum::new_homestead_test(),
|
|
|
|
};
|
2016-03-19 18:13:14 +01:00
|
|
|
|
|
|
|
let genesis = Genesis::from(blockchain.genesis());
|
|
|
|
let state = From::from(blockchain.pre_state.clone());
|
|
|
|
spec.set_genesis_state(state);
|
|
|
|
spec.overwrite_genesis_params(genesis);
|
2016-01-25 23:24:51 +01:00
|
|
|
assert!(spec.is_state_root_valid());
|
2016-01-25 18:56:36 +01:00
|
|
|
|
2016-01-27 16:41:50 +01:00
|
|
|
let temp = RandomTempPath::new();
|
2016-01-25 18:56:36 +01:00
|
|
|
{
|
2016-02-25 17:48:23 +01:00
|
|
|
let client = Client::new(ClientConfig::default(), spec, temp.as_path(), IoChannel::disconnected()).unwrap();
|
2016-03-19 18:13:14 +01:00
|
|
|
for b in &blockchain.blocks_rlp() {
|
2016-01-27 13:28:15 +01:00
|
|
|
if Block::is_good(&b) {
|
2016-01-27 16:13:21 +01:00
|
|
|
let _ = client.import_block(b.clone());
|
2016-03-19 18:13:14 +01:00
|
|
|
client.flush_queue();
|
|
|
|
client.import_verified_blocks(&IoChannel::disconnected());
|
2016-01-27 13:28:15 +01:00
|
|
|
}
|
2016-01-26 18:02:49 +01:00
|
|
|
}
|
2016-03-24 01:25:59 +01:00
|
|
|
fail_unless(client.chain_info().best_block_hash == blockchain.best_block.into());
|
2016-01-25 18:56:36 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-19 18:13:14 +01:00
|
|
|
|
2016-01-25 18:56:36 +01:00
|
|
|
if !fail {
|
2016-02-03 13:20:32 +01:00
|
|
|
flushln!("ok");
|
2016-01-25 18:56:36 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-19 18:13:14 +01:00
|
|
|
|
2016-01-25 18:56:36 +01:00
|
|
|
println!("!!! {:?} tests from failed.", failed.len());
|
|
|
|
failed
|
|
|
|
}
|
|
|
|
|
2016-01-27 17:32:12 +01:00
|
|
|
fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
|
|
|
json_chain_test(json_data, ChainEra::Frontier)
|
|
|
|
}
|
|
|
|
|
2016-01-26 15:39:49 +01:00
|
|
|
declare_test!{BlockchainTests_bcBlockGasLimitTest, "BlockchainTests/bcBlockGasLimitTest"}
|
2016-01-25 23:24:51 +01:00
|
|
|
declare_test!{BlockchainTests_bcForkBlockTest, "BlockchainTests/bcForkBlockTest"}
|
2016-01-27 16:05:23 +01:00
|
|
|
declare_test!{BlockchainTests_bcForkStressTest, "BlockchainTests/bcForkStressTest"}
|
2016-01-27 16:02:03 +01:00
|
|
|
declare_test!{BlockchainTests_bcForkUncle, "BlockchainTests/bcForkUncle"}
|
2016-01-26 00:26:36 +01:00
|
|
|
declare_test!{BlockchainTests_bcGasPricerTest, "BlockchainTests/bcGasPricerTest"}
|
2016-01-27 14:10:52 +01:00
|
|
|
declare_test!{BlockchainTests_bcInvalidHeaderTest, "BlockchainTests/bcInvalidHeaderTest"}
|
2016-01-27 13:28:15 +01:00
|
|
|
declare_test!{BlockchainTests_bcInvalidRLPTest, "BlockchainTests/bcInvalidRLPTest"}
|
|
|
|
declare_test!{BlockchainTests_bcMultiChainTest, "BlockchainTests/bcMultiChainTest"}
|
2016-01-26 00:26:36 +01:00
|
|
|
declare_test!{BlockchainTests_bcRPC_API_Test, "BlockchainTests/bcRPC_API_Test"}
|
2016-01-26 15:39:49 +01:00
|
|
|
declare_test!{BlockchainTests_bcStateTest, "BlockchainTests/bcStateTest"}
|
2016-01-27 15:01:59 +01:00
|
|
|
declare_test!{BlockchainTests_bcTotalDifficultyTest, "BlockchainTests/bcTotalDifficultyTest"}
|
2016-01-27 14:09:32 +01:00
|
|
|
declare_test!{BlockchainTests_bcUncleHeaderValiditiy, "BlockchainTests/bcUncleHeaderValiditiy"}
|
|
|
|
declare_test!{BlockchainTests_bcUncleTest, "BlockchainTests/bcUncleTest"}
|
2016-01-27 14:55:50 +01:00
|
|
|
declare_test!{BlockchainTests_bcValidBlockTest, "BlockchainTests/bcValidBlockTest"}
|
2016-01-27 14:09:32 +01:00
|
|
|
declare_test!{BlockchainTests_bcWalletTest, "BlockchainTests/bcWalletTest"}
|
2016-01-27 17:24:11 +01:00
|
|
|
|
|
|
|
declare_test!{BlockchainTests_RandomTests_bl10251623GO, "BlockchainTests/RandomTests/bl10251623GO"}
|
|
|
|
declare_test!{BlockchainTests_RandomTests_bl201507071825GO, "BlockchainTests/RandomTests/bl201507071825GO"}
|