[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:
@@ -36,7 +36,6 @@ kvdb-memorydb = { version = "0.4.0", optional = true }
|
||||
kvdb-rocksdb = { version = "0.5.0", optional = true }
|
||||
lazy_static = { version = "1.3", optional = true }
|
||||
log = "0.4"
|
||||
macros = { path = "../util/macros", optional = true }
|
||||
machine = { path = "./machine" }
|
||||
memory-cache = { path = "../util/memory-cache" }
|
||||
parity-bytes = "0.1"
|
||||
@@ -82,7 +81,6 @@ kvdb-memorydb = "0.4.0"
|
||||
kvdb-rocksdb = "0.5.0"
|
||||
lazy_static = "1.3"
|
||||
machine = { path = "./machine", features = ["test-helpers"] }
|
||||
macros = { path = "../util/macros" }
|
||||
parity-runtime = "0.1.1"
|
||||
serde_json = "1.0"
|
||||
stats = { path = "../util/stats" }
|
||||
@@ -91,7 +89,7 @@ tempdir = "0.3"
|
||||
trie-standardmap = "0.15.0"
|
||||
|
||||
[features]
|
||||
parity = ["work-notify", "price-info", "stratum", "macros"]
|
||||
parity = ["work-notify", "price-info", "stratum"]
|
||||
# Large optional features that are enabled by default for Parity,
|
||||
# but might be omitted for other dependent crates.
|
||||
work-notify = ["ethcore-miner/work-notify"]
|
||||
@@ -127,7 +125,6 @@ test-helpers = [
|
||||
"parity-crypto",
|
||||
"kvdb-memorydb",
|
||||
"kvdb-rocksdb",
|
||||
"macros",
|
||||
"pod",
|
||||
"tempdir",
|
||||
"basic-authority/test-helpers"
|
||||
|
||||
@@ -20,4 +20,4 @@ parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
|
||||
[dev-dependencies]
|
||||
hex-literal = "0.2.1"
|
||||
macros = { path = "../../util/macros" }
|
||||
maplit = "1.0.2"
|
||||
|
||||
@@ -759,18 +759,18 @@ mod tests {
|
||||
PricingAt, AltBn128Pairing as JsonAltBn128PairingPricing, Pricing as JsonPricing,
|
||||
};
|
||||
use hex_literal::hex;
|
||||
use macros::map;
|
||||
use maplit::btreemap;
|
||||
use num::{BigUint, Zero, One};
|
||||
use parity_bytes::BytesRef;
|
||||
use super::{
|
||||
BTreeMap, Builtin, EthereumBuiltin, FromStr, Implementation, Linear,
|
||||
Builtin, EthereumBuiltin, FromStr, Implementation, Linear,
|
||||
ModexpPricer, modexp as me, Pricing
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn blake2f_cost() {
|
||||
let f = Builtin {
|
||||
pricer: map![0 => Pricing::Blake2F(123)],
|
||||
pricer: btreemap![0 => Pricing::Blake2F(123)],
|
||||
native: EthereumBuiltin::from_str("blake2_f").unwrap(),
|
||||
};
|
||||
// 5 rounds
|
||||
@@ -784,7 +784,7 @@ mod tests {
|
||||
#[test]
|
||||
fn blake2f_cost_on_invalid_length() {
|
||||
let f = Builtin {
|
||||
pricer: map![0 => Pricing::Blake2F(123)],
|
||||
pricer: btreemap![0 => Pricing::Blake2F(123)],
|
||||
native: EthereumBuiltin::from_str("blake2_f").expect("known builtin"),
|
||||
};
|
||||
// invalid input (too short)
|
||||
@@ -1031,7 +1031,7 @@ mod tests {
|
||||
#[test]
|
||||
fn modexp() {
|
||||
let f = Builtin {
|
||||
pricer: map![0 => Pricing::Modexp(ModexpPricer { divisor: 20 })],
|
||||
pricer: btreemap![0 => Pricing::Modexp(ModexpPricer { divisor: 20 })],
|
||||
native: EthereumBuiltin::from_str("modexp").unwrap(),
|
||||
};
|
||||
|
||||
@@ -1141,7 +1141,7 @@ mod tests {
|
||||
fn bn128_add() {
|
||||
|
||||
let f = Builtin {
|
||||
pricer: map![0 => Pricing::Linear(Linear { base: 0, word: 0 })],
|
||||
pricer: btreemap![0 => Pricing::Linear(Linear { base: 0, word: 0 })],
|
||||
native: EthereumBuiltin::from_str("alt_bn128_add").unwrap(),
|
||||
};
|
||||
|
||||
@@ -1199,7 +1199,7 @@ mod tests {
|
||||
fn bn128_mul() {
|
||||
|
||||
let f = Builtin {
|
||||
pricer: map![0 => Pricing::Linear(Linear { base: 0, word: 0 })],
|
||||
pricer: btreemap![0 => Pricing::Linear(Linear { base: 0, word: 0 })],
|
||||
native: EthereumBuiltin::from_str("alt_bn128_mul").unwrap(),
|
||||
};
|
||||
|
||||
@@ -1238,7 +1238,7 @@ mod tests {
|
||||
|
||||
fn builtin_pairing() -> Builtin {
|
||||
Builtin {
|
||||
pricer: map![0 => Pricing::Linear(Linear { base: 0, word: 0 })],
|
||||
pricer: btreemap![0 => Pricing::Linear(Linear { base: 0, word: 0 })],
|
||||
native: EthereumBuiltin::from_str("alt_bn128_pairing").unwrap(),
|
||||
}
|
||||
}
|
||||
@@ -1317,7 +1317,7 @@ mod tests {
|
||||
fn is_active() {
|
||||
let pricer = Pricing::Linear(Linear { base: 10, word: 20 });
|
||||
let b = Builtin {
|
||||
pricer: map![100_000 => pricer],
|
||||
pricer: btreemap![100_000 => pricer],
|
||||
native: EthereumBuiltin::from_str("identity").unwrap(),
|
||||
};
|
||||
|
||||
@@ -1330,7 +1330,7 @@ mod tests {
|
||||
fn from_named_linear() {
|
||||
let pricer = Pricing::Linear(Linear { base: 10, word: 20 });
|
||||
let b = Builtin {
|
||||
pricer: map![0 => pricer],
|
||||
pricer: btreemap![0 => pricer],
|
||||
native: EthereumBuiltin::from_str("identity").unwrap(),
|
||||
};
|
||||
|
||||
@@ -1349,7 +1349,7 @@ mod tests {
|
||||
fn from_json() {
|
||||
let b = Builtin::try_from(ethjson::spec::Builtin {
|
||||
name: "identity".to_owned(),
|
||||
pricing: map![
|
||||
pricing: btreemap![
|
||||
0 => PricingAt {
|
||||
info: None,
|
||||
price: JsonPricing::Linear(JsonLinearPricing { base: 10, word: 20 })
|
||||
@@ -1372,7 +1372,7 @@ mod tests {
|
||||
fn bn128_pairing_eip1108_transition() {
|
||||
let b = Builtin::try_from(JsonBuiltin {
|
||||
name: "alt_bn128_pairing".to_owned(),
|
||||
pricing: map![
|
||||
pricing: btreemap![
|
||||
10 => PricingAt {
|
||||
info: None,
|
||||
price: JsonPricing::AltBn128Pairing(JsonAltBn128PairingPricing {
|
||||
@@ -1398,7 +1398,7 @@ mod tests {
|
||||
fn bn128_add_eip1108_transition() {
|
||||
let b = Builtin::try_from(JsonBuiltin {
|
||||
name: "alt_bn128_add".to_owned(),
|
||||
pricing: map![
|
||||
pricing: btreemap![
|
||||
10 => PricingAt {
|
||||
info: None,
|
||||
price: JsonPricing::Linear(JsonLinearPricing {
|
||||
@@ -1424,7 +1424,7 @@ mod tests {
|
||||
fn bn128_mul_eip1108_transition() {
|
||||
let b = Builtin::try_from(JsonBuiltin {
|
||||
name: "alt_bn128_mul".to_owned(),
|
||||
pricing: map![
|
||||
pricing: btreemap![
|
||||
10 => PricingAt {
|
||||
info: None,
|
||||
price: JsonPricing::Linear(JsonLinearPricing {
|
||||
@@ -1451,7 +1451,7 @@ mod tests {
|
||||
fn multimap_use_most_recent_on_activate() {
|
||||
let b = Builtin::try_from(JsonBuiltin {
|
||||
name: "alt_bn128_mul".to_owned(),
|
||||
pricing: map![
|
||||
pricing: btreemap![
|
||||
10 => PricingAt {
|
||||
info: None,
|
||||
price: JsonPricing::Linear(JsonLinearPricing {
|
||||
@@ -1489,7 +1489,7 @@ mod tests {
|
||||
fn multimap_use_last_with_same_activate_at() {
|
||||
let b = Builtin::try_from(JsonBuiltin {
|
||||
name: "alt_bn128_mul".to_owned(),
|
||||
pricing: map![
|
||||
pricing: btreemap![
|
||||
1 => PricingAt {
|
||||
info: None,
|
||||
price: JsonPricing::Linear(JsonLinearPricing {
|
||||
|
||||
@@ -26,7 +26,6 @@ lazy_static = "1.3.0"
|
||||
log = "0.4"
|
||||
lru-cache = "0.1"
|
||||
machine = { path = "../../machine" }
|
||||
macros = { path = "../../../util/macros" }
|
||||
parity-bytes = "0.1"
|
||||
parking_lot = "0.10.0"
|
||||
rand = "0.7"
|
||||
|
||||
@@ -44,12 +44,10 @@ use client_traits::{EngineClient, ForceUpdateSealing, TransactionRequest};
|
||||
use engine::{Engine, ConstructedVerifier};
|
||||
use block_gas_limit::block_gas_limit;
|
||||
use block_reward::{self, BlockRewardContract, RewardKind};
|
||||
use ethjson;
|
||||
use machine::{
|
||||
ExecutedBlock,
|
||||
Machine,
|
||||
};
|
||||
use macros::map;
|
||||
use keccak_hash::keccak;
|
||||
use log::{info, debug, error, trace, warn};
|
||||
use lru_cache::LruCache;
|
||||
@@ -1277,22 +1275,20 @@ impl Engine for AuthorityRound {
|
||||
.map(ToString::to_string)
|
||||
.unwrap_or_default();
|
||||
|
||||
let mut info = map![
|
||||
"step".into() => step,
|
||||
"signature".into() => signature
|
||||
];
|
||||
let mut info = BTreeMap::new();
|
||||
info.insert("step".into(), step);
|
||||
info.insert("signature".into(), signature);
|
||||
|
||||
if header.number() >= self.empty_steps_transition {
|
||||
let empty_steps =
|
||||
if let Ok(empty_steps) = header_empty_steps(header).as_ref() {
|
||||
format!("[{}]",
|
||||
empty_steps.iter().fold(
|
||||
"".to_string(),
|
||||
|acc, e| if acc.len() > 0 { acc + ","} else { acc } + &e.to_string()))
|
||||
|
||||
} else {
|
||||
"".into()
|
||||
};
|
||||
let empty_steps = header_empty_steps(header).as_ref().map_or(String::new(), |empty_steps| {
|
||||
format!("[{}]", empty_steps.iter().fold(String::new(), |mut acc, e| {
|
||||
if !acc.is_empty() {
|
||||
acc.push(',');
|
||||
}
|
||||
acc.push_str(&e.to_string());
|
||||
acc
|
||||
}))
|
||||
});
|
||||
|
||||
info.insert("emptySteps".into(), empty_steps);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ lazy_static = "1.3.0"
|
||||
log = "0.4"
|
||||
lru-cache = "0.1"
|
||||
machine = { path = "../../machine" }
|
||||
macros = { path = "../../../util/macros" }
|
||||
rand = "0.7"
|
||||
parking_lot = "0.10.0"
|
||||
rlp = "0.4.0"
|
||||
|
||||
@@ -80,7 +80,6 @@ use machine::{
|
||||
ExecutedBlock,
|
||||
Machine,
|
||||
};
|
||||
use macros::map;
|
||||
use parking_lot::RwLock;
|
||||
use rand::Rng;
|
||||
use unexpected::{Mismatch, OutOfBounds};
|
||||
@@ -379,13 +378,12 @@ impl Engine for Clique {
|
||||
|
||||
fn extra_info(&self, header: &Header) -> BTreeMap<String, String> {
|
||||
// clique engine seal fields are the same as ethash seal fields
|
||||
match EthashSeal::parse_seal(header.seal()) {
|
||||
Ok(seal) => map![
|
||||
"nonce".to_owned() => format!("{:#x}", seal.nonce),
|
||||
"mixHash".to_owned() => format!("{:#x}", seal.mix_hash)
|
||||
],
|
||||
_ => BTreeMap::default()
|
||||
let mut engine_info = BTreeMap::new();
|
||||
if let Ok(seal) = EthashSeal::parse_seal(header.seal()) {
|
||||
engine_info.insert("nonce".to_string(), format!("{:#x}", seal.nonce));
|
||||
engine_info.insert("mixHash".to_string(), format!("{:#x}", seal.mix_hash));
|
||||
}
|
||||
engine_info
|
||||
}
|
||||
|
||||
fn maximum_uncle_count(&self, _block: BlockNumber) -> usize { 0 }
|
||||
|
||||
@@ -16,7 +16,6 @@ ethjson = { path = "../../../json" }
|
||||
keccak-hash = "0.4.0"
|
||||
log = "0.4.8"
|
||||
machine = { path = "../../machine" }
|
||||
macros = { path = "../../../util/macros" }
|
||||
unexpected = { path = "../../../util/unexpected" }
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -33,11 +33,9 @@ use common_types::{
|
||||
};
|
||||
use engine::Engine;
|
||||
use ethereum_types::{H256, U256};
|
||||
use ethjson;
|
||||
use ethash::{self, quick_get_difficulty, slow_hash_block_number, EthashManager};
|
||||
use keccak_hash::{KECCAK_EMPTY_LIST_RLP};
|
||||
use keccak_hash::KECCAK_EMPTY_LIST_RLP;
|
||||
use log::trace;
|
||||
use macros::map;
|
||||
use machine::{
|
||||
ExecutedBlock,
|
||||
Machine,
|
||||
@@ -232,18 +230,17 @@ impl Engine for Ethash {
|
||||
|
||||
/// Additional engine-specific information for the user/developer concerning `header`.
|
||||
fn extra_info(&self, header: &Header) -> BTreeMap<String, String> {
|
||||
match EthashSeal::parse_seal(header.seal()) {
|
||||
Ok(seal) => map![
|
||||
"nonce".to_owned() => format!("0x{:x}", seal.nonce),
|
||||
"mixHash".to_owned() => format!("0x{:x}", seal.mix_hash)
|
||||
],
|
||||
_ => BTreeMap::default()
|
||||
let mut engine_info = BTreeMap::new();
|
||||
if let Ok(seal) = EthashSeal::parse_seal(header.seal()) {
|
||||
engine_info.insert("nonce".to_string(), format!("{:#x}", seal.nonce));
|
||||
engine_info.insert("mixHash".to_string(), format!("{:#x}", seal.mix_hash));
|
||||
}
|
||||
engine_info
|
||||
}
|
||||
|
||||
fn maximum_uncle_count(&self, _block: BlockNumber) -> usize { 2 }
|
||||
|
||||
fn maximum_gas_limit(&self) -> Option<U256> { Some(0x7fff_ffff_ffff_ffffu64.into()) }
|
||||
fn maximum_gas_limit(&self) -> Option<U256> { Some(0x7fff_ffff_ffff_ffff_u64.into()) }
|
||||
|
||||
/// Apply the block reward on finalisation of the block.
|
||||
/// This assumes that all uncles are valid uncles (i.e. of at least one generation before the current).
|
||||
|
||||
@@ -44,7 +44,6 @@ ethcore = { path = "../", features = ["test-helpers"] }
|
||||
ethcore-io = { path = "../../util/io" }
|
||||
ethjson = { path = "../../json" }
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
macros = { path = "../../util/macros" }
|
||||
rustc-hex = "1.0"
|
||||
spec = { path = "../spec" }
|
||||
tempdir = "0.3"
|
||||
|
||||
@@ -1233,7 +1233,6 @@ mod tests {
|
||||
};
|
||||
use parity_crypto::publickey::{Generator, Random};
|
||||
use evm::{Factory, evm_test, evm_test_ignore};
|
||||
use macros::vec_into;
|
||||
use vm::{ActionParams, ActionValue, EnvInfo, CreateContractAddress};
|
||||
use ::trace::{
|
||||
trace,
|
||||
@@ -1551,28 +1550,28 @@ mod tests {
|
||||
parent_step: 0,
|
||||
code: vec![124, 96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85, 96, 0, 82, 96, 29, 96, 3, 96, 23, 240, 96, 0, 85],
|
||||
operations: vec![
|
||||
VMOperation { pc: 0, instruction: 124, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 99997.into(), stack_push: vec_into![U256::from_dec_str("2589892687202724018173567190521546555304938078595079151649957320078677").unwrap()], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 30, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 99994.into(), stack_push: vec_into![0], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 32, instruction: 82, gas_cost: 6.into(), executed: Some(VMExecutedOperation { gas_used: 99988.into(), stack_push: vec_into![], mem_diff: Some(MemoryDiff { offset: 0, data: vec![0, 0, 0, 96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85] }), store_diff: None }) },
|
||||
VMOperation { pc: 33, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 99985.into(), stack_push: vec_into![29], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 35, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 99982.into(), stack_push: vec_into![3], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 37, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 99979.into(), stack_push: vec_into![23], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 39, instruction: 240, gas_cost: 99979.into(), executed: Some(VMExecutedOperation { gas_used: 64755.into(), stack_push: vec_into![U256::from_dec_str("1135198453258042933984631383966629874710669425204").unwrap()], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 40, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 64752.into(), stack_push: vec_into![0], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 42, instruction: 85, gas_cost: 20000.into(), executed: Some(VMExecutedOperation { gas_used: 44752.into(), stack_push: vec_into![], mem_diff: None, store_diff: Some(StorageDiff { location: 0.into(), value: U256::from_dec_str("1135198453258042933984631383966629874710669425204").unwrap() }) }) }
|
||||
VMOperation { pc: 0, instruction: 124, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 99997.into(), stack_push: vec![U256::from_dec_str("2589892687202724018173567190521546555304938078595079151649957320078677").unwrap()], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 30, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 99994.into(), stack_push: vec![U256::from(0)], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 32, instruction: 82, gas_cost: 6.into(), executed: Some(VMExecutedOperation { gas_used: 99988.into(), stack_push: vec![], mem_diff: Some(MemoryDiff { offset: 0, data: vec![0, 0, 0, 96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85] }), store_diff: None }) },
|
||||
VMOperation { pc: 33, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 99985.into(), stack_push: vec![U256::from(29)], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 35, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 99982.into(), stack_push: vec![U256::from(3)], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 37, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 99979.into(), stack_push: vec![U256::from(23)], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 39, instruction: 240, gas_cost: 99979.into(), executed: Some(VMExecutedOperation { gas_used: 64755.into(), stack_push: vec![U256::from_dec_str("1135198453258042933984631383966629874710669425204").unwrap()], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 40, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 64752.into(), stack_push: vec![U256::from(0)], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 42, instruction: 85, gas_cost: 20000.into(), executed: Some(VMExecutedOperation { gas_used: 44752.into(), stack_push: vec![], mem_diff: None, store_diff: Some(StorageDiff { location: 0.into(), value: U256::from_dec_str("1135198453258042933984631383966629874710669425204").unwrap() }) }) }
|
||||
],
|
||||
subs: vec![
|
||||
VMTrace {
|
||||
parent_step: 6,
|
||||
code: vec![96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85],
|
||||
operations: vec![
|
||||
VMOperation { pc: 0, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 67976.into(), stack_push: vec_into![16], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 2, instruction: 128, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 67973.into(), stack_push: vec_into![16, 16], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 3, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 67970.into(), stack_push: vec_into![12], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 5, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 67967.into(), stack_push: vec_into![0], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 7, instruction: 57, gas_cost: 9.into(), executed: Some(VMExecutedOperation { gas_used: 67958.into(), stack_push: vec_into![], mem_diff: Some(MemoryDiff { offset: 0, data: vec![96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53] }), store_diff: None }) },
|
||||
VMOperation { pc: 8, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 67955.into(), stack_push: vec_into![0], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 10, instruction: 243, gas_cost: 0.into(), executed: Some(VMExecutedOperation { gas_used: 67955.into(), stack_push: vec_into![], mem_diff: None, store_diff: None }) }
|
||||
VMOperation { pc: 0, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 67976.into(), stack_push: vec![U256::from(16)], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 2, instruction: 128, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 67973.into(), stack_push: vec![U256::from(16); 2], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 3, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 67970.into(), stack_push: vec![U256::from(12)], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 5, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 67967.into(), stack_push: vec![U256::from(0)], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 7, instruction: 57, gas_cost: 9.into(), executed: Some(VMExecutedOperation { gas_used: 67958.into(), stack_push: vec![], mem_diff: Some(MemoryDiff { offset: 0, data: vec![96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53] }), store_diff: None }) },
|
||||
VMOperation { pc: 8, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 67955.into(), stack_push: vec![U256::from(0)], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 10, instruction: 243, gas_cost: 0.into(), executed: Some(VMExecutedOperation { gas_used: 67955.into(), stack_push: vec![], mem_diff: None, store_diff: None }) }
|
||||
],
|
||||
subs: vec![]
|
||||
}
|
||||
@@ -1726,13 +1725,13 @@ mod tests {
|
||||
parent_step: 0,
|
||||
code: vec![96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85],
|
||||
operations: vec![
|
||||
VMOperation { pc: 0, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 99997.into(), stack_push: vec_into![16], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 2, instruction: 128, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 99994.into(), stack_push: vec_into![16, 16], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 3, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 99991.into(), stack_push: vec_into![12], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 5, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 99988.into(), stack_push: vec_into![0], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 7, instruction: 57, gas_cost: 9.into(), executed: Some(VMExecutedOperation { gas_used: 99979.into(), stack_push: vec_into![], mem_diff: Some(MemoryDiff { offset: 0, data: vec![96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53] }), store_diff: None }) },
|
||||
VMOperation { pc: 8, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 99976.into(), stack_push: vec_into![0], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 10, instruction: 243, gas_cost: 0.into(), executed: Some(VMExecutedOperation { gas_used: 99976.into(), stack_push: vec_into![], mem_diff: None, store_diff: None }) }
|
||||
VMOperation { pc: 0, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 99997.into(), stack_push: vec![U256::from(16)], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 2, instruction: 128, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 99994.into(), stack_push: vec![U256::from(16); 2], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 3, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 99991.into(), stack_push: vec![U256::from(12)], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 5, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 99988.into(), stack_push: vec![U256::from(0)], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 7, instruction: 57, gas_cost: 9.into(), executed: Some(VMExecutedOperation { gas_used: 99979.into(), stack_push: vec![], mem_diff: Some(MemoryDiff { offset: 0, data: vec![96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53] }), store_diff: None }) },
|
||||
VMOperation { pc: 8, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 99976.into(), stack_push: vec![U256::from(0)], mem_diff: None, store_diff: None }) },
|
||||
VMOperation { pc: 10, instruction: 243, gas_cost: 0.into(), executed: Some(VMExecutedOperation { gas_used: 99976.into(), stack_push: vec![], mem_diff: None, store_diff: None }) }
|
||||
],
|
||||
subs: vec![]
|
||||
};
|
||||
|
||||
@@ -25,4 +25,4 @@ trie-db = "0.20.0"
|
||||
triehash = { package = "triehash-ethereum", version = "0.2", path = "../../util/triehash-ethereum" }
|
||||
|
||||
[dev-dependencies]
|
||||
macros = { path = "../../util/macros" }
|
||||
maplit = "1.0.2"
|
||||
|
||||
@@ -27,7 +27,6 @@ use triehash::sec_trie_root;
|
||||
use parity_bytes::Bytes;
|
||||
use trie_db::TrieFactory;
|
||||
use ethtrie::Layout;
|
||||
use ethjson;
|
||||
use common_types::account_diff::*;
|
||||
use rlp::{self, RlpStream};
|
||||
use serde::{Serializer, Serialize};
|
||||
@@ -146,55 +145,54 @@ pub fn diff_pod(pre: Option<&PodAccount>, post: Option<&PodAccount>) -> Option<A
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::collections::BTreeMap;
|
||||
use common_types::account_diff::*;
|
||||
use super::{PodAccount, diff_pod};
|
||||
use ethereum_types::H256;
|
||||
use macros::map;
|
||||
use maplit::btreemap;
|
||||
|
||||
#[test]
|
||||
fn existence() {
|
||||
let a = PodAccount {
|
||||
balance: 69.into(), nonce: 0.into(), code: Some(vec![]), storage: map![], version: 0.into(),
|
||||
balance: 69.into(), nonce: 0.into(), code: Some(vec![]), storage: btreemap![], version: 0.into(),
|
||||
};
|
||||
assert_eq!(diff_pod(Some(&a), Some(&a)), None);
|
||||
assert_eq!(diff_pod(None, Some(&a)), Some(AccountDiff{
|
||||
balance: Diff::Born(69.into()),
|
||||
nonce: Diff::Born(0.into()),
|
||||
code: Diff::Born(vec![]),
|
||||
storage: map![],
|
||||
storage: btreemap![],
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn basic() {
|
||||
let a = PodAccount {
|
||||
balance: 69.into(), nonce: 0.into(), code: Some(vec![]), storage: map![], version: 0.into(),
|
||||
balance: 69.into(), nonce: 0.into(), code: Some(vec![]), storage: btreemap![], version: 0.into(),
|
||||
};
|
||||
let b = PodAccount {
|
||||
balance: 42.into(), nonce: 1.into(), code: Some(vec![]), storage: map![], version: 0.into(),
|
||||
balance: 42.into(), nonce: 1.into(), code: Some(vec![]), storage: btreemap![], version: 0.into(),
|
||||
};
|
||||
assert_eq!(diff_pod(Some(&a), Some(&b)), Some(AccountDiff {
|
||||
balance: Diff::Changed(69.into(), 42.into()),
|
||||
nonce: Diff::Changed(0.into(), 1.into()),
|
||||
code: Diff::Same,
|
||||
storage: map![],
|
||||
storage: btreemap![],
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn code() {
|
||||
let a = PodAccount {
|
||||
balance: 0.into(), nonce: 0.into(), code: Some(vec![]), storage: map![], version: 0.into(),
|
||||
balance: 0.into(), nonce: 0.into(), code: Some(vec![]), storage: btreemap![], version: 0.into(),
|
||||
};
|
||||
let b = PodAccount {
|
||||
balance: 0.into(), nonce: 1.into(), code: Some(vec![0]), storage: map![], version: 0.into(),
|
||||
balance: 0.into(), nonce: 1.into(), code: Some(vec![0]), storage: btreemap![], version: 0.into(),
|
||||
};
|
||||
assert_eq!(diff_pod(Some(&a), Some(&b)), Some(AccountDiff {
|
||||
balance: Diff::Same,
|
||||
nonce: Diff::Changed(0.into(), 1.into()),
|
||||
code: Diff::Changed(vec![], vec![0]),
|
||||
storage: map![],
|
||||
storage: btreemap![],
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -204,7 +202,7 @@ mod test {
|
||||
balance: 0.into(),
|
||||
nonce: 0.into(),
|
||||
code: Some(vec![]),
|
||||
storage: map![
|
||||
storage: btreemap![
|
||||
H256::from_low_u64_be(1) => H256::from_low_u64_be(1),
|
||||
H256::from_low_u64_be(2) => H256::from_low_u64_be(2),
|
||||
H256::from_low_u64_be(3) => H256::from_low_u64_be(3),
|
||||
@@ -219,7 +217,7 @@ mod test {
|
||||
balance: 0.into(),
|
||||
nonce: 0.into(),
|
||||
code: Some(vec![]),
|
||||
storage: map![
|
||||
storage: btreemap![
|
||||
H256::from_low_u64_be(1) => H256::from_low_u64_be(1),
|
||||
H256::from_low_u64_be(2) => H256::from_low_u64_be(3),
|
||||
H256::from_low_u64_be(3) => H256::from_low_u64_be(0),
|
||||
@@ -234,7 +232,7 @@ mod test {
|
||||
balance: Diff::Same,
|
||||
nonce: Diff::Same,
|
||||
code: Diff::Same,
|
||||
storage: map![
|
||||
storage: btreemap![
|
||||
H256::from_low_u64_be(2) => Diff::new(H256::from_low_u64_be(2), H256::from_low_u64_be(3)),
|
||||
H256::from_low_u64_be(3) => Diff::new(H256::from_low_u64_be(3), H256::from_low_u64_be(0)),
|
||||
H256::from_low_u64_be(4) => Diff::new(H256::from_low_u64_be(4), H256::from_low_u64_be(0)),
|
||||
|
||||
@@ -20,7 +20,6 @@ use std::collections::BTreeMap;
|
||||
use ethereum_types::{H256, Address};
|
||||
use triehash::sec_trie_root;
|
||||
use common_types::state_diff::StateDiff;
|
||||
use ethjson;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::account::PodAccount;
|
||||
@@ -74,7 +73,6 @@ pub fn diff_pod(pre: &PodState, post: &PodState) -> StateDiff {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::collections::BTreeMap;
|
||||
use common_types::{
|
||||
account_diff::{AccountDiff, Diff},
|
||||
state_diff::StateDiff,
|
||||
@@ -82,122 +80,122 @@ mod test {
|
||||
use ethereum_types::Address;
|
||||
use crate::account::PodAccount;
|
||||
use super::PodState;
|
||||
use macros::map;
|
||||
use maplit::btreemap;
|
||||
|
||||
#[test]
|
||||
fn create_delete() {
|
||||
let a = PodState::from(map![
|
||||
let a = PodState::from(btreemap![
|
||||
Address::from_low_u64_be(1) => PodAccount {
|
||||
balance: 69.into(),
|
||||
nonce: 0.into(),
|
||||
code: Some(Vec::new()),
|
||||
storage: map![],
|
||||
storage: btreemap![],
|
||||
version: 0.into(),
|
||||
}
|
||||
]);
|
||||
assert_eq!(super::diff_pod(&a, &PodState::default()), StateDiff { raw: map![
|
||||
assert_eq!(super::diff_pod(&a, &PodState::default()), StateDiff { raw: btreemap![
|
||||
Address::from_low_u64_be(1) => AccountDiff{
|
||||
balance: Diff::Died(69.into()),
|
||||
nonce: Diff::Died(0.into()),
|
||||
code: Diff::Died(vec![]),
|
||||
storage: map![],
|
||||
storage: btreemap![],
|
||||
}
|
||||
]});
|
||||
assert_eq!(super::diff_pod(&PodState::default(), &a), StateDiff { raw: map![
|
||||
assert_eq!(super::diff_pod(&PodState::default(), &a), StateDiff { raw: btreemap![
|
||||
Address::from_low_u64_be(1) => AccountDiff{
|
||||
balance: Diff::Born(69.into()),
|
||||
nonce: Diff::Born(0.into()),
|
||||
code: Diff::Born(vec![]),
|
||||
storage: map![],
|
||||
storage: btreemap![],
|
||||
}
|
||||
]});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_delete_with_unchanged() {
|
||||
let a = PodState::from(map![
|
||||
let a = PodState::from(btreemap![
|
||||
Address::from_low_u64_be(1) => PodAccount {
|
||||
balance: 69.into(),
|
||||
nonce: 0.into(),
|
||||
code: Some(Vec::new()),
|
||||
storage: map![],
|
||||
storage: btreemap![],
|
||||
version: 0.into(),
|
||||
}
|
||||
]);
|
||||
let b = PodState::from(map![
|
||||
let b = PodState::from(btreemap![
|
||||
Address::from_low_u64_be(1) => PodAccount {
|
||||
balance: 69.into(),
|
||||
nonce: 0.into(),
|
||||
code: Some(Vec::new()),
|
||||
storage: map![],
|
||||
storage: btreemap![],
|
||||
version: 0.into(),
|
||||
},
|
||||
Address::from_low_u64_be(2) => PodAccount {
|
||||
balance: 69.into(),
|
||||
nonce: 0.into(),
|
||||
code: Some(Vec::new()),
|
||||
storage: map![],
|
||||
storage: btreemap![],
|
||||
version: 0.into(),
|
||||
}
|
||||
]);
|
||||
assert_eq!(super::diff_pod(&a, &b), StateDiff { raw: map![
|
||||
assert_eq!(super::diff_pod(&a, &b), StateDiff { raw: btreemap![
|
||||
Address::from_low_u64_be(2) => AccountDiff {
|
||||
balance: Diff::Born(69.into()),
|
||||
nonce: Diff::Born(0.into()),
|
||||
code: Diff::Born(vec![]),
|
||||
storage: map![],
|
||||
storage: btreemap![],
|
||||
}
|
||||
]});
|
||||
assert_eq!(super::diff_pod(&b, &a), StateDiff { raw: map![
|
||||
assert_eq!(super::diff_pod(&b, &a), StateDiff { raw: btreemap![
|
||||
Address::from_low_u64_be(2) => AccountDiff {
|
||||
balance: Diff::Died(69.into()),
|
||||
nonce: Diff::Died(0.into()),
|
||||
code: Diff::Died(vec![]),
|
||||
storage: map![],
|
||||
storage: btreemap![],
|
||||
}
|
||||
]});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn change_with_unchanged() {
|
||||
let a = PodState::from(map![
|
||||
let a = PodState::from(btreemap![
|
||||
Address::from_low_u64_be(1) => PodAccount {
|
||||
balance: 69.into(),
|
||||
nonce: 0.into(),
|
||||
code: Some(Vec::new()),
|
||||
storage: map![],
|
||||
storage: btreemap![],
|
||||
version: 0.into(),
|
||||
},
|
||||
Address::from_low_u64_be(2) => PodAccount {
|
||||
balance: 69.into(),
|
||||
nonce: 0.into(),
|
||||
code: Some(Vec::new()),
|
||||
storage: map![],
|
||||
storage: btreemap![],
|
||||
version: 0.into(),
|
||||
}
|
||||
]);
|
||||
let b = PodState::from(map![
|
||||
let b = PodState::from(btreemap![
|
||||
Address::from_low_u64_be(1) => PodAccount {
|
||||
balance: 69.into(),
|
||||
nonce: 1.into(),
|
||||
code: Some(Vec::new()),
|
||||
storage: map![],
|
||||
storage: btreemap![],
|
||||
version: 0.into(),
|
||||
},
|
||||
Address::from_low_u64_be(2) => PodAccount {
|
||||
balance: 69.into(),
|
||||
nonce: 0.into(),
|
||||
code: Some(Vec::new()),
|
||||
storage: map![],
|
||||
storage: btreemap![],
|
||||
version: 0.into(),
|
||||
}
|
||||
]);
|
||||
assert_eq!(super::diff_pod(&a, &b), StateDiff { raw: map![
|
||||
assert_eq!(super::diff_pod(&a, &b), StateDiff { raw: btreemap![
|
||||
Address::from_low_u64_be(1) => AccountDiff {
|
||||
balance: Diff::Same,
|
||||
nonce: Diff::Changed(0.into(), 1.into()),
|
||||
code: Diff::Same,
|
||||
storage: map![],
|
||||
storage: btreemap![],
|
||||
}
|
||||
]});
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ indexmap = "1.3.0"
|
||||
keccak-hash = "0.4.0"
|
||||
light = { package = "ethcore-light", path = "../light" }
|
||||
log = "0.4"
|
||||
macros = { path = "../../util/macros" }
|
||||
network = { package = "ethcore-network", path = "../../util/network" }
|
||||
parity-runtime = "0.1.1"
|
||||
parity-crypto = { version = "0.5.0", features = ["publickey"] }
|
||||
|
||||
@@ -49,7 +49,6 @@ use light::net::{
|
||||
Capabilities, Handler as LightHandler, EventContext, SampleStore,
|
||||
};
|
||||
use log::{trace, warn};
|
||||
use macros::hash_map;
|
||||
use network::{
|
||||
client_version::ClientVersion,
|
||||
NetworkProtocolHandler, NetworkContext, PeerId, ProtocolId,
|
||||
@@ -795,7 +794,11 @@ impl NetworkConfiguration {
|
||||
max_peers: self.max_peers,
|
||||
min_peers: self.min_peers,
|
||||
max_handshakes: self.max_pending_peers,
|
||||
reserved_protocols: hash_map![WARP_SYNC_PROTOCOL_ID => self.snapshot_peers],
|
||||
reserved_protocols: {
|
||||
let mut reserved = HashMap::new();
|
||||
reserved.insert(WARP_SYNC_PROTOCOL_ID, self.snapshot_peers);
|
||||
reserved
|
||||
},
|
||||
reserved_nodes: self.reserved_nodes,
|
||||
ip_filter: self.ip_filter,
|
||||
non_reserved_mode: if self.allow_non_reserved { NonReservedPeerMode::Accept } else { NonReservedPeerMode::Deny },
|
||||
|
||||
@@ -93,7 +93,6 @@ impl TransactionsStats {
|
||||
mod tests {
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use super::{Stats, TransactionsStats, NodeId, H256};
|
||||
use macros::hash_map;
|
||||
|
||||
#[test]
|
||||
fn should_keep_track_of_propagations() {
|
||||
@@ -112,10 +111,12 @@ mod tests {
|
||||
let stats = stats.get(&hash);
|
||||
assert_eq!(stats, Some(&Stats {
|
||||
first_seen: 5,
|
||||
propagated_to: hash_map![
|
||||
enodeid1 => 2,
|
||||
enodeid2 => 1
|
||||
],
|
||||
propagated_to: {
|
||||
let mut map = HashMap::new();
|
||||
map.insert(enodeid1, 2);
|
||||
map.insert(enodeid2, 1);
|
||||
map
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user