Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 1c68b36

Browse files
committed
Handle missing r, s, v params in json tests
Light cleanup of json test runner
1 parent 3d3b666 commit 1c68b36

File tree

7 files changed

+78
-24
lines changed

7 files changed

+78
-24
lines changed

ethcore/account-state/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ impl<B: Backend> State<B> {
746746
/// Propagate local cache into shared canonical state cache.
747747
fn propagate_to_global_cache(&mut self) {
748748
let mut addresses = self.cache.borrow_mut();
749-
trace!("Committing cache {:?} entries", addresses.len());
749+
trace!(target: "state", "Committing cache {:?} entries", addresses.len());
750750
for (address, a) in addresses.drain().filter(|&(_, ref a)| a.state == AccountState::Committed || a.state == AccountState::CleanFresh) {
751751
self.db.add_to_account_cache(address, a.account, a.state == AccountState::Committed);
752752
}

ethcore/spec/src/genesis.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use keccak_hash::KECCAK_NULL_RLP;
2020
use crate::seal::Seal;
2121

2222
/// Genesis components.
23+
#[derive(Debug)]
2324
pub struct Genesis {
2425
/// Seal.
2526
pub seal: Seal,

ethcore/spec/src/seal.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use ethereum_types::{H64, H256, H520};
2121
use ethjson;
2222

2323
/// Classic ethereum seal.
24+
#[derive(Debug)]
2425
pub struct Ethereum {
2526
/// Seal nonce.
2627
pub nonce: H64,
@@ -37,6 +38,7 @@ impl Into<Generic> for Ethereum {
3738
}
3839

3940
/// AuthorityRound seal.
41+
#[derive(Debug)]
4042
pub struct AuthorityRound {
4143
/// Seal step.
4244
pub step: usize,
@@ -45,6 +47,7 @@ pub struct AuthorityRound {
4547
}
4648

4749
/// Tendermint seal.
50+
#[derive(Debug)]
4851
pub struct Tendermint {
4952
/// Seal round.
5053
pub round: usize,
@@ -73,9 +76,11 @@ impl Into<Generic> for Tendermint {
7376
}
7477
}
7578

79+
#[derive(Debug)]
7680
pub struct Generic(pub Vec<u8>);
7781

7882
/// Genesis seal type.
83+
#[derive(Debug)]
7984
pub enum Seal {
8085
/// Classic ethereum seal.
8186
Ethereum(Ethereum),

ethcore/spec/src/spec.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ use crate::{
5858
seal::Generic as GenericSeal,
5959
};
6060

61-
62-
63-
6461
/// Runtime parameters for the spec that are related to how the software should run the chain,
6562
/// rather than integral properties of the chain itself.
6663
pub struct SpecParams<'a> {
@@ -219,7 +216,7 @@ pub struct Spec {
219216
pub hardcoded_sync: Option<SpecHardcodedSync>,
220217
/// Contract constructors to be executed on genesis.
221218
pub constructors: Vec<(Address, Bytes)>,
222-
/// May be prepopulated if we know this in advance.
219+
/// May be pre-populated if we know this in advance.
223220
pub state_root: H256,
224221
/// Genesis state as plain old data.
225222
pub genesis_state: PodState,

ethcore/src/json_tests/chain.rs

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use miner::Miner;
2424
use io::IoChannel;
2525
use test_helpers;
2626
use types::verification::Unverified;
27-
use verification::VerifierType;
27+
use verification::{VerifierType, queue::kind::BlockLike};
2828
use super::SKIP_TEST_STATE;
2929
use super::HookType;
3030

@@ -39,7 +39,10 @@ pub fn run_test_file<H: FnMut(&str, HookType)>(p: &Path, h: &mut H) {
3939
}
4040

4141
fn skip_test(name: &String) -> bool {
42-
SKIP_TEST_STATE.block.iter().any(|block_test|block_test.subtests.contains(name))
42+
SKIP_TEST_STATE
43+
.block
44+
.iter()
45+
.any(|block_test|block_test.subtests.contains(name))
4346
}
4447

4548
pub fn json_chain_test<H: FnMut(&str, HookType)>(json_data: &[u8], start_stop_hook: &mut H) -> Vec<String> {
@@ -52,18 +55,23 @@ pub fn json_chain_test<H: FnMut(&str, HookType)>(json_data: &[u8], start_stop_ho
5255
println!(" - {} | {:?} Ignoring tests because in skip list", name, blockchain.network);
5356
continue;
5457
}
58+
5559
start_stop_hook(&name, HookType::OnStart);
5660

5761
let mut fail = false;
5862
{
59-
let mut fail_unless = |cond: bool| if !cond && !fail {
60-
failed.push(name.clone());
61-
flushln!("FAIL");
62-
fail = true;
63-
true
64-
} else {false};
63+
let mut fail_unless = |cond: bool| {
64+
if !cond && !fail {
65+
failed.push(name.clone());
66+
flushln!("FAIL");
67+
fail = true;
68+
true
69+
} else {
70+
false
71+
}
72+
};
6573

66-
flush!(" - {}...", name);
74+
info!(" - {}...", name);
6775

6876
let spec = {
6977
let mut spec = match EvmTestClient::fork_spec_from_json(&blockchain.network) {
@@ -89,16 +97,25 @@ pub fn json_chain_test<H: FnMut(&str, HookType)>(json_data: &[u8], start_stop_ho
8997
config.check_seal = false;
9098
}
9199
config.history = 8;
100+
config.queue.verifier_settings.num_verifiers = 1;
92101
let client = Client::new(
93102
config,
94103
&spec,
95104
db,
96105
Arc::new(Miner::new_for_tests(&spec, None)),
97106
IoChannel::disconnected(),
98-
).unwrap();
107+
).expect("Failed to instantiate a new Client");
108+
99109
for b in blockchain.blocks_rlp() {
110+
let bytes_len = b.len();
100111
if let Ok(block) = Unverified::from_rlp(b) {
101-
let _ = client.import_block(block);
112+
let num = block.header.number();
113+
let hash = block.hash();
114+
trace!(target: "json-tests", "{} – Importing {} bytes. Block #{}/{}", name, bytes_len, num, hash);
115+
let res = client.import_block(block);
116+
if let Err(e) = res {
117+
warn!(target: "json-tests", "{} – Error importing block #{}/{}: {:?}", name, num, hash, e);
118+
}
102119
client.flush_queue();
103120
}
104121
}
@@ -113,7 +130,9 @@ pub fn json_chain_test<H: FnMut(&str, HookType)>(json_data: &[u8], start_stop_ho
113130
start_stop_hook(&name, HookType::OnStop);
114131
}
115132

116-
println!("!!! {:?} tests from failed.", failed.len());
133+
if failed.len() > 0 {
134+
println!("!!! {:?} tests failed.", failed.len());
135+
}
117136
failed
118137
}
119138

json/src/maybe.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@
1818
1919
use std::fmt;
2020
use std::marker::PhantomData;
21+
22+
use ethereum_types::U256;
2123
use serde::{Deserialize, Deserializer};
2224
use serde::de::{Error, Visitor, IntoDeserializer};
2325

26+
use crate::uint::Uint;
27+
2428
/// Deserializer of empty string values into optionals.
2529
#[derive(Debug, PartialEq, Clone)]
2630
pub enum MaybeEmpty<T> {
@@ -32,7 +36,8 @@ pub enum MaybeEmpty<T> {
3236

3337
impl<'a, T> Deserialize<'a> for MaybeEmpty<T> where T: Deserialize<'a> {
3438
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
35-
where D: Deserializer<'a> {
39+
where D: Deserializer<'a>
40+
{
3641
deserializer.deserialize_any(MaybeEmptyVisitor::new())
3742
}
3843
}
@@ -78,6 +83,30 @@ impl<T> Into<Option<T>> for MaybeEmpty<T> {
7883
}
7984
}
8085

86+
impl From<MaybeEmpty<Uint>> for U256 {
87+
fn from(maybe: MaybeEmpty<Uint>) -> U256 {
88+
match maybe {
89+
MaybeEmpty::Some(v) => v.0,
90+
MaybeEmpty::None => U256::zero(),
91+
}
92+
}
93+
}
94+
95+
impl From<MaybeEmpty<Uint>> for u64 {
96+
fn from(maybe: MaybeEmpty<Uint>) -> u64 {
97+
match maybe {
98+
MaybeEmpty::Some(v) => v.0.low_u64(),
99+
MaybeEmpty::None => 0u64,
100+
}
101+
}
102+
}
103+
104+
impl Default for MaybeEmpty<Uint> {
105+
fn default() -> Self {
106+
MaybeEmpty::Some(Uint::default())
107+
}
108+
}
109+
81110
#[cfg(test)]
82111
mod tests {
83112
use std::str::FromStr;

json/src/transaction.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ pub struct Transaction {
3636
/// Value.
3737
pub value: Uint,
3838
/// R.
39-
pub r: Uint,
39+
#[serde(default)]
40+
pub r: MaybeEmpty<Uint>,
4041
/// S.
41-
pub s: Uint,
42+
#[serde(default)]
43+
pub s: MaybeEmpty<Uint>,
4244
/// V.
43-
pub v: Uint,
45+
#[serde(default)]
46+
pub v: MaybeEmpty<Uint>,
4447
/// Secret
4548
#[serde(rename = "secretKey")]
4649
pub secret: Option<H256>,
@@ -72,9 +75,9 @@ mod tests {
7275
assert_eq!(tx.nonce, Uint(U256::zero()));
7376
assert_eq!(tx.to, MaybeEmpty::None);
7477
assert_eq!(tx.value, Uint(U256::zero()));
75-
assert_eq!(tx.r, Uint(U256::zero()));
76-
assert_eq!(tx.s, Uint(U256::one()));
77-
assert_eq!(tx.v, Uint(U256::from(2)));
78+
assert_eq!(tx.r, Uint(U256::zero()).into());
79+
assert_eq!(tx.s, Uint(U256::one()).into());
80+
assert_eq!(tx.v, Uint(U256::from(2)).into());
7881
assert_eq!(tx.secret, Some(H256(Eth256::zero())));
7982
}
8083
}

0 commit comments

Comments
 (0)