2018-06-04 10:19:50 +02:00
|
|
|
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
|
2016-02-05 13:40:41 +01:00
|
|
|
// 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/>.
|
|
|
|
|
2018-06-25 11:21:45 +02:00
|
|
|
use std::path::Path;
|
2017-07-29 23:19:33 +02:00
|
|
|
use std::sync::Arc;
|
2018-03-03 18:42:13 +01:00
|
|
|
use client::{EvmTestClient, Client, ClientConfig, ChainInfo, ImportBlock};
|
2016-01-26 19:18:22 +01:00
|
|
|
use block::Block;
|
2016-03-19 18:13:14 +01:00
|
|
|
use spec::Genesis;
|
2016-03-19 18:38:02 +01:00
|
|
|
use ethjson;
|
2016-05-31 22:24:32 +02:00
|
|
|
use miner::Miner;
|
2016-08-05 10:32:04 +02:00
|
|
|
use io::IoChannel;
|
2018-06-20 15:13:07 +02:00
|
|
|
use test_helpers;
|
2016-01-25 18:56:36 +01:00
|
|
|
|
2018-06-25 11:21:45 +02:00
|
|
|
use super::HookType;
|
|
|
|
|
|
|
|
/// Run chain jsontests on a given folder.
|
|
|
|
pub fn run_test_path<H: FnMut(&str, HookType)>(p: &Path, skip: &[&'static str], h: &mut H) {
|
|
|
|
::json_tests::test_common::run_test_path(p, skip, json_chain_test, h)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Run chain jsontests on a given file.
|
|
|
|
pub fn run_test_file<H: FnMut(&str, HookType)>(p: &Path, h: &mut H) {
|
|
|
|
::json_tests::test_common::run_test_file(p, json_chain_test, h)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn json_chain_test<H: FnMut(&str, HookType)>(json_data: &[u8], start_stop_hook: &mut H) -> Vec<String> {
|
2017-03-22 06:23:40 +01:00
|
|
|
::ethcore_logger::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() {
|
2018-06-25 11:21:45 +02:00
|
|
|
start_stop_hook(&name, HookType::OnStart);
|
|
|
|
|
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-08-05 23:33:55 +02:00
|
|
|
let spec = {
|
2017-09-15 21:07:54 +02:00
|
|
|
let mut spec = match EvmTestClient::spec_from_json(&blockchain.network) {
|
2018-06-25 11:21:45 +02:00
|
|
|
Some(spec) => spec,
|
2017-09-15 21:07:54 +02:00
|
|
|
None => {
|
|
|
|
println!(" - {} | {:?} Ignoring tests because of missing spec", name, blockchain.network);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-24 10:49:13 +02:00
|
|
|
let genesis = Genesis::from(blockchain.genesis());
|
|
|
|
let state = From::from(blockchain.pre_state.clone());
|
2017-05-03 09:00:02 +02:00
|
|
|
spec.set_genesis_state(state).expect("Failed to overwrite genesis state");
|
2016-06-24 10:49:13 +02:00
|
|
|
spec.overwrite_genesis_params(genesis);
|
|
|
|
assert!(spec.is_state_root_valid());
|
|
|
|
spec
|
2016-01-27 17:32:12 +01:00
|
|
|
};
|
2016-03-19 18:13:14 +01:00
|
|
|
|
2016-01-25 18:56:36 +01:00
|
|
|
{
|
2018-06-20 15:13:07 +02:00
|
|
|
let db = test_helpers::new_db();
|
2017-10-10 16:56:03 +02:00
|
|
|
let mut config = ClientConfig::default();
|
|
|
|
config.history = 8;
|
2016-06-24 10:49:13 +02:00
|
|
|
let client = Client::new(
|
2017-10-10 16:56:03 +02:00
|
|
|
config,
|
2016-08-05 23:33:55 +02:00
|
|
|
&spec,
|
2017-02-20 17:21:55 +01:00
|
|
|
db,
|
2018-04-13 17:34:27 +02:00
|
|
|
Arc::new(Miner::new_for_tests(&spec, None)),
|
2016-09-07 15:27:28 +02:00
|
|
|
IoChannel::disconnected(),
|
2016-06-24 10:49:13 +02:00
|
|
|
).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();
|
2016-07-19 09:21:41 +02:00
|
|
|
client.import_verified_blocks();
|
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
|
|
|
}
|
2018-06-25 11:21:45 +02:00
|
|
|
|
|
|
|
start_stop_hook(&name, HookType::OnStop);
|
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
|
|
|
|
}
|
|
|
|
|
2018-06-25 11:21:45 +02:00
|
|
|
#[cfg(test)]
|
2017-09-15 21:07:54 +02:00
|
|
|
mod block_tests {
|
2016-07-16 13:02:56 +02:00
|
|
|
use super::json_chain_test;
|
2018-06-25 11:21:45 +02:00
|
|
|
use json_tests::HookType;
|
2016-07-16 13:02:56 +02:00
|
|
|
|
2018-06-25 11:21:45 +02:00
|
|
|
fn do_json_test<H: FnMut(&str, HookType)>(json_data: &[u8], h: &mut H) -> Vec<String> {
|
|
|
|
json_chain_test(json_data, h)
|
2016-07-16 13:02:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
declare_test!{BlockchainTests_bcBlockGasLimitTest, "BlockchainTests/bcBlockGasLimitTest"}
|
2017-09-15 21:07:54 +02:00
|
|
|
declare_test!{BlockchainTests_bcExploitTest, "BlockchainTests/bcExploitTest"}
|
|
|
|
declare_test!{BlockchainTests_bcForgedTest, "BlockchainTests/bcForgedTest"}
|
2016-07-16 13:02:56 +02:00
|
|
|
declare_test!{BlockchainTests_bcForkStressTest, "BlockchainTests/bcForkStressTest"}
|
|
|
|
declare_test!{BlockchainTests_bcGasPricerTest, "BlockchainTests/bcGasPricerTest"}
|
|
|
|
declare_test!{BlockchainTests_bcInvalidHeaderTest, "BlockchainTests/bcInvalidHeaderTest"}
|
|
|
|
declare_test!{BlockchainTests_bcMultiChainTest, "BlockchainTests/bcMultiChainTest"}
|
2017-09-15 21:07:54 +02:00
|
|
|
declare_test!{BlockchainTests_bcRandomBlockhashTest, "BlockchainTests/bcRandomBlockhashTest"}
|
2016-07-16 13:02:56 +02:00
|
|
|
declare_test!{BlockchainTests_bcTotalDifficultyTest, "BlockchainTests/bcTotalDifficultyTest"}
|
2017-10-10 17:48:37 +02:00
|
|
|
declare_test!{BlockchainTests_bcUncleHeaderValidity, "BlockchainTests/bcUncleHeaderValidity"}
|
2016-07-16 13:02:56 +02:00
|
|
|
declare_test!{BlockchainTests_bcUncleTest, "BlockchainTests/bcUncleTest"}
|
|
|
|
declare_test!{BlockchainTests_bcValidBlockTest, "BlockchainTests/bcValidBlockTest"}
|
|
|
|
declare_test!{BlockchainTests_bcWalletTest, "BlockchainTests/bcWalletTest"}
|
|
|
|
|
2017-09-15 21:07:54 +02:00
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stAttackTest, "BlockchainTests/GeneralStateTests/stAttackTest/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stBadOpcodeTest, "BlockchainTests/GeneralStateTests/stBadOpcode/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stCallCodes, "BlockchainTests/GeneralStateTests/stCallCodes/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stCallDelegateCodesCallCodeHomestead, "BlockchainTests/GeneralStateTests/stCallDelegateCodesCallCodeHomestead/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stCallDelegateCodesHomestead, "BlockchainTests/GeneralStateTests/stCallDelegateCodesHomestead/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stChangedEIP150, "BlockchainTests/GeneralStateTests/stChangedEIP150/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stCodeSizeLimit, "BlockchainTests/GeneralStateTests/stCodeSizeLimit/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stCreateTest, "BlockchainTests/GeneralStateTests/stCreateTest/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stDelegatecallTestHomestead, "BlockchainTests/GeneralStateTests/stDelegatecallTestHomestead/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stEIP150singleCodeGasPrices, "BlockchainTests/GeneralStateTests/stEIP150singleCodeGasPrices/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stEIP150Specific, "BlockchainTests/GeneralStateTests/stEIP150Specific/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stEIP158Specific, "BlockchainTests/GeneralStateTests/stEIP158Specific/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stExample, "BlockchainTests/GeneralStateTests/stExample/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stHomesteadSpecific, "BlockchainTests/GeneralStateTests/stHomesteadSpecific/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stInitCodeTest, "BlockchainTests/GeneralStateTests/stInitCodeTest/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stLogTests, "BlockchainTests/GeneralStateTests/stLogTests/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stMemExpandingEIP150Calls, "BlockchainTests/GeneralStateTests/stMemExpandingEIP150Calls/"}
|
|
|
|
declare_test!{heavy => BlockchainTests_GeneralStateTest_stMemoryStressTest, "BlockchainTests/GeneralStateTests/stMemoryStressTest/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stMemoryTest, "BlockchainTests/GeneralStateTests/stMemoryTest/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stNonZeroCallsTest, "BlockchainTests/GeneralStateTests/stNonZeroCallsTest/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stPreCompiledContracts, "BlockchainTests/GeneralStateTests/stPreCompiledContracts/"}
|
|
|
|
declare_test!{heavy => BlockchainTests_GeneralStateTest_stQuadraticComplexityTest, "BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stRandom, "BlockchainTests/GeneralStateTests/stRandom/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stRecursiveCreate, "BlockchainTests/GeneralStateTests/stRecursiveCreate/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stRefundTest, "BlockchainTests/GeneralStateTests/stRefundTest/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stReturnDataTest, "BlockchainTests/GeneralStateTests/stReturnDataTest/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stRevertTest, "BlockchainTests/GeneralStateTests/stRevertTest/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stSolidityTest, "BlockchainTests/GeneralStateTests/stSolidityTest/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stSpecialTest, "BlockchainTests/GeneralStateTests/stSpecialTest/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stStackTests, "BlockchainTests/GeneralStateTests/stStackTests/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stStaticCall, "BlockchainTests/GeneralStateTests/stStaticCall/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stSystemOperationsTest, "BlockchainTests/GeneralStateTests/stSystemOperationsTest/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stTransactionTest, "BlockchainTests/GeneralStateTests/stTransactionTest/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stTransitionTest, "BlockchainTests/GeneralStateTests/stTransitionTest/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stWalletTest, "BlockchainTests/GeneralStateTests/stWalletTest/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stZeroCallsRevert, "BlockchainTests/GeneralStateTests/stZeroCallsRevert/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stZeroCallsTest, "BlockchainTests/GeneralStateTests/stZeroCallsTest/"}
|
|
|
|
declare_test!{BlockchainTests_GeneralStateTest_stZeroKnowledge, "BlockchainTests/GeneralStateTests/stZeroKnowledge/"}
|
|
|
|
|
|
|
|
declare_test!{BlockchainTests_TransitionTests_bcEIP158ToByzantium, "BlockchainTests/TransitionTests/bcEIP158ToByzantium/"}
|
|
|
|
declare_test!{BlockchainTests_TransitionTests_bcFrontierToHomestead, "BlockchainTests/TransitionTests/bcFrontierToHomestead/"}
|
|
|
|
declare_test!{BlockchainTests_TransitionTests_bcHomesteadToDao, "BlockchainTests/TransitionTests/bcHomesteadToDao/"}
|
|
|
|
declare_test!{BlockchainTests_TransitionTests_bcHomesteadToEIP150, "BlockchainTests/TransitionTests/bcHomesteadToEIP150/"}
|
2016-01-27 17:32:12 +01:00
|
|
|
}
|