[dependencies]: remove util/macros (#11501)
* [dependencies]: remove `util/macros` * fix typo: `flish` -> flush` * [json tests]: add log if `write` or `flush` fails `write` is performed to `stdout` `logging` is performed to `stderr` * [rocksdb-migration]: remove unused `Progress` * [rpc test]: BTreeMap -> `btreemap!`
This commit is contained in:
@@ -25,8 +25,7 @@ use io::IoChannel;
|
||||
use test_helpers::{self, EvmTestClient};
|
||||
use types::verification::Unverified;
|
||||
use verification::{VerifierType, queue::kind::BlockLike};
|
||||
use super::SKIP_TESTS;
|
||||
use super::HookType;
|
||||
use super::{HookType, SKIP_TESTS};
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn skip_test(name: &String) -> bool {
|
||||
@@ -56,7 +55,7 @@ pub fn json_chain_test<H: FnMut(&str, HookType)>(path: &Path, json_data: &[u8],
|
||||
let mut fail_unless = |cond: bool| {
|
||||
if !cond && !fail {
|
||||
failed.push(name.clone());
|
||||
flushln!("FAIL");
|
||||
flushed_writeln!("FAIL");
|
||||
fail = true;
|
||||
true
|
||||
} else {
|
||||
@@ -64,7 +63,7 @@ pub fn json_chain_test<H: FnMut(&str, HookType)>(path: &Path, json_data: &[u8],
|
||||
}
|
||||
};
|
||||
|
||||
flush!(" - {}...", name);
|
||||
flushed_write!(" - {}...", name);
|
||||
|
||||
let spec = {
|
||||
let mut spec = match EvmTestClient::fork_spec_from_json(&blockchain.network) {
|
||||
@@ -123,9 +122,9 @@ pub fn json_chain_test<H: FnMut(&str, HookType)>(path: &Path, json_data: &[u8],
|
||||
}
|
||||
|
||||
if !fail {
|
||||
flushln!("ok");
|
||||
flushed_writeln!("OK");
|
||||
} else {
|
||||
flushln!("fail");
|
||||
flushed_writeln!("FAILED");
|
||||
}
|
||||
|
||||
start_stop_hook(&name, HookType::OnStop);
|
||||
|
||||
@@ -37,8 +37,7 @@ pub fn json_difficulty_test<H: FnMut(&str, HookType)>(
|
||||
for (name, test) in tests.into_iter() {
|
||||
start_stop_hook(&name, HookType::OnStart);
|
||||
|
||||
flush!(" - {}...", name);
|
||||
println!(" - {}...", name);
|
||||
flushed_writeln!(" - {}...", name);
|
||||
|
||||
let mut parent_header = Header::new();
|
||||
let block_number: u64 = test.current_block_number.into();
|
||||
@@ -53,7 +52,7 @@ pub fn json_difficulty_test<H: FnMut(&str, HookType)>(
|
||||
engine.populate_from_parent(&mut header, &parent_header);
|
||||
let expected_difficulty: U256 = test.current_difficulty.into();
|
||||
assert_eq!(header.difficulty(), &expected_difficulty);
|
||||
flushln!("ok");
|
||||
flushed_writeln!("OK");
|
||||
|
||||
start_stop_hook(&name, HookType::OnStop);
|
||||
}
|
||||
|
||||
86
ethcore/src/json_tests/macros.rs
Normal file
86
ethcore/src/json_tests/macros.rs
Normal file
@@ -0,0 +1,86 @@
|
||||
//! Helper macros for running the `JSON tests`
|
||||
|
||||
/// Declares a test:
|
||||
///
|
||||
/// declare_test!(test_name, "path/to/folder/with/tests");
|
||||
///
|
||||
/// Declares a test but skip the named test files inside the folder (no extension):
|
||||
///
|
||||
/// declare_test!(skip => ["a-test-file", "other-test-file"], test_name, "path/to/folder/with/tests");
|
||||
///
|
||||
/// NOTE: a skipped test is considered a passing test as far as `cargo test` is concerned. Normally
|
||||
/// one test corresponds to a folder full of test files, each of which may contain many tests.
|
||||
#[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, []);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
macro_rules! test {
|
||||
($name: expr, $skip: expr) => {
|
||||
$crate::json_tests::test_common::run_test_path(
|
||||
std::path::Path::new(concat!("res/ethereum/tests/", $name)),
|
||||
&$skip,
|
||||
do_json_test,
|
||||
&mut |_, _| ()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Similar to `print!` but flushes stdout in order to ensure the output is emitted immediately.
|
||||
#[macro_export]
|
||||
macro_rules! flushed_write {
|
||||
($arg:expr) => ($crate::json_tests::macros::write_and_flush($arg.into()));
|
||||
($($arg:tt)*) => ($crate::json_tests::macros::write_and_flush(format!("{}", format_args!($($arg)*))));
|
||||
}
|
||||
|
||||
/// Similar to `println!` but flushes stdout in order to ensure the output is emitted immediately.
|
||||
#[macro_export]
|
||||
macro_rules! flushed_writeln {
|
||||
($fmt:expr) => (flushed_write!(concat!($fmt, "\n")));
|
||||
($fmt:expr, $($arg:tt)*) => (flushed_write!(concat!($fmt, "\n"), $($arg)*));
|
||||
}
|
||||
|
||||
/// Write to stdout and flush (ignores errors)
|
||||
#[doc(hidden)]
|
||||
pub fn write_and_flush(s: String) {
|
||||
if let Err(err) = std::io::Write::write_all(&mut std::io::stdout(), s.as_bytes()) {
|
||||
error!(target: "json_tests", "io::Write::write_all to stdout failed because of: {:?}", err);
|
||||
}
|
||||
if let Err(err) = std::io::Write::flush(&mut std::io::stdout()) {
|
||||
error!(target: "json_tests", "io::Write::flush stdout failed because of: {:?}", err);
|
||||
}
|
||||
}
|
||||
@@ -14,23 +14,24 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Helpers and tests for operating on jsontests.
|
||||
//! Helpers and tests for operating on `JSON` tests.
|
||||
|
||||
#[macro_use]
|
||||
mod test_common;
|
||||
mod macros;
|
||||
|
||||
mod transaction;
|
||||
mod executive;
|
||||
mod state;
|
||||
mod chain;
|
||||
mod trie;
|
||||
mod executive;
|
||||
mod skip;
|
||||
mod state;
|
||||
mod test_common;
|
||||
mod transaction;
|
||||
mod trie;
|
||||
|
||||
#[cfg(test)]
|
||||
mod difficulty;
|
||||
|
||||
pub use self::test_common::HookType;
|
||||
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::test_common::HookType;
|
||||
|
||||
use self::skip::SKIP_TESTS;
|
||||
|
||||
@@ -17,13 +17,10 @@
|
||||
use std::path::Path;
|
||||
use super::test_common::*;
|
||||
use pod::PodState;
|
||||
use trace;
|
||||
use ethjson;
|
||||
use test_helpers::{EvmTestClient, EvmTestError, TransactErr, TransactSuccess};
|
||||
use types::transaction::SignedTransaction;
|
||||
use vm::EnvInfo;
|
||||
use super::SKIP_TESTS;
|
||||
use super::HookType;
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn skip_test(subname: &str, chain: &String, number: usize) -> bool {
|
||||
@@ -84,25 +81,25 @@ pub fn json_chain_test<H: FnMut(&str, HookType)>(path: &Path, json_data: &[u8],
|
||||
match result() {
|
||||
Err(err) => {
|
||||
println!("{} !!! Unexpected internal error: {:?}", info, err);
|
||||
flushln!("{} fail", info);
|
||||
flushed_writeln!("{} 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);
|
||||
flushed_writeln!("{} 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);
|
||||
flushed_writeln!("{} fail", info);
|
||||
failed.push(name.clone());
|
||||
},
|
||||
Ok(Err(TransactErr { error, .. })) => {
|
||||
flushln!("{} ok ({:?})", info, error);
|
||||
flushed_writeln!("{} ok ({:?})", info, error);
|
||||
},
|
||||
Ok(_) => {
|
||||
flushln!("{} ok", info);
|
||||
flushed_writeln!("{} ok", info);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ 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};
|
||||
|
||||
/// Indicate when to run the hook passed to test functions.
|
||||
@@ -41,7 +42,7 @@ pub fn run_test_path<H: FnMut(&str, HookType)>(
|
||||
if !skip.is_empty() {
|
||||
// todo[dvdplm] it's really annoying to have to use flushln here. Should be `info!(target:
|
||||
// "json-tests", …)`. Issue https://github.com/paritytech/parity-ethereum/issues/11084
|
||||
flushln!("[run_test_path] Skipping tests in {}: {:?}", path.display(), skip);
|
||||
flushed_writeln!("[run_test_path] Skipping tests in {}: {:?}", path.display(), skip);
|
||||
}
|
||||
let mut errors = Vec::new();
|
||||
run_test_path_inner(path, skip, runner, start_stop_hook, &mut errors);
|
||||
@@ -121,63 +122,3 @@ pub fn run_test_file<H: FnMut(&str, HookType)>(
|
||||
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 |_, _| ()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Declares a test:
|
||||
///
|
||||
/// declare_test!(test_name, "path/to/folder/with/tests");
|
||||
///
|
||||
/// Declares a test but skip the named test files inside the folder (no extension):
|
||||
///
|
||||
/// declare_test!(skip => ["a-test-file", "other-test-file"], test_name, "path/to/folder/with/tests");
|
||||
///
|
||||
/// NOTE: a skipped test is considered a passing test as far as `cargo test` is concerned. Normally
|
||||
/// one test corresponds to a folder full of test files, each of which may contain many tests.
|
||||
#[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, []);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,9 +83,6 @@ extern crate kvdb_rocksdb;
|
||||
#[cfg(feature = "json-tests")]
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
#[cfg(any(test, feature = "json-tests"))]
|
||||
#[macro_use]
|
||||
extern crate macros;
|
||||
#[cfg(any(test, feature = "test-helpers"))]
|
||||
extern crate pod;
|
||||
#[cfg(any(test, feature = "blooms-db"))]
|
||||
|
||||
@@ -38,8 +38,6 @@ use client_traits::{
|
||||
BlockInfo, BlockChainClient, BlockChainReset, ChainInfo,
|
||||
ImportExportBlocks, Tick, ImportBlock
|
||||
};
|
||||
use spec;
|
||||
use stats;
|
||||
use machine::executive::{Executive, TransactOptions};
|
||||
use miner::{Miner, PendingOrdering, MinerService};
|
||||
use account_state::{State, CleanupMode, backend};
|
||||
@@ -51,6 +49,14 @@ use test_helpers::{
|
||||
use rustc_hex::ToHex;
|
||||
use registrar::RegistrarClient;
|
||||
|
||||
fn into_u256_vec<'a, T, I>(iter: I) -> Vec<U256>
|
||||
where
|
||||
I: IntoIterator<Item = &'a T>,
|
||||
T: Into<U256> + Clone + 'a,
|
||||
{
|
||||
iter.into_iter().cloned().map(Into::into).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn imports_from_empty() {
|
||||
let db = test_helpers::new_db();
|
||||
@@ -204,32 +210,32 @@ fn can_collect_garbage() {
|
||||
|
||||
#[test]
|
||||
fn can_generate_gas_price_median() {
|
||||
let client = generate_dummy_client_with_data(3, 1, slice_into![1, 2, 3]);
|
||||
let client = generate_dummy_client_with_data(3, 1, &into_u256_vec(&[1, 2, 3]));
|
||||
assert_eq!(Some(&U256::from(2)), client.gas_price_corpus(3).median());
|
||||
|
||||
let client = generate_dummy_client_with_data(4, 1, slice_into![1, 4, 3, 2]);
|
||||
let client = generate_dummy_client_with_data(4, 1, &into_u256_vec(&[1, 4, 3, 2]));
|
||||
assert_eq!(Some(&U256::from(3)), client.gas_price_corpus(3).median());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_generate_gas_price_histogram() {
|
||||
let client = generate_dummy_client_with_data(20, 1, slice_into![6354,8593,6065,4842,7845,7002,689,4958,4250,6098,5804,4320,643,8895,2296,8589,7145,2000,2512,1408]);
|
||||
let client = generate_dummy_client_with_data(20, 1, &into_u256_vec(&[6354,8593,6065,4842,7845,7002,689,4958,4250,6098,5804,4320,643,8895,2296,8589,7145,2000,2512,1408]));
|
||||
|
||||
let hist = client.gas_price_corpus(20).histogram(5).unwrap();
|
||||
let correct_hist = stats::Histogram { bucket_bounds: vec_into![643, 2294, 3945, 5596, 7247, 8898], counts: vec![4,2,4,6,4] };
|
||||
let correct_hist = stats::Histogram { bucket_bounds: into_u256_vec(&[643, 2294, 3945, 5596, 7247, 8898]), counts: vec![4,2,4,6,4] };
|
||||
assert_eq!(hist, correct_hist);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_gas_price_histogram() {
|
||||
let client = generate_dummy_client_with_data(20, 0, slice_into![]);
|
||||
let client = generate_dummy_client_with_data(20, 0, &[]);
|
||||
|
||||
assert!(client.gas_price_corpus(20).histogram(5).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn corpus_is_sorted() {
|
||||
let client = generate_dummy_client_with_data(2, 1, slice_into![U256::from_str("11426908979").unwrap(), U256::from_str("50426908979").unwrap()]);
|
||||
let client = generate_dummy_client_with_data(2, 1, &[U256::from_str("11426908979").unwrap(), U256::from_str("50426908979").unwrap()]);
|
||||
let corpus = client.gas_price_corpus(20);
|
||||
assert!(corpus[0] < corpus[1]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user