Reformat the source code
This commit is contained in:
@@ -14,184 +14,199 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use client::{EvmTestClient, Client, ClientConfig, ChainInfo, ImportBlock};
|
||||
use spec::Genesis;
|
||||
use super::{HookType, SKIP_TEST_STATE};
|
||||
use client::{ChainInfo, Client, ClientConfig, EvmTestClient, ImportBlock};
|
||||
use ethjson;
|
||||
use miner::Miner;
|
||||
use io::IoChannel;
|
||||
use miner::Miner;
|
||||
use spec::Genesis;
|
||||
use std::{path::Path, sync::Arc};
|
||||
use test_helpers;
|
||||
use verification::queue::kind::blocks::Unverified;
|
||||
use verification::VerifierType;
|
||||
use super::SKIP_TEST_STATE;
|
||||
use super::HookType;
|
||||
use verification::{queue::kind::blocks::Unverified, VerifierType};
|
||||
|
||||
/// 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)
|
||||
::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)
|
||||
::json_tests::test_common::run_test_file(p, json_chain_test, h)
|
||||
}
|
||||
|
||||
fn skip_test(name: &String) -> bool {
|
||||
SKIP_TEST_STATE.block.iter().any(|block_test|block_test.subtests.contains(name))
|
||||
SKIP_TEST_STATE
|
||||
.block
|
||||
.iter()
|
||||
.any(|block_test| block_test.subtests.contains(name))
|
||||
}
|
||||
|
||||
pub fn json_chain_test<H: FnMut(&str, HookType)>(json_data: &[u8], start_stop_hook: &mut H) -> Vec<String> {
|
||||
let _ = ::env_logger::try_init();
|
||||
let tests = ethjson::blockchain::Test::load(json_data).unwrap();
|
||||
let mut failed = Vec::new();
|
||||
pub fn json_chain_test<H: FnMut(&str, HookType)>(
|
||||
json_data: &[u8],
|
||||
start_stop_hook: &mut H,
|
||||
) -> Vec<String> {
|
||||
let _ = ::env_logger::try_init();
|
||||
let tests = ethjson::blockchain::Test::load(json_data).unwrap();
|
||||
let mut failed = Vec::new();
|
||||
|
||||
for (name, blockchain) in tests.into_iter() {
|
||||
if skip_test(&name) {
|
||||
println!(" - {} | {:?} Ignoring tests because in skip list", name, blockchain.network);
|
||||
continue;
|
||||
}
|
||||
start_stop_hook(&name, HookType::OnStart);
|
||||
for (name, blockchain) in tests.into_iter() {
|
||||
if skip_test(&name) {
|
||||
println!(
|
||||
" - {} | {:?} Ignoring tests because in skip list",
|
||||
name, blockchain.network
|
||||
);
|
||||
continue;
|
||||
}
|
||||
start_stop_hook(&name, HookType::OnStart);
|
||||
|
||||
let mut fail = false;
|
||||
{
|
||||
let mut fail_unless = |cond: bool| if !cond && !fail {
|
||||
failed.push(name.clone());
|
||||
flushln!("FAIL");
|
||||
fail = true;
|
||||
true
|
||||
} else {false};
|
||||
let mut fail = false;
|
||||
{
|
||||
let mut fail_unless = |cond: bool| {
|
||||
if !cond && !fail {
|
||||
failed.push(name.clone());
|
||||
flushln!("FAIL");
|
||||
fail = true;
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
};
|
||||
|
||||
flush!(" - {}...", name);
|
||||
flush!(" - {}...", name);
|
||||
|
||||
let spec = {
|
||||
let mut spec = match EvmTestClient::spec_from_json(&blockchain.network) {
|
||||
Some(spec) => spec,
|
||||
None => {
|
||||
println!(" - {} | {:?} Ignoring tests because of missing spec", name, blockchain.network);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let spec = {
|
||||
let mut spec = match EvmTestClient::spec_from_json(&blockchain.network) {
|
||||
Some(spec) => spec,
|
||||
None => {
|
||||
println!(
|
||||
" - {} | {:?} Ignoring tests because of missing spec",
|
||||
name, blockchain.network
|
||||
);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
let genesis = Genesis::from(blockchain.genesis());
|
||||
let state = From::from(blockchain.pre_state.clone());
|
||||
spec.set_genesis_state(state).expect("Failed to overwrite genesis state");
|
||||
spec.overwrite_genesis_params(genesis);
|
||||
assert!(spec.is_state_root_valid());
|
||||
spec
|
||||
};
|
||||
let genesis = Genesis::from(blockchain.genesis());
|
||||
let state = From::from(blockchain.pre_state.clone());
|
||||
spec.set_genesis_state(state)
|
||||
.expect("Failed to overwrite genesis state");
|
||||
spec.overwrite_genesis_params(genesis);
|
||||
assert!(spec.is_state_root_valid());
|
||||
spec
|
||||
};
|
||||
|
||||
{
|
||||
let db = test_helpers::new_db();
|
||||
let mut config = ClientConfig::default();
|
||||
if ethjson::blockchain::Engine::NoProof == blockchain.engine {
|
||||
config.verifier_type = VerifierType::CanonNoSeal;
|
||||
config.check_seal = false;
|
||||
}
|
||||
config.history = 8;
|
||||
let client = Client::new(
|
||||
config,
|
||||
&spec,
|
||||
db,
|
||||
Arc::new(Miner::new_for_tests(&spec, None)),
|
||||
IoChannel::disconnected(),
|
||||
).unwrap();
|
||||
for b in blockchain.blocks_rlp() {
|
||||
if let Ok(block) = Unverified::from_rlp(b) {
|
||||
let _ = client.import_block(block);
|
||||
client.flush_queue();
|
||||
client.import_verified_blocks();
|
||||
}
|
||||
}
|
||||
fail_unless(client.chain_info().best_block_hash == blockchain.best_block.into());
|
||||
}
|
||||
}
|
||||
{
|
||||
let db = test_helpers::new_db();
|
||||
let mut config = ClientConfig::default();
|
||||
if ethjson::blockchain::Engine::NoProof == blockchain.engine {
|
||||
config.verifier_type = VerifierType::CanonNoSeal;
|
||||
config.check_seal = false;
|
||||
}
|
||||
config.history = 8;
|
||||
let client = Client::new(
|
||||
config,
|
||||
&spec,
|
||||
db,
|
||||
Arc::new(Miner::new_for_tests(&spec, None)),
|
||||
IoChannel::disconnected(),
|
||||
)
|
||||
.unwrap();
|
||||
for b in blockchain.blocks_rlp() {
|
||||
if let Ok(block) = Unverified::from_rlp(b) {
|
||||
let _ = client.import_block(block);
|
||||
client.flush_queue();
|
||||
client.import_verified_blocks();
|
||||
}
|
||||
}
|
||||
fail_unless(client.chain_info().best_block_hash == blockchain.best_block.into());
|
||||
}
|
||||
}
|
||||
|
||||
if !fail {
|
||||
flushln!("ok");
|
||||
}
|
||||
if !fail {
|
||||
flushln!("ok");
|
||||
}
|
||||
|
||||
start_stop_hook(&name, HookType::OnStop);
|
||||
}
|
||||
start_stop_hook(&name, HookType::OnStop);
|
||||
}
|
||||
|
||||
println!("!!! {:?} tests from failed.", failed.len());
|
||||
failed
|
||||
println!("!!! {:?} tests from failed.", failed.len());
|
||||
failed
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod block_tests {
|
||||
use super::json_chain_test;
|
||||
use json_tests::HookType;
|
||||
use super::json_chain_test;
|
||||
use json_tests::HookType;
|
||||
|
||||
fn do_json_test<H: FnMut(&str, HookType)>(json_data: &[u8], h: &mut H) -> Vec<String> {
|
||||
json_chain_test(json_data, h)
|
||||
}
|
||||
fn do_json_test<H: FnMut(&str, HookType)>(json_data: &[u8], h: &mut H) -> Vec<String> {
|
||||
json_chain_test(json_data, h)
|
||||
}
|
||||
|
||||
declare_test!{BlockchainTests_bcBlockGasLimitTest, "BlockchainTests/bcBlockGasLimitTest"}
|
||||
declare_test!{BlockchainTests_bcExploitTest, "BlockchainTests/bcExploitTest"}
|
||||
declare_test!{BlockchainTests_bcForgedTest, "BlockchainTests/bcForgedTest"}
|
||||
declare_test!{BlockchainTests_bcForkStressTest, "BlockchainTests/bcForkStressTest"}
|
||||
declare_test!{BlockchainTests_bcGasPricerTest, "BlockchainTests/bcGasPricerTest"}
|
||||
declare_test!{BlockchainTests_bcInvalidHeaderTest, "BlockchainTests/bcInvalidHeaderTest"}
|
||||
declare_test!{BlockchainTests_bcMultiChainTest, "BlockchainTests/bcMultiChainTest"}
|
||||
declare_test!{BlockchainTests_bcRandomBlockhashTest, "BlockchainTests/bcRandomBlockhashTest"}
|
||||
declare_test!{BlockchainTests_bcStateTest, "BlockchainTests/bcStateTests"}
|
||||
declare_test!{BlockchainTests_bcTotalDifficultyTest, "BlockchainTests/bcTotalDifficultyTest"}
|
||||
declare_test!{BlockchainTests_bcUncleHeaderValidity, "BlockchainTests/bcUncleHeaderValidity"}
|
||||
declare_test!{BlockchainTests_bcUncleTest, "BlockchainTests/bcUncleTest"}
|
||||
declare_test!{BlockchainTests_bcValidBlockTest, "BlockchainTests/bcValidBlockTest"}
|
||||
declare_test!{BlockchainTests_bcWalletTest, "BlockchainTests/bcWalletTest"}
|
||||
declare_test! {BlockchainTests_bcBlockGasLimitTest, "BlockchainTests/bcBlockGasLimitTest"}
|
||||
declare_test! {BlockchainTests_bcExploitTest, "BlockchainTests/bcExploitTest"}
|
||||
declare_test! {BlockchainTests_bcForgedTest, "BlockchainTests/bcForgedTest"}
|
||||
declare_test! {BlockchainTests_bcForkStressTest, "BlockchainTests/bcForkStressTest"}
|
||||
declare_test! {BlockchainTests_bcGasPricerTest, "BlockchainTests/bcGasPricerTest"}
|
||||
declare_test! {BlockchainTests_bcInvalidHeaderTest, "BlockchainTests/bcInvalidHeaderTest"}
|
||||
declare_test! {BlockchainTests_bcMultiChainTest, "BlockchainTests/bcMultiChainTest"}
|
||||
declare_test! {BlockchainTests_bcRandomBlockhashTest, "BlockchainTests/bcRandomBlockhashTest"}
|
||||
declare_test! {BlockchainTests_bcStateTest, "BlockchainTests/bcStateTests"}
|
||||
declare_test! {BlockchainTests_bcTotalDifficultyTest, "BlockchainTests/bcTotalDifficultyTest"}
|
||||
declare_test! {BlockchainTests_bcUncleHeaderValidity, "BlockchainTests/bcUncleHeaderValidity"}
|
||||
declare_test! {BlockchainTests_bcUncleTest, "BlockchainTests/bcUncleTest"}
|
||||
declare_test! {BlockchainTests_bcValidBlockTest, "BlockchainTests/bcValidBlockTest"}
|
||||
declare_test! {BlockchainTests_bcWalletTest, "BlockchainTests/bcWalletTest"}
|
||||
|
||||
declare_test!{BlockchainTests_GeneralStateTest_stArgsZeroOneBalance, "BlockchainTests/GeneralStateTests/stArgsZeroOneBalance/"}
|
||||
declare_test!{BlockchainTests_GeneralStateTest_stAttackTest, "BlockchainTests/GeneralStateTests/stAttackTest/"}
|
||||
declare_test!{BlockchainTests_GeneralStateTest_stBadOpcodeTest, "BlockchainTests/GeneralStateTests/stBadOpcode/"}
|
||||
declare_test!{BlockchainTests_GeneralStateTest_stBugsTest, "BlockchainTests/GeneralStateTests/stBugs/"}
|
||||
declare_test!{BlockchainTests_GeneralStateTest_stCallCodes, "BlockchainTests/GeneralStateTests/stCallCodes/"}
|
||||
declare_test!{BlockchainTests_GeneralStateTest_stCallCreateCallCodeTest, "BlockchainTests/GeneralStateTests/stCallCreateCallCodeTest/"}
|
||||
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_stCreate2, "BlockchainTests/GeneralStateTests/stCreate2/"}
|
||||
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!{BlockchainTests_GeneralStateTest_stPreCompiledContracts2, "BlockchainTests/GeneralStateTests/stPreCompiledContracts2/"}
|
||||
declare_test!{heavy => BlockchainTests_GeneralStateTest_stQuadraticComplexityTest, "BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/"}
|
||||
declare_test!{BlockchainTests_GeneralStateTest_stRandom, "BlockchainTests/GeneralStateTests/stRandom/"}
|
||||
declare_test!{BlockchainTests_GeneralStateTest_stRandom2, "BlockchainTests/GeneralStateTests/stRandom2/"}
|
||||
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_stShift, "BlockchainTests/GeneralStateTests/stShift/"}
|
||||
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_GeneralStateTest_stZeroKnowledge2, "BlockchainTests/GeneralStateTests/stZeroKnowledge2/"}
|
||||
declare_test!{BlockchainTests_GeneralStateTest_stSStoreTest, "BlockchainTests/GeneralStateTests/stSStoreTest/"}
|
||||
declare_test! {BlockchainTests_GeneralStateTest_stArgsZeroOneBalance, "BlockchainTests/GeneralStateTests/stArgsZeroOneBalance/"}
|
||||
declare_test! {BlockchainTests_GeneralStateTest_stAttackTest, "BlockchainTests/GeneralStateTests/stAttackTest/"}
|
||||
declare_test! {BlockchainTests_GeneralStateTest_stBadOpcodeTest, "BlockchainTests/GeneralStateTests/stBadOpcode/"}
|
||||
declare_test! {BlockchainTests_GeneralStateTest_stBugsTest, "BlockchainTests/GeneralStateTests/stBugs/"}
|
||||
declare_test! {BlockchainTests_GeneralStateTest_stCallCodes, "BlockchainTests/GeneralStateTests/stCallCodes/"}
|
||||
declare_test! {BlockchainTests_GeneralStateTest_stCallCreateCallCodeTest, "BlockchainTests/GeneralStateTests/stCallCreateCallCodeTest/"}
|
||||
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_stCreate2, "BlockchainTests/GeneralStateTests/stCreate2/"}
|
||||
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! {BlockchainTests_GeneralStateTest_stPreCompiledContracts2, "BlockchainTests/GeneralStateTests/stPreCompiledContracts2/"}
|
||||
declare_test! {heavy => BlockchainTests_GeneralStateTest_stQuadraticComplexityTest, "BlockchainTests/GeneralStateTests/stQuadraticComplexityTest/"}
|
||||
declare_test! {BlockchainTests_GeneralStateTest_stRandom, "BlockchainTests/GeneralStateTests/stRandom/"}
|
||||
declare_test! {BlockchainTests_GeneralStateTest_stRandom2, "BlockchainTests/GeneralStateTests/stRandom2/"}
|
||||
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_stShift, "BlockchainTests/GeneralStateTests/stShift/"}
|
||||
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_GeneralStateTest_stZeroKnowledge2, "BlockchainTests/GeneralStateTests/stZeroKnowledge2/"}
|
||||
declare_test! {BlockchainTests_GeneralStateTest_stSStoreTest, "BlockchainTests/GeneralStateTests/stSStoreTest/"}
|
||||
|
||||
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/"}
|
||||
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/"}
|
||||
}
|
||||
|
||||
@@ -14,85 +14,85 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use ethjson;
|
||||
use types::header::Header;
|
||||
use ethereum_types::U256;
|
||||
use ethjson;
|
||||
use spec::Spec;
|
||||
use types::header::Header;
|
||||
|
||||
use super::HookType;
|
||||
|
||||
pub fn json_difficulty_test<H: FnMut(&str, HookType)>(json_data: &[u8], spec: Spec, start_stop_hook: &mut H) -> Vec<String> {
|
||||
let _ = ::env_logger::try_init();
|
||||
let tests = ethjson::test::DifficultyTest::load(json_data).unwrap();
|
||||
let engine = &spec.engine;
|
||||
pub fn json_difficulty_test<H: FnMut(&str, HookType)>(
|
||||
json_data: &[u8],
|
||||
spec: Spec,
|
||||
start_stop_hook: &mut H,
|
||||
) -> Vec<String> {
|
||||
let _ = ::env_logger::try_init();
|
||||
let tests = ethjson::test::DifficultyTest::load(json_data).unwrap();
|
||||
let engine = &spec.engine;
|
||||
|
||||
for (name, test) in tests.into_iter() {
|
||||
start_stop_hook(&name, HookType::OnStart);
|
||||
for (name, test) in tests.into_iter() {
|
||||
start_stop_hook(&name, HookType::OnStart);
|
||||
|
||||
flush!(" - {}...", name);
|
||||
println!(" - {}...", name);
|
||||
flush!(" - {}...", name);
|
||||
println!(" - {}...", name);
|
||||
|
||||
let mut parent_header = Header::new();
|
||||
let block_number: u64 = test.current_block_number.into();
|
||||
parent_header.set_number(block_number - 1);
|
||||
parent_header.set_gas_limit(0x20000.into());
|
||||
parent_header.set_timestamp(test.parent_timestamp.into());
|
||||
parent_header.set_difficulty(test.parent_difficulty.into());
|
||||
parent_header.set_uncles_hash(test.parent_uncles.into());
|
||||
let mut header = Header::new();
|
||||
header.set_number(block_number);
|
||||
header.set_timestamp(test.current_timestamp.into());
|
||||
engine.populate_from_parent(&mut header, &parent_header);
|
||||
let expected_difficulty: U256 = test.current_difficulty.into();
|
||||
assert_eq!(header.difficulty(), &expected_difficulty);
|
||||
flushln!("ok");
|
||||
let mut parent_header = Header::new();
|
||||
let block_number: u64 = test.current_block_number.into();
|
||||
parent_header.set_number(block_number - 1);
|
||||
parent_header.set_gas_limit(0x20000.into());
|
||||
parent_header.set_timestamp(test.parent_timestamp.into());
|
||||
parent_header.set_difficulty(test.parent_difficulty.into());
|
||||
parent_header.set_uncles_hash(test.parent_uncles.into());
|
||||
let mut header = Header::new();
|
||||
header.set_number(block_number);
|
||||
header.set_timestamp(test.current_timestamp.into());
|
||||
engine.populate_from_parent(&mut header, &parent_header);
|
||||
let expected_difficulty: U256 = test.current_difficulty.into();
|
||||
assert_eq!(header.difficulty(), &expected_difficulty);
|
||||
flushln!("ok");
|
||||
|
||||
start_stop_hook(&name, HookType::OnStop);
|
||||
}
|
||||
vec![]
|
||||
start_stop_hook(&name, HookType::OnStop);
|
||||
}
|
||||
vec![]
|
||||
}
|
||||
|
||||
macro_rules! difficulty_json_test {
|
||||
( $spec:ident ) => {
|
||||
( $spec:ident ) => {
|
||||
use super::json_difficulty_test;
|
||||
use json_tests::HookType;
|
||||
use tempdir::TempDir;
|
||||
|
||||
use super::json_difficulty_test;
|
||||
use tempdir::TempDir;
|
||||
use json_tests::HookType;
|
||||
|
||||
fn do_json_test<H: FnMut(&str, HookType)>(json_data: &[u8], h: &mut H) -> Vec<String> {
|
||||
let tempdir = TempDir::new("").unwrap();
|
||||
json_difficulty_test(json_data, ::ethereum::$spec(&tempdir.path()), h)
|
||||
}
|
||||
|
||||
}
|
||||
fn do_json_test<H: FnMut(&str, HookType)>(json_data: &[u8], h: &mut H) -> Vec<String> {
|
||||
let tempdir = TempDir::new("").unwrap();
|
||||
json_difficulty_test(json_data, ::ethereum::$spec(&tempdir.path()), h)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! difficulty_json_test_nopath {
|
||||
( $spec:ident ) => {
|
||||
( $spec:ident ) => {
|
||||
use super::json_difficulty_test;
|
||||
use json_tests::HookType;
|
||||
|
||||
use super::json_difficulty_test;
|
||||
use json_tests::HookType;
|
||||
|
||||
fn do_json_test<H: FnMut(&str, HookType)>(json_data: &[u8], h: &mut H) -> Vec<String> {
|
||||
json_difficulty_test(json_data, ::ethereum::$spec(), h)
|
||||
}
|
||||
|
||||
}
|
||||
fn do_json_test<H: FnMut(&str, HookType)>(json_data: &[u8], h: &mut H) -> Vec<String> {
|
||||
json_difficulty_test(json_data, ::ethereum::$spec(), h)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
mod difficulty_test {
|
||||
difficulty_json_test!(new_foundation);
|
||||
declare_test!{DifficultyTests_difficulty, "BasicTests/difficulty.json"}
|
||||
difficulty_json_test!(new_foundation);
|
||||
declare_test! {DifficultyTests_difficulty, "BasicTests/difficulty.json"}
|
||||
}
|
||||
|
||||
mod difficulty_test_byzantium {
|
||||
difficulty_json_test_nopath!(new_byzantium_test);
|
||||
declare_test!{DifficultyTests_difficultyByzantium, "BasicTests/difficultyByzantium.json"}
|
||||
difficulty_json_test_nopath!(new_byzantium_test);
|
||||
declare_test! {DifficultyTests_difficultyByzantium, "BasicTests/difficultyByzantium.json"}
|
||||
}
|
||||
|
||||
mod difficulty_test_foundation {
|
||||
difficulty_json_test!(new_foundation);
|
||||
declare_test!{DifficultyTests_difficultyMainNetwork, "BasicTests/difficultyMainNetwork.json"}
|
||||
difficulty_json_test!(new_foundation);
|
||||
declare_test! {DifficultyTests_difficultyMainNetwork, "BasicTests/difficultyMainNetwork.json"}
|
||||
}
|
||||
|
||||
// Disabling Ropsten diff tests; waiting for upstream ethereum/tests Constantinople update
|
||||
@@ -102,11 +102,11 @@ mod difficulty_test_foundation {
|
||||
//}
|
||||
|
||||
mod difficulty_test_frontier {
|
||||
difficulty_json_test_nopath!(new_frontier_test);
|
||||
declare_test!{DifficultyTests_difficultyFrontier, "BasicTests/difficultyFrontier.json"}
|
||||
difficulty_json_test_nopath!(new_frontier_test);
|
||||
declare_test! {DifficultyTests_difficultyFrontier, "BasicTests/difficultyFrontier.json"}
|
||||
}
|
||||
|
||||
mod difficulty_test_homestead {
|
||||
difficulty_json_test_nopath!(new_homestead_test);
|
||||
declare_test!{DifficultyTests_difficultyHomestead, "BasicTests/difficultyHomestead.json"}
|
||||
difficulty_json_test_nopath!(new_homestead_test);
|
||||
declare_test! {DifficultyTests_difficultyHomestead, "BasicTests/difficultyHomestead.json"}
|
||||
}
|
||||
|
||||
@@ -14,363 +14,404 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use super::test_common::*;
|
||||
use state::{Backend as StateBackend, State, Substate};
|
||||
use executive::*;
|
||||
use evm::{VMType, Finalize};
|
||||
use vm::{
|
||||
self, ActionParams, CallType, Schedule, Ext,
|
||||
ContractCreateResult, EnvInfo, MessageCallResult,
|
||||
CreateContractAddress, ReturnData,
|
||||
};
|
||||
use externalities::*;
|
||||
use test_helpers::get_temp_state;
|
||||
use ethjson;
|
||||
use trace::{Tracer, NoopTracer};
|
||||
use trace::{VMTracer, NoopVMTracer};
|
||||
use bytes::Bytes;
|
||||
use ethjson;
|
||||
use ethtrie;
|
||||
use rlp::RlpStream;
|
||||
use evm::{Finalize, VMType};
|
||||
use executive::*;
|
||||
use externalities::*;
|
||||
use hash::keccak;
|
||||
use machine::EthereumMachine as Machine;
|
||||
use rlp::RlpStream;
|
||||
use state::{Backend as StateBackend, State, Substate};
|
||||
use std::{path::Path, sync::Arc};
|
||||
use test_helpers::get_temp_state;
|
||||
use trace::{NoopTracer, NoopVMTracer, Tracer, VMTracer};
|
||||
use vm::{
|
||||
self, ActionParams, CallType, ContractCreateResult, CreateContractAddress, EnvInfo, Ext,
|
||||
MessageCallResult, ReturnData, Schedule,
|
||||
};
|
||||
|
||||
use super::HookType;
|
||||
|
||||
/// Run executive 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, do_json_test, h)
|
||||
::json_tests::test_common::run_test_path(p, skip, do_json_test, h)
|
||||
}
|
||||
|
||||
/// Run executive 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, do_json_test, h)
|
||||
::json_tests::test_common::run_test_file(p, do_json_test, h)
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
struct CallCreate {
|
||||
data: Bytes,
|
||||
destination: Option<Address>,
|
||||
gas_limit: U256,
|
||||
value: U256
|
||||
data: Bytes,
|
||||
destination: Option<Address>,
|
||||
gas_limit: U256,
|
||||
value: U256,
|
||||
}
|
||||
|
||||
impl From<ethjson::vm::Call> for CallCreate {
|
||||
fn from(c: ethjson::vm::Call) -> Self {
|
||||
let dst: Option<ethjson::hash::Address> = c.destination.into();
|
||||
CallCreate {
|
||||
data: c.data.into(),
|
||||
destination: dst.map(Into::into),
|
||||
gas_limit: c.gas_limit.into(),
|
||||
value: c.value.into()
|
||||
}
|
||||
}
|
||||
fn from(c: ethjson::vm::Call) -> Self {
|
||||
let dst: Option<ethjson::hash::Address> = c.destination.into();
|
||||
CallCreate {
|
||||
data: c.data.into(),
|
||||
destination: dst.map(Into::into),
|
||||
gas_limit: c.gas_limit.into(),
|
||||
value: c.value.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Tiny wrapper around executive externalities.
|
||||
/// Stores callcreates.
|
||||
struct TestExt<'a, T: 'a, V: 'a, B: 'a>
|
||||
where T: Tracer, V: VMTracer, B: StateBackend
|
||||
where
|
||||
T: Tracer,
|
||||
V: VMTracer,
|
||||
B: StateBackend,
|
||||
{
|
||||
ext: Externalities<'a, T, V, B>,
|
||||
callcreates: Vec<CallCreate>,
|
||||
nonce: U256,
|
||||
sender: Address,
|
||||
ext: Externalities<'a, T, V, B>,
|
||||
callcreates: Vec<CallCreate>,
|
||||
nonce: U256,
|
||||
sender: Address,
|
||||
}
|
||||
|
||||
impl<'a, T: 'a, V: 'a, B: 'a> TestExt<'a, T, V, B>
|
||||
where T: Tracer, V: VMTracer, B: StateBackend,
|
||||
where
|
||||
T: Tracer,
|
||||
V: VMTracer,
|
||||
B: StateBackend,
|
||||
{
|
||||
fn new(
|
||||
state: &'a mut State<B>,
|
||||
info: &'a EnvInfo,
|
||||
machine: &'a Machine,
|
||||
schedule: &'a Schedule,
|
||||
depth: usize,
|
||||
origin_info: &'a OriginInfo,
|
||||
substate: &'a mut Substate,
|
||||
output: OutputPolicy,
|
||||
address: Address,
|
||||
tracer: &'a mut T,
|
||||
vm_tracer: &'a mut V,
|
||||
) -> ethtrie::Result<Self> {
|
||||
let static_call = false;
|
||||
Ok(TestExt {
|
||||
nonce: state.nonce(&address)?,
|
||||
ext: Externalities::new(state, info, machine, schedule, depth, 0, origin_info, substate, output, tracer, vm_tracer, static_call),
|
||||
callcreates: vec![],
|
||||
sender: address,
|
||||
})
|
||||
}
|
||||
fn new(
|
||||
state: &'a mut State<B>,
|
||||
info: &'a EnvInfo,
|
||||
machine: &'a Machine,
|
||||
schedule: &'a Schedule,
|
||||
depth: usize,
|
||||
origin_info: &'a OriginInfo,
|
||||
substate: &'a mut Substate,
|
||||
output: OutputPolicy,
|
||||
address: Address,
|
||||
tracer: &'a mut T,
|
||||
vm_tracer: &'a mut V,
|
||||
) -> ethtrie::Result<Self> {
|
||||
let static_call = false;
|
||||
Ok(TestExt {
|
||||
nonce: state.nonce(&address)?,
|
||||
ext: Externalities::new(
|
||||
state,
|
||||
info,
|
||||
machine,
|
||||
schedule,
|
||||
depth,
|
||||
0,
|
||||
origin_info,
|
||||
substate,
|
||||
output,
|
||||
tracer,
|
||||
vm_tracer,
|
||||
static_call,
|
||||
),
|
||||
callcreates: vec![],
|
||||
sender: address,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: 'a, V: 'a, B: 'a> Ext for TestExt<'a, T, V, B>
|
||||
where T: Tracer, V: VMTracer, B: StateBackend
|
||||
where
|
||||
T: Tracer,
|
||||
V: VMTracer,
|
||||
B: StateBackend,
|
||||
{
|
||||
fn storage_at(&self, key: &H256) -> vm::Result<H256> {
|
||||
self.ext.storage_at(key)
|
||||
}
|
||||
fn storage_at(&self, key: &H256) -> vm::Result<H256> {
|
||||
self.ext.storage_at(key)
|
||||
}
|
||||
|
||||
fn initial_storage_at(&self, key: &H256) -> vm::Result<H256> {
|
||||
self.ext.initial_storage_at(key)
|
||||
}
|
||||
fn initial_storage_at(&self, key: &H256) -> vm::Result<H256> {
|
||||
self.ext.initial_storage_at(key)
|
||||
}
|
||||
|
||||
fn set_storage(&mut self, key: H256, value: H256) -> vm::Result<()> {
|
||||
self.ext.set_storage(key, value)
|
||||
}
|
||||
fn set_storage(&mut self, key: H256, value: H256) -> vm::Result<()> {
|
||||
self.ext.set_storage(key, value)
|
||||
}
|
||||
|
||||
fn exists(&self, address: &Address) -> vm::Result<bool> {
|
||||
self.ext.exists(address)
|
||||
}
|
||||
fn exists(&self, address: &Address) -> vm::Result<bool> {
|
||||
self.ext.exists(address)
|
||||
}
|
||||
|
||||
fn exists_and_not_null(&self, address: &Address) -> vm::Result<bool> {
|
||||
self.ext.exists_and_not_null(address)
|
||||
}
|
||||
fn exists_and_not_null(&self, address: &Address) -> vm::Result<bool> {
|
||||
self.ext.exists_and_not_null(address)
|
||||
}
|
||||
|
||||
fn balance(&self, address: &Address) -> vm::Result<U256> {
|
||||
self.ext.balance(address)
|
||||
}
|
||||
fn balance(&self, address: &Address) -> vm::Result<U256> {
|
||||
self.ext.balance(address)
|
||||
}
|
||||
|
||||
fn origin_balance(&self) -> vm::Result<U256> {
|
||||
self.ext.origin_balance()
|
||||
}
|
||||
fn origin_balance(&self) -> vm::Result<U256> {
|
||||
self.ext.origin_balance()
|
||||
}
|
||||
|
||||
fn blockhash(&mut self, number: &U256) -> H256 {
|
||||
self.ext.blockhash(number)
|
||||
}
|
||||
fn blockhash(&mut self, number: &U256) -> H256 {
|
||||
self.ext.blockhash(number)
|
||||
}
|
||||
|
||||
fn create(
|
||||
&mut self,
|
||||
gas: &U256,
|
||||
value: &U256,
|
||||
code: &[u8],
|
||||
address: CreateContractAddress,
|
||||
_trap: bool
|
||||
) -> Result<ContractCreateResult, vm::TrapKind> {
|
||||
self.callcreates.push(CallCreate {
|
||||
data: code.to_vec(),
|
||||
destination: None,
|
||||
gas_limit: *gas,
|
||||
value: *value
|
||||
});
|
||||
let contract_address = contract_address(address, &self.sender, &self.nonce, &code).0;
|
||||
Ok(ContractCreateResult::Created(contract_address, *gas))
|
||||
}
|
||||
fn create(
|
||||
&mut self,
|
||||
gas: &U256,
|
||||
value: &U256,
|
||||
code: &[u8],
|
||||
address: CreateContractAddress,
|
||||
_trap: bool,
|
||||
) -> Result<ContractCreateResult, vm::TrapKind> {
|
||||
self.callcreates.push(CallCreate {
|
||||
data: code.to_vec(),
|
||||
destination: None,
|
||||
gas_limit: *gas,
|
||||
value: *value,
|
||||
});
|
||||
let contract_address = contract_address(address, &self.sender, &self.nonce, &code).0;
|
||||
Ok(ContractCreateResult::Created(contract_address, *gas))
|
||||
}
|
||||
|
||||
fn call(
|
||||
&mut self,
|
||||
gas: &U256,
|
||||
_sender_address: &Address,
|
||||
receive_address: &Address,
|
||||
value: Option<U256>,
|
||||
data: &[u8],
|
||||
_code_address: &Address,
|
||||
_call_type: CallType,
|
||||
_trap: bool
|
||||
) -> Result<MessageCallResult, vm::TrapKind> {
|
||||
self.callcreates.push(CallCreate {
|
||||
data: data.to_vec(),
|
||||
destination: Some(receive_address.clone()),
|
||||
gas_limit: *gas,
|
||||
value: value.unwrap()
|
||||
});
|
||||
Ok(MessageCallResult::Success(*gas, ReturnData::empty()))
|
||||
}
|
||||
fn call(
|
||||
&mut self,
|
||||
gas: &U256,
|
||||
_sender_address: &Address,
|
||||
receive_address: &Address,
|
||||
value: Option<U256>,
|
||||
data: &[u8],
|
||||
_code_address: &Address,
|
||||
_call_type: CallType,
|
||||
_trap: bool,
|
||||
) -> Result<MessageCallResult, vm::TrapKind> {
|
||||
self.callcreates.push(CallCreate {
|
||||
data: data.to_vec(),
|
||||
destination: Some(receive_address.clone()),
|
||||
gas_limit: *gas,
|
||||
value: value.unwrap(),
|
||||
});
|
||||
Ok(MessageCallResult::Success(*gas, ReturnData::empty()))
|
||||
}
|
||||
|
||||
fn extcode(&self, address: &Address) -> vm::Result<Option<Arc<Bytes>>> {
|
||||
self.ext.extcode(address)
|
||||
}
|
||||
fn extcode(&self, address: &Address) -> vm::Result<Option<Arc<Bytes>>> {
|
||||
self.ext.extcode(address)
|
||||
}
|
||||
|
||||
fn extcodesize(&self, address: &Address) -> vm::Result<Option<usize>> {
|
||||
self.ext.extcodesize(address)
|
||||
}
|
||||
fn extcodesize(&self, address: &Address) -> vm::Result<Option<usize>> {
|
||||
self.ext.extcodesize(address)
|
||||
}
|
||||
|
||||
fn extcodehash(&self, address: &Address) -> vm::Result<Option<H256>> {
|
||||
self.ext.extcodehash(address)
|
||||
}
|
||||
fn extcodehash(&self, address: &Address) -> vm::Result<Option<H256>> {
|
||||
self.ext.extcodehash(address)
|
||||
}
|
||||
|
||||
fn log(&mut self, topics: Vec<H256>, data: &[u8]) -> vm::Result<()> {
|
||||
self.ext.log(topics, data)
|
||||
}
|
||||
fn log(&mut self, topics: Vec<H256>, data: &[u8]) -> vm::Result<()> {
|
||||
self.ext.log(topics, data)
|
||||
}
|
||||
|
||||
fn ret(self, gas: &U256, data: &ReturnData, apply_state: bool) -> Result<U256, vm::Error> {
|
||||
self.ext.ret(gas, data, apply_state)
|
||||
}
|
||||
fn ret(self, gas: &U256, data: &ReturnData, apply_state: bool) -> Result<U256, vm::Error> {
|
||||
self.ext.ret(gas, data, apply_state)
|
||||
}
|
||||
|
||||
fn suicide(&mut self, refund_address: &Address) -> vm::Result<()> {
|
||||
self.ext.suicide(refund_address)
|
||||
}
|
||||
fn suicide(&mut self, refund_address: &Address) -> vm::Result<()> {
|
||||
self.ext.suicide(refund_address)
|
||||
}
|
||||
|
||||
fn schedule(&self) -> &Schedule {
|
||||
self.ext.schedule()
|
||||
}
|
||||
fn schedule(&self) -> &Schedule {
|
||||
self.ext.schedule()
|
||||
}
|
||||
|
||||
fn env_info(&self) -> &EnvInfo {
|
||||
self.ext.env_info()
|
||||
}
|
||||
fn env_info(&self) -> &EnvInfo {
|
||||
self.ext.env_info()
|
||||
}
|
||||
|
||||
fn chain_id(&self) -> u64 { 0 }
|
||||
fn chain_id(&self) -> u64 {
|
||||
0
|
||||
}
|
||||
|
||||
fn depth(&self) -> usize {
|
||||
0
|
||||
}
|
||||
fn depth(&self) -> usize {
|
||||
0
|
||||
}
|
||||
|
||||
fn is_static(&self) -> bool {
|
||||
false
|
||||
}
|
||||
fn is_static(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn add_sstore_refund(&mut self, value: usize) {
|
||||
self.ext.add_sstore_refund(value)
|
||||
}
|
||||
fn add_sstore_refund(&mut self, value: usize) {
|
||||
self.ext.add_sstore_refund(value)
|
||||
}
|
||||
|
||||
fn sub_sstore_refund(&mut self, value: usize) {
|
||||
self.ext.sub_sstore_refund(value)
|
||||
}
|
||||
fn sub_sstore_refund(&mut self, value: usize) {
|
||||
self.ext.sub_sstore_refund(value)
|
||||
}
|
||||
}
|
||||
|
||||
fn do_json_test<H: FnMut(&str, HookType)>(json_data: &[u8], h: &mut H) -> Vec<String> {
|
||||
let vms = VMType::all();
|
||||
vms
|
||||
.iter()
|
||||
.flat_map(|vm| do_json_test_for(vm, json_data, h))
|
||||
.collect()
|
||||
let vms = VMType::all();
|
||||
vms.iter()
|
||||
.flat_map(|vm| do_json_test_for(vm, json_data, h))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn do_json_test_for<H: FnMut(&str, HookType)>(vm_type: &VMType, json_data: &[u8], start_stop_hook: &mut H) -> Vec<String> {
|
||||
let tests = ethjson::vm::Test::load(json_data).unwrap();
|
||||
let mut failed = Vec::new();
|
||||
fn do_json_test_for<H: FnMut(&str, HookType)>(
|
||||
vm_type: &VMType,
|
||||
json_data: &[u8],
|
||||
start_stop_hook: &mut H,
|
||||
) -> Vec<String> {
|
||||
let tests = ethjson::vm::Test::load(json_data).unwrap();
|
||||
let mut failed = Vec::new();
|
||||
|
||||
for (name, vm) in tests.into_iter() {
|
||||
start_stop_hook(&format!("{}-{}", name, vm_type), HookType::OnStart);
|
||||
for (name, vm) in tests.into_iter() {
|
||||
start_stop_hook(&format!("{}-{}", name, vm_type), HookType::OnStart);
|
||||
|
||||
info!(target: "jsontests", "name: {:?}", name);
|
||||
let mut fail = false;
|
||||
info!(target: "jsontests", "name: {:?}", name);
|
||||
let mut fail = false;
|
||||
|
||||
let mut fail_unless = |cond: bool, s: &str | if !cond && !fail {
|
||||
failed.push(format!("[{}] {}: {}", vm_type, name, s));
|
||||
fail = true
|
||||
};
|
||||
let mut fail_unless = |cond: bool, s: &str| {
|
||||
if !cond && !fail {
|
||||
failed.push(format!("[{}] {}: {}", vm_type, name, s));
|
||||
fail = true
|
||||
}
|
||||
};
|
||||
|
||||
macro_rules! try_fail {
|
||||
($e: expr) => {
|
||||
match $e {
|
||||
Ok(x) => x,
|
||||
Err(e) => {
|
||||
let msg = format!("Internal error: {}", e);
|
||||
fail_unless(false, &msg);
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
macro_rules! try_fail {
|
||||
($e: expr) => {
|
||||
match $e {
|
||||
Ok(x) => x,
|
||||
Err(e) => {
|
||||
let msg = format!("Internal error: {}", e);
|
||||
fail_unless(false, &msg);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let out_of_gas = vm.out_of_gas();
|
||||
let mut state = get_temp_state();
|
||||
state.populate_from(From::from(vm.pre_state.clone()));
|
||||
let info: EnvInfo = From::from(vm.env);
|
||||
let machine = {
|
||||
let mut machine = ::ethereum::new_frontier_test_machine();
|
||||
machine.set_schedule_creation_rules(Box::new(move |s, _| s.max_depth = 1));
|
||||
machine
|
||||
};
|
||||
let out_of_gas = vm.out_of_gas();
|
||||
let mut state = get_temp_state();
|
||||
state.populate_from(From::from(vm.pre_state.clone()));
|
||||
let info: EnvInfo = From::from(vm.env);
|
||||
let machine = {
|
||||
let mut machine = ::ethereum::new_frontier_test_machine();
|
||||
machine.set_schedule_creation_rules(Box::new(move |s, _| s.max_depth = 1));
|
||||
machine
|
||||
};
|
||||
|
||||
let params = ActionParams::from(vm.transaction);
|
||||
let params = ActionParams::from(vm.transaction);
|
||||
|
||||
let mut substate = Substate::new();
|
||||
let mut tracer = NoopTracer;
|
||||
let mut vm_tracer = NoopVMTracer;
|
||||
let vm_factory = state.vm_factory();
|
||||
let origin_info = OriginInfo::from(¶ms);
|
||||
let mut substate = Substate::new();
|
||||
let mut tracer = NoopTracer;
|
||||
let mut vm_tracer = NoopVMTracer;
|
||||
let vm_factory = state.vm_factory();
|
||||
let origin_info = OriginInfo::from(¶ms);
|
||||
|
||||
// execute
|
||||
let (res, callcreates) = {
|
||||
let schedule = machine.schedule(info.number);
|
||||
let mut ex = try_fail!(TestExt::new(
|
||||
&mut state,
|
||||
&info,
|
||||
&machine,
|
||||
&schedule,
|
||||
0,
|
||||
&origin_info,
|
||||
&mut substate,
|
||||
OutputPolicy::Return,
|
||||
params.address.clone(),
|
||||
&mut tracer,
|
||||
&mut vm_tracer,
|
||||
));
|
||||
let mut evm = vm_factory.create(params, &schedule, 0);
|
||||
let res = evm.exec(&mut ex).ok().expect("TestExt never trap; resume error never happens; qed");
|
||||
// a return in finalize will not alter callcreates
|
||||
let callcreates = ex.callcreates.clone();
|
||||
(res.finalize(ex), callcreates)
|
||||
};
|
||||
// execute
|
||||
let (res, callcreates) = {
|
||||
let schedule = machine.schedule(info.number);
|
||||
let mut ex = try_fail!(TestExt::new(
|
||||
&mut state,
|
||||
&info,
|
||||
&machine,
|
||||
&schedule,
|
||||
0,
|
||||
&origin_info,
|
||||
&mut substate,
|
||||
OutputPolicy::Return,
|
||||
params.address.clone(),
|
||||
&mut tracer,
|
||||
&mut vm_tracer,
|
||||
));
|
||||
let mut evm = vm_factory.create(params, &schedule, 0);
|
||||
let res = evm
|
||||
.exec(&mut ex)
|
||||
.ok()
|
||||
.expect("TestExt never trap; resume error never happens; qed");
|
||||
// a return in finalize will not alter callcreates
|
||||
let callcreates = ex.callcreates.clone();
|
||||
(res.finalize(ex), callcreates)
|
||||
};
|
||||
|
||||
let output = match &res {
|
||||
Ok(res) => res.return_data.to_vec(),
|
||||
Err(_) => Vec::new(),
|
||||
};
|
||||
let output = match &res {
|
||||
Ok(res) => res.return_data.to_vec(),
|
||||
Err(_) => Vec::new(),
|
||||
};
|
||||
|
||||
let log_hash = {
|
||||
let mut rlp = RlpStream::new_list(substate.logs.len());
|
||||
for l in &substate.logs {
|
||||
rlp.append(l);
|
||||
}
|
||||
keccak(&rlp.drain())
|
||||
};
|
||||
let log_hash = {
|
||||
let mut rlp = RlpStream::new_list(substate.logs.len());
|
||||
for l in &substate.logs {
|
||||
rlp.append(l);
|
||||
}
|
||||
keccak(&rlp.drain())
|
||||
};
|
||||
|
||||
match res {
|
||||
Err(_) => fail_unless(out_of_gas, "didn't expect to run out of gas."),
|
||||
Ok(res) => {
|
||||
fail_unless(!out_of_gas, "expected to run out of gas.");
|
||||
fail_unless(Some(res.gas_left) == vm.gas_left.map(Into::into), "gas_left is incorrect");
|
||||
let vm_output: Option<Vec<u8>> = vm.output.map(Into::into);
|
||||
fail_unless(Some(output) == vm_output, "output is incorrect");
|
||||
fail_unless(Some(log_hash) == vm.logs.map(|h| h.0), "logs are incorrect");
|
||||
match res {
|
||||
Err(_) => fail_unless(out_of_gas, "didn't expect to run out of gas."),
|
||||
Ok(res) => {
|
||||
fail_unless(!out_of_gas, "expected to run out of gas.");
|
||||
fail_unless(
|
||||
Some(res.gas_left) == vm.gas_left.map(Into::into),
|
||||
"gas_left is incorrect",
|
||||
);
|
||||
let vm_output: Option<Vec<u8>> = vm.output.map(Into::into);
|
||||
fail_unless(Some(output) == vm_output, "output is incorrect");
|
||||
fail_unless(Some(log_hash) == vm.logs.map(|h| h.0), "logs are incorrect");
|
||||
|
||||
for (address, account) in vm.post_state.unwrap().into_iter() {
|
||||
let address = address.into();
|
||||
let code: Vec<u8> = account.code.into();
|
||||
let found_code = try_fail!(state.code(&address));
|
||||
let found_balance = try_fail!(state.balance(&address));
|
||||
let found_nonce = try_fail!(state.nonce(&address));
|
||||
for (address, account) in vm.post_state.unwrap().into_iter() {
|
||||
let address = address.into();
|
||||
let code: Vec<u8> = account.code.into();
|
||||
let found_code = try_fail!(state.code(&address));
|
||||
let found_balance = try_fail!(state.balance(&address));
|
||||
let found_nonce = try_fail!(state.nonce(&address));
|
||||
|
||||
fail_unless(found_code.as_ref().map_or_else(|| code.is_empty(), |c| &**c == &code), "code is incorrect");
|
||||
fail_unless(found_balance == account.balance.into(), "balance is incorrect");
|
||||
fail_unless(found_nonce == account.nonce.into(), "nonce is incorrect");
|
||||
for (k, v) in account.storage {
|
||||
let key: U256 = k.into();
|
||||
let value: U256 = v.into();
|
||||
let found_storage = try_fail!(state.storage_at(&address, &From::from(key)));
|
||||
fail_unless(found_storage == From::from(value), "storage is incorrect");
|
||||
}
|
||||
}
|
||||
fail_unless(
|
||||
found_code
|
||||
.as_ref()
|
||||
.map_or_else(|| code.is_empty(), |c| &**c == &code),
|
||||
"code is incorrect",
|
||||
);
|
||||
fail_unless(
|
||||
found_balance == account.balance.into(),
|
||||
"balance is incorrect",
|
||||
);
|
||||
fail_unless(found_nonce == account.nonce.into(), "nonce is incorrect");
|
||||
for (k, v) in account.storage {
|
||||
let key: U256 = k.into();
|
||||
let value: U256 = v.into();
|
||||
let found_storage = try_fail!(state.storage_at(&address, &From::from(key)));
|
||||
fail_unless(found_storage == From::from(value), "storage is incorrect");
|
||||
}
|
||||
}
|
||||
|
||||
let calls: Option<Vec<CallCreate>> = vm.calls.map(|c| c.into_iter().map(From::from).collect());
|
||||
fail_unless(Some(callcreates) == calls, "callcreates does not match");
|
||||
}
|
||||
};
|
||||
let calls: Option<Vec<CallCreate>> =
|
||||
vm.calls.map(|c| c.into_iter().map(From::from).collect());
|
||||
fail_unless(Some(callcreates) == calls, "callcreates does not match");
|
||||
}
|
||||
};
|
||||
|
||||
start_stop_hook(&format!("{}-{}", name, vm_type), HookType::OnStop);
|
||||
}
|
||||
start_stop_hook(&format!("{}-{}", name, vm_type), HookType::OnStop);
|
||||
}
|
||||
|
||||
for f in &failed {
|
||||
error!("FAILED: {:?}", f);
|
||||
}
|
||||
for f in &failed {
|
||||
error!("FAILED: {:?}", f);
|
||||
}
|
||||
|
||||
failed
|
||||
failed
|
||||
}
|
||||
|
||||
declare_test!{ExecutiveTests_vmArithmeticTest, "VMTests/vmArithmeticTest"}
|
||||
declare_test!{ExecutiveTests_vmBitwiseLogicOperationTest, "VMTests/vmBitwiseLogicOperation"}
|
||||
declare_test!{ExecutiveTests_vmBlockInfoTest, "VMTests/vmBlockInfoTest"}
|
||||
// TODO [todr] Fails with Signal 11 when using JIT
|
||||
declare_test!{ExecutiveTests_vmEnvironmentalInfoTest, "VMTests/vmEnvironmentalInfo"}
|
||||
declare_test!{ExecutiveTests_vmIOandFlowOperationsTest, "VMTests/vmIOandFlowOperations"}
|
||||
declare_test!{ExecutiveTests_vmLogTest, "VMTests/vmLogTest"}
|
||||
declare_test!{heavy => ExecutiveTests_vmPerformance, "VMTests/vmPerformance"}
|
||||
declare_test!{ExecutiveTests_vmPushDupSwapTest, "VMTests/vmPushDupSwapTest"}
|
||||
declare_test!{ExecutiveTests_vmRandomTest, "VMTests/vmRandomTest"}
|
||||
declare_test!{ExecutiveTests_vmSha3Test, "VMTests/vmSha3Test"}
|
||||
declare_test!{ExecutiveTests_vmSystemOperationsTest, "VMTests/vmSystemOperations"}
|
||||
declare_test!{ExecutiveTests_vmTests, "VMTests/vmTests"}
|
||||
declare_test! {ExecutiveTests_vmArithmeticTest, "VMTests/vmArithmeticTest"}
|
||||
declare_test! {ExecutiveTests_vmBitwiseLogicOperationTest, "VMTests/vmBitwiseLogicOperation"}
|
||||
declare_test! {ExecutiveTests_vmBlockInfoTest, "VMTests/vmBlockInfoTest"}
|
||||
// TODO [todr] Fails with Signal 11 when using JIT
|
||||
declare_test! {ExecutiveTests_vmEnvironmentalInfoTest, "VMTests/vmEnvironmentalInfo"}
|
||||
declare_test! {ExecutiveTests_vmIOandFlowOperationsTest, "VMTests/vmIOandFlowOperations"}
|
||||
declare_test! {ExecutiveTests_vmLogTest, "VMTests/vmLogTest"}
|
||||
declare_test! {heavy => ExecutiveTests_vmPerformance, "VMTests/vmPerformance"}
|
||||
declare_test! {ExecutiveTests_vmPushDupSwapTest, "VMTests/vmPushDupSwapTest"}
|
||||
declare_test! {ExecutiveTests_vmRandomTest, "VMTests/vmRandomTest"}
|
||||
declare_test! {ExecutiveTests_vmSha3Test, "VMTests/vmSha3Test"}
|
||||
declare_test! {ExecutiveTests_vmSystemOperationsTest, "VMTests/vmSystemOperations"}
|
||||
declare_test! {ExecutiveTests_vmTests, "VMTests/vmTests"}
|
||||
|
||||
@@ -19,28 +19,32 @@
|
||||
#[macro_use]
|
||||
mod test_common;
|
||||
|
||||
mod transaction;
|
||||
mod executive;
|
||||
mod state;
|
||||
mod chain;
|
||||
mod trie;
|
||||
mod executive;
|
||||
mod skip;
|
||||
mod state;
|
||||
mod transaction;
|
||||
mod trie;
|
||||
|
||||
#[cfg(test)]
|
||||
mod difficulty;
|
||||
|
||||
pub use self::test_common::HookType;
|
||||
|
||||
pub use self::transaction::run_test_path as run_transaction_test_path;
|
||||
pub use self::transaction::run_test_file as run_transaction_test_file;
|
||||
pub use self::executive::run_test_path as run_executive_test_path;
|
||||
pub use self::executive::run_test_file as run_executive_test_file;
|
||||
pub use self::state::run_test_path as run_state_test_path;
|
||||
pub use self::state::run_test_file as run_state_test_file;
|
||||
pub use self::chain::run_test_path as run_chain_test_path;
|
||||
pub use self::chain::run_test_file as run_chain_test_file;
|
||||
pub use self::trie::run_generic_test_path as run_generic_trie_test_path;
|
||||
pub use self::trie::run_generic_test_file as run_generic_trie_test_file;
|
||||
pub use self::trie::run_secure_test_path as run_secure_trie_test_path;
|
||||
pub use self::trie::run_secure_test_file as run_secure_trie_test_file;
|
||||
use self::skip::SKIP_TEST_STATE;
|
||||
pub use self::{
|
||||
chain::{run_test_file as run_chain_test_file, run_test_path as run_chain_test_path},
|
||||
executive::{
|
||||
run_test_file as run_executive_test_file, run_test_path as run_executive_test_path,
|
||||
},
|
||||
state::{run_test_file as run_state_test_file, run_test_path as run_state_test_path},
|
||||
transaction::{
|
||||
run_test_file as run_transaction_test_file, run_test_path as run_transaction_test_path,
|
||||
},
|
||||
trie::{
|
||||
run_generic_test_file as run_generic_trie_test_file,
|
||||
run_generic_test_path as run_generic_trie_test_path,
|
||||
run_secure_test_file as run_secure_trie_test_file,
|
||||
run_secure_test_path as run_secure_trie_test_path,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -18,17 +18,15 @@
|
||||
|
||||
use ethjson;
|
||||
|
||||
#[cfg(feature="ci-skip-tests")]
|
||||
lazy_static!{
|
||||
pub static ref SKIP_TEST_STATE: ethjson::test::SkipStates = {
|
||||
let skip_data = include_bytes!("../../res/ethereum/tests-issues/currents.json");
|
||||
ethjson::test::SkipStates::load(&skip_data[..]).expect("No invalid json allowed")
|
||||
};
|
||||
#[cfg(feature = "ci-skip-tests")]
|
||||
lazy_static! {
|
||||
pub static ref SKIP_TEST_STATE: ethjson::test::SkipStates = {
|
||||
let skip_data = include_bytes!("../../res/ethereum/tests-issues/currents.json");
|
||||
ethjson::test::SkipStates::load(&skip_data[..]).expect("No invalid json allowed")
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(not(feature="ci-skip-tests"))]
|
||||
lazy_static!{
|
||||
pub static ref SKIP_TEST_STATE: ethjson::test::SkipStates = {
|
||||
ethjson::test::SkipStates::empty()
|
||||
};
|
||||
#[cfg(not(feature = "ci-skip-tests"))]
|
||||
lazy_static! {
|
||||
pub static ref SKIP_TEST_STATE: ethjson::test::SkipStates = ethjson::test::SkipStates::empty();
|
||||
}
|
||||
|
||||
@@ -14,175 +14,194 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::path::Path;
|
||||
use super::test_common::*;
|
||||
use pod_state::PodState;
|
||||
use trace;
|
||||
use super::{test_common::*, HookType, SKIP_TEST_STATE};
|
||||
use client::{EvmTestClient, EvmTestError, TransactErr, TransactSuccess};
|
||||
use ethjson;
|
||||
use pod_state::PodState;
|
||||
use std::path::Path;
|
||||
use trace;
|
||||
use types::transaction::SignedTransaction;
|
||||
use vm::EnvInfo;
|
||||
use super::SKIP_TEST_STATE;
|
||||
use super::HookType;
|
||||
|
||||
/// Run state 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)
|
||||
::json_tests::test_common::run_test_path(p, skip, json_chain_test, h)
|
||||
}
|
||||
|
||||
/// Run state 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)
|
||||
::json_tests::test_common::run_test_file(p, json_chain_test, h)
|
||||
}
|
||||
|
||||
fn skip_test(subname: &str, chain: &String, number: usize) -> bool {
|
||||
SKIP_TEST_STATE.state.iter().any(|state_test|{
|
||||
if let Some(subtest) = state_test.subtests.get(subname) {
|
||||
chain == &subtest.chain &&
|
||||
(subtest.subnumbers[0] == "*"
|
||||
|| subtest.subnumbers.contains(&number.to_string()))
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
SKIP_TEST_STATE.state.iter().any(|state_test| {
|
||||
if let Some(subtest) = state_test.subtests.get(subname) {
|
||||
chain == &subtest.chain
|
||||
&& (subtest.subnumbers[0] == "*"
|
||||
|| subtest.subnumbers.contains(&number.to_string()))
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn json_chain_test<H: FnMut(&str, HookType)>(json_data: &[u8], start_stop_hook: &mut H) -> Vec<String> {
|
||||
let _ = ::env_logger::try_init();
|
||||
let tests = ethjson::state::test::Test::load(json_data).unwrap();
|
||||
let mut failed = Vec::new();
|
||||
pub fn json_chain_test<H: FnMut(&str, HookType)>(
|
||||
json_data: &[u8],
|
||||
start_stop_hook: &mut H,
|
||||
) -> Vec<String> {
|
||||
let _ = ::env_logger::try_init();
|
||||
let tests = ethjson::state::test::Test::load(json_data).unwrap();
|
||||
let mut failed = Vec::new();
|
||||
|
||||
for (name, test) in tests.into_iter() {
|
||||
start_stop_hook(&name, HookType::OnStart);
|
||||
for (name, test) in tests.into_iter() {
|
||||
start_stop_hook(&name, HookType::OnStart);
|
||||
|
||||
{
|
||||
let multitransaction = test.transaction;
|
||||
let env: EnvInfo = test.env.into();
|
||||
let pre: PodState = test.pre_state.into();
|
||||
{
|
||||
let multitransaction = test.transaction;
|
||||
let env: EnvInfo = test.env.into();
|
||||
let pre: PodState = test.pre_state.into();
|
||||
|
||||
for (spec_name, states) in test.post_states {
|
||||
let total = states.len();
|
||||
let spec = match EvmTestClient::spec_from_json(&spec_name) {
|
||||
Some(spec) => spec,
|
||||
None => {
|
||||
println!(" - {} | {:?} Ignoring tests because of missing spec", name, spec_name);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
for (spec_name, states) in test.post_states {
|
||||
let total = states.len();
|
||||
let spec = match EvmTestClient::spec_from_json(&spec_name) {
|
||||
Some(spec) => spec,
|
||||
None => {
|
||||
println!(
|
||||
" - {} | {:?} Ignoring tests because of missing spec",
|
||||
name, spec_name
|
||||
);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
for (i, state) in states.into_iter().enumerate() {
|
||||
let info = format!(" - {} | {:?} ({}/{}) ...", name, spec_name, i + 1, total);
|
||||
if skip_test(&name, &spec.name, i + 1) {
|
||||
println!("{} in skip list : SKIPPED", info);
|
||||
continue;
|
||||
}
|
||||
for (i, state) in states.into_iter().enumerate() {
|
||||
let info = format!(" - {} | {:?} ({}/{}) ...", name, spec_name, i + 1, total);
|
||||
if skip_test(&name, &spec.name, i + 1) {
|
||||
println!("{} in skip list : SKIPPED", info);
|
||||
continue;
|
||||
}
|
||||
|
||||
let post_root: H256 = state.hash.into();
|
||||
let transaction: SignedTransaction = multitransaction.select(&state.indexes).into();
|
||||
let post_root: H256 = state.hash.into();
|
||||
let transaction: SignedTransaction =
|
||||
multitransaction.select(&state.indexes).into();
|
||||
|
||||
let result = || -> Result<_, EvmTestError> {
|
||||
Ok(EvmTestClient::from_pod_state(&spec, pre.clone())?
|
||||
.transact(&env, transaction, trace::NoopTracer, trace::NoopVMTracer))
|
||||
};
|
||||
match result() {
|
||||
Err(err) => {
|
||||
println!("{} !!! Unexpected internal error: {:?}", info, err);
|
||||
flushln!("{} fail", info);
|
||||
failed.push(name.clone());
|
||||
},
|
||||
Ok(Ok(TransactSuccess { 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(Err(TransactErr { 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(Err(TransactErr { error, .. })) => {
|
||||
flushln!("{} ok ({:?})", info, error);
|
||||
},
|
||||
Ok(_) => {
|
||||
flushln!("{} ok", info);
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let result = || -> Result<_, EvmTestError> {
|
||||
Ok(EvmTestClient::from_pod_state(&spec, pre.clone())?.transact(
|
||||
&env,
|
||||
transaction,
|
||||
trace::NoopTracer,
|
||||
trace::NoopVMTracer,
|
||||
))
|
||||
};
|
||||
match result() {
|
||||
Err(err) => {
|
||||
println!("{} !!! Unexpected internal error: {:?}", info, err);
|
||||
flushln!("{} fail", info);
|
||||
failed.push(name.clone());
|
||||
}
|
||||
Ok(Ok(TransactSuccess { 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(Err(TransactErr {
|
||||
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(Err(TransactErr { error, .. })) => {
|
||||
flushln!("{} ok ({:?})", info, error);
|
||||
}
|
||||
Ok(_) => {
|
||||
flushln!("{} ok", info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
start_stop_hook(&name, HookType::OnStop);
|
||||
}
|
||||
start_stop_hook(&name, HookType::OnStop);
|
||||
}
|
||||
|
||||
if !failed.is_empty() {
|
||||
println!("!!! {:?} tests failed.", failed.len());
|
||||
}
|
||||
failed
|
||||
if !failed.is_empty() {
|
||||
println!("!!! {:?} tests failed.", failed.len());
|
||||
}
|
||||
failed
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod state_tests {
|
||||
use super::json_chain_test;
|
||||
use json_tests::HookType;
|
||||
use super::json_chain_test;
|
||||
use json_tests::HookType;
|
||||
|
||||
fn do_json_test<H: FnMut(&str, HookType)>(json_data: &[u8], h: &mut H) -> Vec<String> {
|
||||
json_chain_test(json_data, h)
|
||||
}
|
||||
fn do_json_test<H: FnMut(&str, HookType)>(json_data: &[u8], h: &mut H) -> Vec<String> {
|
||||
json_chain_test(json_data, h)
|
||||
}
|
||||
|
||||
declare_test!{GeneralStateTest_stArgsZeroOneBalance, "GeneralStateTests/stArgsZeroOneBalance/"}
|
||||
declare_test!{GeneralStateTest_stAttackTest, "GeneralStateTests/stAttackTest/"}
|
||||
declare_test!{GeneralStateTest_stBadOpcodeTest, "GeneralStateTests/stBadOpcode/"}
|
||||
declare_test!{GeneralStateTest_stBugs, "GeneralStateTests/stBugs/"}
|
||||
declare_test!{GeneralStateTest_stCallCodes, "GeneralStateTests/stCallCodes/"}
|
||||
declare_test!{GeneralStateTest_stCallCreateCallCodeTest, "GeneralStateTests/stCallCreateCallCodeTest/"}
|
||||
declare_test!{GeneralStateTest_stCallDelegateCodesCallCodeHomestead, "GeneralStateTests/stCallDelegateCodesCallCodeHomestead/"}
|
||||
declare_test!{GeneralStateTest_stCallDelegateCodesHomestead, "GeneralStateTests/stCallDelegateCodesHomestead/"}
|
||||
declare_test!{GeneralStateTest_stChangedEIP150, "GeneralStateTests/stChangedEIP150/"}
|
||||
declare_test!{GeneralStateTest_stCodeCopyTest, "GeneralStateTests/stCodeCopyTest/"}
|
||||
declare_test!{GeneralStateTest_stCodeSizeLimit, "GeneralStateTests/stCodeSizeLimit/"}
|
||||
declare_test!{GeneralStateTest_stCreate2Test, "GeneralStateTests/stCreate2/"}
|
||||
declare_test!{GeneralStateTest_stCreateTest, "GeneralStateTests/stCreateTest/"}
|
||||
declare_test!{GeneralStateTest_stDelegatecallTestHomestead, "GeneralStateTests/stDelegatecallTestHomestead/"}
|
||||
declare_test!{GeneralStateTest_stEIP150singleCodeGasPrices, "GeneralStateTests/stEIP150singleCodeGasPrices/"}
|
||||
declare_test!{GeneralStateTest_stEIP150Specific, "GeneralStateTests/stEIP150Specific/"}
|
||||
declare_test!{GeneralStateTest_stEIP158Specific, "GeneralStateTests/stEIP158Specific/"}
|
||||
declare_test!{GeneralStateTest_stEWASMTests, "GeneralStateTests/stEWASMTests/"}
|
||||
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!{GeneralStateTest_stPreCompiledContracts2, "GeneralStateTests/stPreCompiledContracts2/"}
|
||||
declare_test!{heavy => GeneralStateTest_stQuadraticComplexityTest, "GeneralStateTests/stQuadraticComplexityTest/"}
|
||||
declare_test!{GeneralStateTest_stRandom, "GeneralStateTests/stRandom/"}
|
||||
declare_test!{GeneralStateTest_stRandom2, "GeneralStateTests/stRandom2/"}
|
||||
declare_test!{GeneralStateTest_stRecursiveCreate, "GeneralStateTests/stRecursiveCreate/"}
|
||||
declare_test!{GeneralStateTest_stRefundTest, "GeneralStateTests/stRefundTest/"}
|
||||
declare_test!{GeneralStateTest_stReturnDataTest, "GeneralStateTests/stReturnDataTest/"}
|
||||
declare_test!{GeneralStateTest_stRevertTest, "GeneralStateTests/stRevertTest/"}
|
||||
declare_test!{GeneralStateTest_stSStoreTest, "GeneralStateTests/stSStoreTest/"}
|
||||
declare_test!{GeneralStateTest_stShift, "GeneralStateTests/stShift/"}
|
||||
declare_test!{GeneralStateTest_stSolidityTest, "GeneralStateTests/stSolidityTest/"}
|
||||
declare_test!{GeneralStateTest_stSpecialTest, "GeneralStateTests/stSpecialTest/"}
|
||||
declare_test!{GeneralStateTest_stStackTests, "GeneralStateTests/stStackTests/"}
|
||||
declare_test!{GeneralStateTest_stStaticCall, "GeneralStateTests/stStaticCall/"}
|
||||
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/"}
|
||||
declare_test!{GeneralStateTest_stZeroKnowledge, "GeneralStateTests/stZeroKnowledge/"}
|
||||
declare_test! {GeneralStateTest_stArgsZeroOneBalance, "GeneralStateTests/stArgsZeroOneBalance/"}
|
||||
declare_test! {GeneralStateTest_stAttackTest, "GeneralStateTests/stAttackTest/"}
|
||||
declare_test! {GeneralStateTest_stBadOpcodeTest, "GeneralStateTests/stBadOpcode/"}
|
||||
declare_test! {GeneralStateTest_stBugs, "GeneralStateTests/stBugs/"}
|
||||
declare_test! {GeneralStateTest_stCallCodes, "GeneralStateTests/stCallCodes/"}
|
||||
declare_test! {GeneralStateTest_stCallCreateCallCodeTest, "GeneralStateTests/stCallCreateCallCodeTest/"}
|
||||
declare_test! {GeneralStateTest_stCallDelegateCodesCallCodeHomestead, "GeneralStateTests/stCallDelegateCodesCallCodeHomestead/"}
|
||||
declare_test! {GeneralStateTest_stCallDelegateCodesHomestead, "GeneralStateTests/stCallDelegateCodesHomestead/"}
|
||||
declare_test! {GeneralStateTest_stChangedEIP150, "GeneralStateTests/stChangedEIP150/"}
|
||||
declare_test! {GeneralStateTest_stCodeCopyTest, "GeneralStateTests/stCodeCopyTest/"}
|
||||
declare_test! {GeneralStateTest_stCodeSizeLimit, "GeneralStateTests/stCodeSizeLimit/"}
|
||||
declare_test! {GeneralStateTest_stCreate2Test, "GeneralStateTests/stCreate2/"}
|
||||
declare_test! {GeneralStateTest_stCreateTest, "GeneralStateTests/stCreateTest/"}
|
||||
declare_test! {GeneralStateTest_stDelegatecallTestHomestead, "GeneralStateTests/stDelegatecallTestHomestead/"}
|
||||
declare_test! {GeneralStateTest_stEIP150singleCodeGasPrices, "GeneralStateTests/stEIP150singleCodeGasPrices/"}
|
||||
declare_test! {GeneralStateTest_stEIP150Specific, "GeneralStateTests/stEIP150Specific/"}
|
||||
declare_test! {GeneralStateTest_stEIP158Specific, "GeneralStateTests/stEIP158Specific/"}
|
||||
declare_test! {GeneralStateTest_stEWASMTests, "GeneralStateTests/stEWASMTests/"}
|
||||
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! {GeneralStateTest_stPreCompiledContracts2, "GeneralStateTests/stPreCompiledContracts2/"}
|
||||
declare_test! {heavy => GeneralStateTest_stQuadraticComplexityTest, "GeneralStateTests/stQuadraticComplexityTest/"}
|
||||
declare_test! {GeneralStateTest_stRandom, "GeneralStateTests/stRandom/"}
|
||||
declare_test! {GeneralStateTest_stRandom2, "GeneralStateTests/stRandom2/"}
|
||||
declare_test! {GeneralStateTest_stRecursiveCreate, "GeneralStateTests/stRecursiveCreate/"}
|
||||
declare_test! {GeneralStateTest_stRefundTest, "GeneralStateTests/stRefundTest/"}
|
||||
declare_test! {GeneralStateTest_stReturnDataTest, "GeneralStateTests/stReturnDataTest/"}
|
||||
declare_test! {GeneralStateTest_stRevertTest, "GeneralStateTests/stRevertTest/"}
|
||||
declare_test! {GeneralStateTest_stSStoreTest, "GeneralStateTests/stSStoreTest/"}
|
||||
declare_test! {GeneralStateTest_stShift, "GeneralStateTests/stShift/"}
|
||||
declare_test! {GeneralStateTest_stSolidityTest, "GeneralStateTests/stSolidityTest/"}
|
||||
declare_test! {GeneralStateTest_stSpecialTest, "GeneralStateTests/stSpecialTest/"}
|
||||
declare_test! {GeneralStateTest_stStackTests, "GeneralStateTests/stStackTests/"}
|
||||
declare_test! {GeneralStateTest_stStaticCall, "GeneralStateTests/stStaticCall/"}
|
||||
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/"}
|
||||
declare_test! {GeneralStateTest_stZeroKnowledge, "GeneralStateTests/stZeroKnowledge/"}
|
||||
|
||||
// Attempts to send a transaction that requires more than current balance:
|
||||
// Tx:
|
||||
// https://github.com/ethereum/tests/blob/726b161ba8a739691006cc1ba080672bb50a9d49/GeneralStateTests/stZeroKnowledge2/ecmul_0-3_5616_28000_96.json#L170
|
||||
// Balance:
|
||||
// https://github.com/ethereum/tests/blob/726b161ba8a739691006cc1ba080672bb50a9d49/GeneralStateTests/stZeroKnowledge2/ecmul_0-3_5616_28000_96.json#L126
|
||||
declare_test!{GeneralStateTest_stZeroKnowledge2, "GeneralStateTests/stZeroKnowledge2/"}
|
||||
// Attempts to send a transaction that requires more than current balance:
|
||||
// Tx:
|
||||
// https://github.com/ethereum/tests/blob/726b161ba8a739691006cc1ba080672bb50a9d49/GeneralStateTests/stZeroKnowledge2/ecmul_0-3_5616_28000_96.json#L170
|
||||
// Balance:
|
||||
// https://github.com/ethereum/tests/blob/726b161ba8a739691006cc1ba080672bb50a9d49/GeneralStateTests/stZeroKnowledge2/ecmul_0-3_5616_28000_96.json#L126
|
||||
declare_test! {GeneralStateTest_stZeroKnowledge2, "GeneralStateTests/stZeroKnowledge2/"}
|
||||
}
|
||||
|
||||
@@ -14,137 +14,152 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::io::Read;
|
||||
use std::fs::{File, read_dir};
|
||||
use std::path::Path;
|
||||
use std::ffi::OsString;
|
||||
pub use ethereum_types::{H256, U256, Address};
|
||||
pub use ethereum_types::{Address, H256, U256};
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
ffi::OsString,
|
||||
fs::{read_dir, File},
|
||||
io::Read,
|
||||
path::Path,
|
||||
};
|
||||
|
||||
/// Indicate when to run the hook passed to test functions.
|
||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||
pub enum HookType {
|
||||
/// Hook to code to run on test start.
|
||||
OnStart,
|
||||
/// Hook to code to run on test end.
|
||||
OnStop
|
||||
/// Hook to code to run on test start.
|
||||
OnStart,
|
||||
/// Hook to code to run on test end.
|
||||
OnStop,
|
||||
}
|
||||
|
||||
pub fn run_test_path<H: FnMut(&str, HookType)>(
|
||||
p: &Path, skip: &[&'static str],
|
||||
runner: fn(json_data: &[u8], start_stop_hook: &mut H) -> Vec<String>,
|
||||
start_stop_hook: &mut H
|
||||
p: &Path,
|
||||
skip: &[&'static str],
|
||||
runner: fn(json_data: &[u8], start_stop_hook: &mut H) -> Vec<String>,
|
||||
start_stop_hook: &mut H,
|
||||
) {
|
||||
let mut errors = Vec::new();
|
||||
run_test_path_inner(p, skip, runner, start_stop_hook, &mut errors);
|
||||
let empty: [String; 0] = [];
|
||||
assert_eq!(errors, empty);
|
||||
let mut errors = Vec::new();
|
||||
run_test_path_inner(p, skip, runner, start_stop_hook, &mut errors);
|
||||
let empty: [String; 0] = [];
|
||||
assert_eq!(errors, empty);
|
||||
}
|
||||
|
||||
fn run_test_path_inner<H: FnMut(&str, HookType)>(
|
||||
p: &Path, skip: &[&'static str],
|
||||
runner: fn(json_data: &[u8], start_stop_hook: &mut H) -> Vec<String>,
|
||||
start_stop_hook: &mut H,
|
||||
errors: &mut Vec<String>
|
||||
p: &Path,
|
||||
skip: &[&'static str],
|
||||
runner: fn(json_data: &[u8], start_stop_hook: &mut H) -> Vec<String>,
|
||||
start_stop_hook: &mut H,
|
||||
errors: &mut Vec<String>,
|
||||
) {
|
||||
let path = Path::new(p);
|
||||
let s: HashSet<OsString> = skip.iter().map(|s| {
|
||||
let mut os: OsString = s.into();
|
||||
os.push(".json");
|
||||
os
|
||||
}).collect();
|
||||
let extension = path.extension().and_then(|s| s.to_str());
|
||||
if path.is_dir() {
|
||||
for p in read_dir(path).unwrap().filter_map(|e| {
|
||||
let e = e.unwrap();
|
||||
if s.contains(&e.file_name()) {
|
||||
None
|
||||
} else {
|
||||
Some(e.path())
|
||||
}}) {
|
||||
run_test_path_inner(&p, skip, runner, start_stop_hook, errors);
|
||||
}
|
||||
} else if extension == Some("swp") || extension == None {
|
||||
// Ignore junk
|
||||
} else {
|
||||
let mut path = p.to_path_buf();
|
||||
path.set_extension("json");
|
||||
run_test_file_append(&path, runner, start_stop_hook, errors)
|
||||
}
|
||||
let path = Path::new(p);
|
||||
let s: HashSet<OsString> = skip
|
||||
.iter()
|
||||
.map(|s| {
|
||||
let mut os: OsString = s.into();
|
||||
os.push(".json");
|
||||
os
|
||||
})
|
||||
.collect();
|
||||
let extension = path.extension().and_then(|s| s.to_str());
|
||||
if path.is_dir() {
|
||||
for p in read_dir(path).unwrap().filter_map(|e| {
|
||||
let e = e.unwrap();
|
||||
if s.contains(&e.file_name()) {
|
||||
None
|
||||
} else {
|
||||
Some(e.path())
|
||||
}
|
||||
}) {
|
||||
run_test_path_inner(&p, skip, runner, start_stop_hook, errors);
|
||||
}
|
||||
} else if extension == Some("swp") || extension == None {
|
||||
// Ignore junk
|
||||
} else {
|
||||
let mut path = p.to_path_buf();
|
||||
path.set_extension("json");
|
||||
run_test_file_append(&path, runner, start_stop_hook, errors)
|
||||
}
|
||||
}
|
||||
|
||||
fn run_test_file_append<H: FnMut(&str, HookType)>(
|
||||
path: &Path,
|
||||
runner: fn(json_data: &[u8], start_stop_hook: &mut H) -> Vec<String>,
|
||||
start_stop_hook: &mut H,
|
||||
errors: &mut Vec<String>
|
||||
path: &Path,
|
||||
runner: fn(json_data: &[u8], start_stop_hook: &mut H) -> Vec<String>,
|
||||
start_stop_hook: &mut H,
|
||||
errors: &mut Vec<String>,
|
||||
) {
|
||||
let mut data = Vec::new();
|
||||
let mut file = match File::open(&path) {
|
||||
Ok(file) => file,
|
||||
Err(_) => panic!("Error opening test file at: {:?}", path),
|
||||
};
|
||||
file.read_to_end(&mut data).expect("Error reading test file");
|
||||
errors.append(&mut runner(&data, start_stop_hook));
|
||||
let mut data = Vec::new();
|
||||
let mut file = match File::open(&path) {
|
||||
Ok(file) => file,
|
||||
Err(_) => panic!("Error opening test file at: {:?}", path),
|
||||
};
|
||||
file.read_to_end(&mut data)
|
||||
.expect("Error reading test file");
|
||||
errors.append(&mut runner(&data, start_stop_hook));
|
||||
}
|
||||
|
||||
pub fn run_test_file<H: FnMut(&str, HookType)>(
|
||||
path: &Path,
|
||||
runner: fn(json_data: &[u8], start_stop_hook: &mut H) -> Vec<String>,
|
||||
start_stop_hook: &mut H
|
||||
path: &Path,
|
||||
runner: fn(json_data: &[u8], start_stop_hook: &mut H) -> Vec<String>,
|
||||
start_stop_hook: &mut H,
|
||||
) {
|
||||
let mut data = Vec::new();
|
||||
let mut file = match File::open(&path) {
|
||||
Ok(file) => file,
|
||||
Err(_) => panic!("Error opening test file at: {:?}", path),
|
||||
};
|
||||
file.read_to_end(&mut data).expect("Error reading test file");
|
||||
let results = runner(&data, start_stop_hook);
|
||||
let empty: [String; 0] = [];
|
||||
assert_eq!(results, empty);
|
||||
let mut data = Vec::new();
|
||||
let mut file = match File::open(&path) {
|
||||
Ok(file) => file,
|
||||
Err(_) => panic!("Error opening test file at: {:?}", path),
|
||||
};
|
||||
file.read_to_end(&mut data)
|
||||
.expect("Error reading test file");
|
||||
let results = runner(&data, start_stop_hook);
|
||||
let empty: [String; 0] = [];
|
||||
assert_eq!(results, empty);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
macro_rules! test {
|
||||
($name: expr, $skip: expr) => {
|
||||
::json_tests::test_common::run_test_path(::std::path::Path::new(concat!("res/ethereum/tests/", $name)), &$skip, do_json_test, &mut |_, _| ());
|
||||
}
|
||||
($name: expr, $skip: expr) => {
|
||||
::json_tests::test_common::run_test_path(
|
||||
::std::path::Path::new(concat!("res/ethereum/tests/", $name)),
|
||||
&$skip,
|
||||
do_json_test,
|
||||
&mut |_, _| (),
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! declare_test {
|
||||
(skip => $arr: expr, $id: ident, $name: expr) => {
|
||||
#[cfg(test)]
|
||||
#[test]
|
||||
#[allow(non_snake_case)]
|
||||
fn $id() {
|
||||
test!($name, $arr);
|
||||
}
|
||||
};
|
||||
(ignore => $id: ident, $name: expr) => {
|
||||
#[cfg(test)]
|
||||
#[ignore]
|
||||
#[test]
|
||||
#[allow(non_snake_case)]
|
||||
fn $id() {
|
||||
test!($name, []);
|
||||
}
|
||||
};
|
||||
(heavy => $id: ident, $name: expr) => {
|
||||
#[cfg(test)]
|
||||
#[cfg(feature = "test-heavy")]
|
||||
#[test]
|
||||
#[allow(non_snake_case)]
|
||||
fn $id() {
|
||||
test!($name, []);
|
||||
}
|
||||
};
|
||||
($id: ident, $name: expr) => {
|
||||
#[cfg(test)]
|
||||
#[test]
|
||||
#[allow(non_snake_case)]
|
||||
fn $id() {
|
||||
test!($name, []);
|
||||
}
|
||||
}
|
||||
(skip => $arr: expr, $id: ident, $name: expr) => {
|
||||
#[cfg(test)]
|
||||
#[test]
|
||||
#[allow(non_snake_case)]
|
||||
fn $id() {
|
||||
test!($name, $arr);
|
||||
}
|
||||
};
|
||||
(ignore => $id: ident, $name: expr) => {
|
||||
#[cfg(test)]
|
||||
#[ignore]
|
||||
#[test]
|
||||
#[allow(non_snake_case)]
|
||||
fn $id() {
|
||||
test!($name, []);
|
||||
}
|
||||
};
|
||||
(heavy => $id: ident, $name: expr) => {
|
||||
#[cfg(test)]
|
||||
#[cfg(feature = "test-heavy")]
|
||||
#[test]
|
||||
#[allow(non_snake_case)]
|
||||
fn $id() {
|
||||
test!($name, []);
|
||||
}
|
||||
};
|
||||
($id: ident, $name: expr) => {
|
||||
#[cfg(test)]
|
||||
#[test]
|
||||
#[allow(non_snake_case)]
|
||||
fn $id() {
|
||||
test!($name, []);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,99 +14,110 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::path::Path;
|
||||
use super::test_common::*;
|
||||
use client::EvmTestClient;
|
||||
use ethjson;
|
||||
use rlp::Rlp;
|
||||
use types::header::Header;
|
||||
use types::transaction::UnverifiedTransaction;
|
||||
use std::path::Path;
|
||||
use transaction_ext::Transaction;
|
||||
use types::{header::Header, transaction::UnverifiedTransaction};
|
||||
|
||||
/// Run transaction 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, do_json_test, h)
|
||||
::json_tests::test_common::run_test_path(p, skip, do_json_test, h)
|
||||
}
|
||||
|
||||
/// Run transaction 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, do_json_test, h)
|
||||
::json_tests::test_common::run_test_file(p, do_json_test, h)
|
||||
}
|
||||
|
||||
// Block number used to run the tests.
|
||||
// Make sure that all the specified features are activated.
|
||||
const BLOCK_NUMBER: u64 = 0x6ffffffffffffe;
|
||||
|
||||
fn do_json_test<H: FnMut(&str, HookType)>(json_data: &[u8], start_stop_hook: &mut H) -> Vec<String> {
|
||||
let tests = ethjson::transaction::Test::load(json_data).unwrap();
|
||||
let mut failed = Vec::new();
|
||||
for (name, test) in tests.into_iter() {
|
||||
start_stop_hook(&name, HookType::OnStart);
|
||||
fn do_json_test<H: FnMut(&str, HookType)>(
|
||||
json_data: &[u8],
|
||||
start_stop_hook: &mut H,
|
||||
) -> Vec<String> {
|
||||
let tests = ethjson::transaction::Test::load(json_data).unwrap();
|
||||
let mut failed = Vec::new();
|
||||
for (name, test) in tests.into_iter() {
|
||||
start_stop_hook(&name, HookType::OnStart);
|
||||
|
||||
for (spec_name, result) in test.post_state {
|
||||
let spec = match EvmTestClient::spec_from_json(&spec_name) {
|
||||
Some(spec) => spec,
|
||||
None => {
|
||||
println!(" - {} | {:?} Ignoring tests because of missing spec", name, spec_name);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
for (spec_name, result) in test.post_state {
|
||||
let spec = match EvmTestClient::spec_from_json(&spec_name) {
|
||||
Some(spec) => spec,
|
||||
None => {
|
||||
println!(
|
||||
" - {} | {:?} Ignoring tests because of missing spec",
|
||||
name, spec_name
|
||||
);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
let mut fail_unless = |cond: bool, title: &str| if !cond {
|
||||
failed.push(format!("{}-{:?}", name, spec_name));
|
||||
println!("Transaction failed: {:?}-{:?}: {:?}", name, spec_name, title);
|
||||
};
|
||||
let mut fail_unless = |cond: bool, title: &str| {
|
||||
if !cond {
|
||||
failed.push(format!("{}-{:?}", name, spec_name));
|
||||
println!(
|
||||
"Transaction failed: {:?}-{:?}: {:?}",
|
||||
name, spec_name, title
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
let rlp: Vec<u8> = test.rlp.clone().into();
|
||||
let res = Rlp::new(&rlp)
|
||||
.as_val()
|
||||
.map_err(::error::Error::from)
|
||||
.and_then(|t: UnverifiedTransaction| {
|
||||
let mut header: Header = Default::default();
|
||||
// Use high enough number to activate all required features.
|
||||
header.set_number(BLOCK_NUMBER);
|
||||
let rlp: Vec<u8> = test.rlp.clone().into();
|
||||
let res = Rlp::new(&rlp)
|
||||
.as_val()
|
||||
.map_err(::error::Error::from)
|
||||
.and_then(|t: UnverifiedTransaction| {
|
||||
let mut header: Header = Default::default();
|
||||
// Use high enough number to activate all required features.
|
||||
header.set_number(BLOCK_NUMBER);
|
||||
|
||||
let minimal = t.gas_required(&spec.engine.schedule(header.number())).into();
|
||||
if t.gas < minimal {
|
||||
return Err(::types::transaction::Error::InsufficientGas {
|
||||
minimal, got: t.gas,
|
||||
}.into());
|
||||
}
|
||||
spec.engine.verify_transaction_basic(&t, &header)?;
|
||||
Ok(spec.engine.verify_transaction_unordered(t, &header)?)
|
||||
});
|
||||
let minimal = t
|
||||
.gas_required(&spec.engine.schedule(header.number()))
|
||||
.into();
|
||||
if t.gas < minimal {
|
||||
return Err(::types::transaction::Error::InsufficientGas {
|
||||
minimal,
|
||||
got: t.gas,
|
||||
}
|
||||
.into());
|
||||
}
|
||||
spec.engine.verify_transaction_basic(&t, &header)?;
|
||||
Ok(spec.engine.verify_transaction_unordered(t, &header)?)
|
||||
});
|
||||
|
||||
match (res, result.hash, result.sender) {
|
||||
(Ok(t), Some(hash), Some(sender)) => {
|
||||
fail_unless(t.sender() == sender.into(), "sender mismatch");
|
||||
fail_unless(t.hash() == hash.into(), "hash mismatch");
|
||||
},
|
||||
(Err(_), None, None) => {},
|
||||
data => {
|
||||
fail_unless(
|
||||
false,
|
||||
&format!("Validity different: {:?}", data)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
match (res, result.hash, result.sender) {
|
||||
(Ok(t), Some(hash), Some(sender)) => {
|
||||
fail_unless(t.sender() == sender.into(), "sender mismatch");
|
||||
fail_unless(t.hash() == hash.into(), "hash mismatch");
|
||||
}
|
||||
(Err(_), None, None) => {}
|
||||
data => {
|
||||
fail_unless(false, &format!("Validity different: {:?}", data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
start_stop_hook(&name, HookType::OnStop);
|
||||
}
|
||||
start_stop_hook(&name, HookType::OnStop);
|
||||
}
|
||||
|
||||
for f in &failed {
|
||||
println!("FAILED: {:?}", f);
|
||||
}
|
||||
failed
|
||||
for f in &failed {
|
||||
println!("FAILED: {:?}", f);
|
||||
}
|
||||
failed
|
||||
}
|
||||
|
||||
declare_test!{TransactionTests_ttAddress, "TransactionTests/ttAddress"}
|
||||
declare_test!{TransactionTests_ttData, "TransactionTests/ttData"}
|
||||
declare_test!{TransactionTests_ttGasLimit, "TransactionTests/ttGasLimit"}
|
||||
declare_test!{TransactionTests_ttGasPrice, "TransactionTests/ttGasPrice"}
|
||||
declare_test!{TransactionTests_ttNonce, "TransactionTests/ttNonce"}
|
||||
declare_test!{TransactionTests_ttRSValue, "TransactionTests/ttRSValue"}
|
||||
declare_test!{TransactionTests_ttSignature, "TransactionTests/ttSignature"}
|
||||
declare_test!{TransactionTests_ttValue, "TransactionTests/ttValue"}
|
||||
declare_test!{TransactionTests_ttVValue, "TransactionTests/ttVValue"}
|
||||
declare_test!{TransactionTests_ttWrongRLP, "TransactionTests/ttWrongRLP"}
|
||||
declare_test! {TransactionTests_ttAddress, "TransactionTests/ttAddress"}
|
||||
declare_test! {TransactionTests_ttData, "TransactionTests/ttData"}
|
||||
declare_test! {TransactionTests_ttGasLimit, "TransactionTests/ttGasLimit"}
|
||||
declare_test! {TransactionTests_ttGasPrice, "TransactionTests/ttGasPrice"}
|
||||
declare_test! {TransactionTests_ttNonce, "TransactionTests/ttNonce"}
|
||||
declare_test! {TransactionTests_ttRSValue, "TransactionTests/ttRSValue"}
|
||||
declare_test! {TransactionTests_ttSignature, "TransactionTests/ttSignature"}
|
||||
declare_test! {TransactionTests_ttValue, "TransactionTests/ttValue"}
|
||||
declare_test! {TransactionTests_ttVValue, "TransactionTests/ttVValue"}
|
||||
declare_test! {TransactionTests_ttWrongRLP, "TransactionTests/ttWrongRLP"}
|
||||
|
||||
@@ -14,96 +14,102 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use ethjson;
|
||||
use trie::{TrieFactory, TrieSpec};
|
||||
use ethtrie::RlpCodec;
|
||||
use ethereum_types::H256;
|
||||
use ethjson;
|
||||
use ethtrie::RlpCodec;
|
||||
use trie::{TrieFactory, TrieSpec};
|
||||
|
||||
use super::HookType;
|
||||
|
||||
pub use self::generic::run_test_path as run_generic_test_path;
|
||||
pub use self::generic::run_test_file as run_generic_test_file;
|
||||
pub use self::secure::run_test_path as run_secure_test_path;
|
||||
pub use self::secure::run_test_file as run_secure_test_file;
|
||||
pub use self::{
|
||||
generic::{run_test_file as run_generic_test_file, run_test_path as run_generic_test_path},
|
||||
secure::{run_test_file as run_secure_test_file, run_test_path as run_secure_test_path},
|
||||
};
|
||||
|
||||
fn test_trie<H: FnMut(&str, HookType)>(json: &[u8], trie: TrieSpec, start_stop_hook: &mut H) -> Vec<String> {
|
||||
let tests = ethjson::trie::Test::load(json).unwrap();
|
||||
let factory = TrieFactory::<_, RlpCodec>::new(trie);
|
||||
let mut result = vec![];
|
||||
fn test_trie<H: FnMut(&str, HookType)>(
|
||||
json: &[u8],
|
||||
trie: TrieSpec,
|
||||
start_stop_hook: &mut H,
|
||||
) -> Vec<String> {
|
||||
let tests = ethjson::trie::Test::load(json).unwrap();
|
||||
let factory = TrieFactory::<_, RlpCodec>::new(trie);
|
||||
let mut result = vec![];
|
||||
|
||||
for (name, test) in tests.into_iter() {
|
||||
start_stop_hook(&name, HookType::OnStart);
|
||||
for (name, test) in tests.into_iter() {
|
||||
start_stop_hook(&name, HookType::OnStart);
|
||||
|
||||
let mut memdb = journaldb::new_memory_db();
|
||||
let mut root = H256::default();
|
||||
let mut t = factory.create(&mut memdb, &mut root);
|
||||
let mut memdb = journaldb::new_memory_db();
|
||||
let mut root = H256::default();
|
||||
let mut t = factory.create(&mut memdb, &mut root);
|
||||
|
||||
for (key, value) in test.input.data.into_iter() {
|
||||
let key: Vec<u8> = key.into();
|
||||
let value: Vec<u8> = value.map_or_else(Vec::new, Into::into);
|
||||
t.insert(&key, &value)
|
||||
.expect(&format!("Trie test '{:?}' failed due to internal error", name));
|
||||
}
|
||||
for (key, value) in test.input.data.into_iter() {
|
||||
let key: Vec<u8> = key.into();
|
||||
let value: Vec<u8> = value.map_or_else(Vec::new, Into::into);
|
||||
t.insert(&key, &value).expect(&format!(
|
||||
"Trie test '{:?}' failed due to internal error",
|
||||
name
|
||||
));
|
||||
}
|
||||
|
||||
if *t.root() != test.root.into() {
|
||||
result.push(format!("Trie test '{:?}' failed.", name));
|
||||
}
|
||||
if *t.root() != test.root.into() {
|
||||
result.push(format!("Trie test '{:?}' failed.", name));
|
||||
}
|
||||
|
||||
start_stop_hook(&name, HookType::OnStop);
|
||||
}
|
||||
start_stop_hook(&name, HookType::OnStop);
|
||||
}
|
||||
|
||||
for i in &result {
|
||||
println!("FAILED: {}", i);
|
||||
}
|
||||
for i in &result {
|
||||
println!("FAILED: {}", i);
|
||||
}
|
||||
|
||||
result
|
||||
result
|
||||
}
|
||||
|
||||
mod generic {
|
||||
use std::path::Path;
|
||||
use trie::TrieSpec;
|
||||
use std::path::Path;
|
||||
use trie::TrieSpec;
|
||||
|
||||
use super::HookType;
|
||||
use super::HookType;
|
||||
|
||||
/// Run generic trie 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, do_json_test, h)
|
||||
}
|
||||
/// Run generic trie 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, do_json_test, h)
|
||||
}
|
||||
|
||||
/// Run generic trie 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, do_json_test, h)
|
||||
}
|
||||
/// Run generic trie 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, do_json_test, h)
|
||||
}
|
||||
|
||||
fn do_json_test<H: FnMut(&str, HookType)>(json: &[u8], h: &mut H) -> Vec<String> {
|
||||
super::test_trie(json, TrieSpec::Generic, h)
|
||||
}
|
||||
fn do_json_test<H: FnMut(&str, HookType)>(json: &[u8], h: &mut H) -> Vec<String> {
|
||||
super::test_trie(json, TrieSpec::Generic, h)
|
||||
}
|
||||
|
||||
declare_test!{TrieTests_trietest, "TrieTests/trietest"}
|
||||
declare_test!{TrieTests_trieanyorder, "TrieTests/trieanyorder"}
|
||||
declare_test! {TrieTests_trietest, "TrieTests/trietest"}
|
||||
declare_test! {TrieTests_trieanyorder, "TrieTests/trieanyorder"}
|
||||
}
|
||||
|
||||
mod secure {
|
||||
use std::path::Path;
|
||||
use trie::TrieSpec;
|
||||
use std::path::Path;
|
||||
use trie::TrieSpec;
|
||||
|
||||
use super::HookType;
|
||||
use super::HookType;
|
||||
|
||||
/// Run secure trie 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, do_json_test, h)
|
||||
}
|
||||
/// Run secure trie 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, do_json_test, h)
|
||||
}
|
||||
|
||||
/// Run secure trie 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, do_json_test, h)
|
||||
}
|
||||
/// Run secure trie 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, do_json_test, h)
|
||||
}
|
||||
|
||||
fn do_json_test<H: FnMut(&str, HookType)>(json: &[u8], h: &mut H) -> Vec<String> {
|
||||
super::test_trie(json, TrieSpec::Secure, h)
|
||||
}
|
||||
fn do_json_test<H: FnMut(&str, HookType)>(json: &[u8], h: &mut H) -> Vec<String> {
|
||||
super::test_trie(json, TrieSpec::Secure, h)
|
||||
}
|
||||
|
||||
declare_test!{TrieTests_hex_encoded_secure, "TrieTests/hex_encoded_securetrie_test"}
|
||||
declare_test!{TrieTests_trietest_secure, "TrieTests/trietest_secureTrie"}
|
||||
declare_test!{TrieTests_trieanyorder_secure, "TrieTests/trieanyorder_secureTrie"}
|
||||
declare_test! {TrieTests_hex_encoded_secure, "TrieTests/hex_encoded_securetrie_test"}
|
||||
declare_test! {TrieTests_trietest_secure, "TrieTests/trietest_secureTrie"}
|
||||
declare_test! {TrieTests_trieanyorder_secure, "TrieTests/trieanyorder_secureTrie"}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user