2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 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/>.
|
|
|
|
|
2016-01-13 01:19:05 +01:00
|
|
|
use super::test_common::*;
|
2017-04-12 13:33:49 +02:00
|
|
|
use pod_state::PodState;
|
2017-08-28 14:25:16 +02:00
|
|
|
use trace;
|
|
|
|
use client::{EvmTestClient, EvmTestError, TransactResult};
|
2016-03-25 13:08:57 +01:00
|
|
|
use ethjson;
|
2017-07-12 13:09:17 +02:00
|
|
|
use transaction::SignedTransaction;
|
2017-08-01 12:37:57 +02:00
|
|
|
use vm::EnvInfo;
|
2016-01-13 01:19:05 +01:00
|
|
|
|
2017-04-12 13:33:49 +02:00
|
|
|
pub fn json_chain_test(json_data: &[u8]) -> Vec<String> {
|
2017-03-22 06:23:40 +01:00
|
|
|
::ethcore_logger::init_log();
|
2017-04-12 13:33:49 +02:00
|
|
|
let tests = ethjson::state::test::Test::load(json_data).unwrap();
|
2016-01-13 01:19:05 +01:00
|
|
|
let mut failed = Vec::new();
|
2016-01-29 17:49:58 +01:00
|
|
|
|
2016-03-25 13:08:57 +01:00
|
|
|
for (name, test) in tests.into_iter() {
|
2016-01-15 04:02:06 +01:00
|
|
|
{
|
2017-04-12 13:33:49 +02:00
|
|
|
let multitransaction = test.transaction;
|
2017-04-19 14:30:00 +02:00
|
|
|
let env: EnvInfo = test.env.into();
|
2016-03-25 13:08:57 +01:00
|
|
|
let pre: PodState = test.pre_state.into();
|
2016-01-13 15:54:17 +01:00
|
|
|
|
2017-08-28 14:25:16 +02:00
|
|
|
for (spec_name, states) in test.post_states {
|
2017-04-12 13:33:49 +02:00
|
|
|
let total = states.len();
|
2017-08-28 14:25:16 +02:00
|
|
|
let spec = match EvmTestClient::spec_from_json(&spec_name) {
|
|
|
|
Some(spec) => spec,
|
|
|
|
None => {
|
|
|
|
println!(" - {} | {:?} Ignoring tests because of missing spec", name, spec_name);
|
|
|
|
continue;
|
|
|
|
}
|
2017-04-12 13:33:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
for (i, state) in states.into_iter().enumerate() {
|
2017-08-28 14:25:16 +02:00
|
|
|
let info = format!(" - {} | {:?} ({}/{}) ...", name, spec_name, i + 1, total);
|
2017-04-12 13:33:49 +02:00
|
|
|
|
|
|
|
let post_root: H256 = state.hash.into();
|
2017-04-19 14:30:00 +02:00
|
|
|
let transaction: SignedTransaction = multitransaction.select(&state.indexes).into();
|
2017-08-28 14:25:16 +02:00
|
|
|
|
|
|
|
let result = || -> Result<_, EvmTestError> {
|
|
|
|
Ok(EvmTestClient::from_pod_state(spec, pre.clone())?
|
|
|
|
.transact(&env, transaction, trace::NoopVMTracer))
|
|
|
|
};
|
|
|
|
match result() {
|
|
|
|
Err(err) => {
|
|
|
|
println!("{} !!! Unexpected internal error: {:?}", info, err);
|
|
|
|
flushln!("{} fail", info);
|
|
|
|
failed.push(name.clone());
|
|
|
|
},
|
|
|
|
Ok(TransactResult::Ok { state_root, .. }) if state_root != post_root => {
|
|
|
|
println!("{} !!! State mismatch (got: {}, expect: {}", info, state_root, post_root);
|
|
|
|
flushln!("{} fail", info);
|
|
|
|
failed.push(name.clone());
|
|
|
|
},
|
|
|
|
Ok(TransactResult::Err { state_root, ref error }) if state_root != post_root => {
|
|
|
|
println!("{} !!! State mismatch (got: {}, expect: {}", info, state_root, post_root);
|
|
|
|
println!("{} !!! Execution error: {:?}", info, error);
|
|
|
|
flushln!("{} fail", info);
|
|
|
|
failed.push(name.clone());
|
|
|
|
},
|
|
|
|
Ok(TransactResult::Err { error, .. }) => {
|
|
|
|
flushln!("{} ok ({:?})", info, error);
|
|
|
|
},
|
|
|
|
Ok(_) => {
|
|
|
|
flushln!("{} ok", info);
|
|
|
|
},
|
2016-01-15 13:08:37 +01:00
|
|
|
}
|
2016-01-15 04:02:06 +01:00
|
|
|
}
|
2016-01-15 01:44:23 +01:00
|
|
|
}
|
2016-01-13 01:19:05 +01:00
|
|
|
}
|
2016-03-25 13:08:57 +01:00
|
|
|
|
2016-01-13 01:19:05 +01:00
|
|
|
}
|
2016-03-25 13:08:57 +01:00
|
|
|
|
2017-04-19 14:30:00 +02:00
|
|
|
if !failed.is_empty() {
|
|
|
|
println!("!!! {:?} tests failed.", failed.len());
|
|
|
|
}
|
2016-01-13 01:19:05 +01:00
|
|
|
failed
|
|
|
|
}
|
|
|
|
|
2017-04-12 13:33:49 +02:00
|
|
|
mod state_tests {
|
2016-10-15 14:39:15 +02:00
|
|
|
use super::json_chain_test;
|
2016-01-29 17:49:58 +01:00
|
|
|
|
2016-10-15 14:39:15 +02:00
|
|
|
fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
2017-04-12 13:33:49 +02:00
|
|
|
json_chain_test(json_data)
|
2016-10-15 14:39:15 +02:00
|
|
|
}
|
2016-01-29 17:49:58 +01:00
|
|
|
|
2017-04-12 13:33:49 +02:00
|
|
|
declare_test!{GeneralStateTest_stAttackTest, "GeneralStateTests/stAttackTest/"}
|
2017-09-15 21:07:54 +02:00
|
|
|
declare_test!{GeneralStateTest_stBadOpcodeTest, "GeneralStateTests/stBadOpcode/"}
|
2017-04-12 13:33:49 +02:00
|
|
|
declare_test!{GeneralStateTest_stCallCodes, "GeneralStateTests/stCallCodes/"}
|
|
|
|
declare_test!{GeneralStateTest_stCallDelegateCodesCallCodeHomestead, "GeneralStateTests/stCallDelegateCodesCallCodeHomestead/"}
|
|
|
|
declare_test!{GeneralStateTest_stCallDelegateCodesHomestead, "GeneralStateTests/stCallDelegateCodesHomestead/"}
|
|
|
|
declare_test!{GeneralStateTest_stChangedEIP150, "GeneralStateTests/stChangedEIP150/"}
|
|
|
|
declare_test!{GeneralStateTest_stCodeSizeLimit, "GeneralStateTests/stCodeSizeLimit/"}
|
|
|
|
declare_test!{GeneralStateTest_stCreateTest, "GeneralStateTests/stCreateTest/"}
|
|
|
|
declare_test!{GeneralStateTest_stDelegatecallTestHomestead, "GeneralStateTests/stDelegatecallTestHomestead/"}
|
|
|
|
declare_test!{GeneralStateTest_stEIP150singleCodeGasPrices, "GeneralStateTests/stEIP150singleCodeGasPrices/"}
|
|
|
|
declare_test!{GeneralStateTest_stEIP150Specific, "GeneralStateTests/stEIP150Specific/"}
|
2017-09-15 21:07:54 +02:00
|
|
|
declare_test!{GeneralStateTest_stEIP158Specific, "GeneralStateTests/stEIP158Specific/"}
|
2017-04-12 13:33:49 +02:00
|
|
|
declare_test!{GeneralStateTest_stExample, "GeneralStateTests/stExample/"}
|
|
|
|
declare_test!{GeneralStateTest_stHomesteadSpecific, "GeneralStateTests/stHomesteadSpecific/"}
|
|
|
|
declare_test!{GeneralStateTest_stInitCodeTest, "GeneralStateTests/stInitCodeTest/"}
|
|
|
|
declare_test!{GeneralStateTest_stLogTests, "GeneralStateTests/stLogTests/"}
|
|
|
|
declare_test!{GeneralStateTest_stMemExpandingEIP150Calls, "GeneralStateTests/stMemExpandingEIP150Calls/"}
|
|
|
|
declare_test!{heavy => GeneralStateTest_stMemoryStressTest, "GeneralStateTests/stMemoryStressTest/"}
|
|
|
|
declare_test!{GeneralStateTest_stMemoryTest, "GeneralStateTests/stMemoryTest/"}
|
|
|
|
declare_test!{GeneralStateTest_stNonZeroCallsTest, "GeneralStateTests/stNonZeroCallsTest/"}
|
|
|
|
declare_test!{GeneralStateTest_stPreCompiledContracts, "GeneralStateTests/stPreCompiledContracts/"}
|
|
|
|
declare_test!{heavy => GeneralStateTest_stQuadraticComplexityTest, "GeneralStateTests/stQuadraticComplexityTest/"}
|
|
|
|
declare_test!{GeneralStateTest_stRandom, "GeneralStateTests/stRandom/"}
|
|
|
|
declare_test!{GeneralStateTest_stRecursiveCreate, "GeneralStateTests/stRecursiveCreate/"}
|
|
|
|
declare_test!{GeneralStateTest_stRefundTest, "GeneralStateTests/stRefundTest/"}
|
2017-09-15 21:07:54 +02:00
|
|
|
declare_test!{GeneralStateTest_stReturnDataTest, "GeneralStateTests/stReturnDataTest/"}
|
|
|
|
declare_test!{GeneralStateTest_stRevertTest, "GeneralStateTests/stRevertTest/"}
|
2017-04-12 13:33:49 +02:00
|
|
|
declare_test!{GeneralStateTest_stSolidityTest, "GeneralStateTests/stSolidityTest/"}
|
|
|
|
declare_test!{GeneralStateTest_stSpecialTest, "GeneralStateTests/stSpecialTest/"}
|
|
|
|
declare_test!{GeneralStateTest_stStackTests, "GeneralStateTests/stStackTests/"}
|
2017-09-15 21:07:54 +02:00
|
|
|
declare_test!{GeneralStateTest_stStaticCall, "GeneralStateTests/stStaticCall/"}
|
2017-04-12 13:33:49 +02:00
|
|
|
declare_test!{GeneralStateTest_stSystemOperationsTest, "GeneralStateTests/stSystemOperationsTest/"}
|
|
|
|
declare_test!{GeneralStateTest_stTransactionTest, "GeneralStateTests/stTransactionTest/"}
|
|
|
|
declare_test!{GeneralStateTest_stTransitionTest, "GeneralStateTests/stTransitionTest/"}
|
|
|
|
declare_test!{GeneralStateTest_stWalletTest, "GeneralStateTests/stWalletTest/"}
|
|
|
|
declare_test!{GeneralStateTest_stZeroCallsRevert, "GeneralStateTests/stZeroCallsRevert/"}
|
|
|
|
declare_test!{GeneralStateTest_stZeroCallsTest, "GeneralStateTests/stZeroCallsTest/"}
|
2017-09-15 21:07:54 +02:00
|
|
|
declare_test!{GeneralStateTest_stZeroKnowledge, "GeneralStateTests/stZeroKnowledge/"}
|
2016-10-15 14:39:15 +02:00
|
|
|
}
|
2017-04-12 13:33:49 +02:00
|
|
|
|