fixed loading of executive tests, unrevealed failing consensus tests
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
//! Blockchain test state deserializer.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::ops::Deref;
|
||||
use hash::Address;
|
||||
use blockchain::account::Account;
|
||||
|
||||
@@ -25,10 +24,11 @@ use blockchain::account::Account;
|
||||
#[derive(Debug, PartialEq, Deserialize, Clone)]
|
||||
pub struct State(pub BTreeMap<Address, Account>);
|
||||
|
||||
impl Deref for State {
|
||||
type Target = BTreeMap<Address, Account>;
|
||||
impl IntoIterator for State {
|
||||
type Item = <BTreeMap<Address, Account> as IntoIterator>::Item;
|
||||
type IntoIter = <BTreeMap<Address, Account> as IntoIterator>::IntoIter;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.0.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
//! Blockchain test deserializer.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::ops::Deref;
|
||||
use std::io::Read;
|
||||
use serde_json;
|
||||
use serde_json::Error;
|
||||
@@ -27,11 +26,12 @@ use blockchain::blockchain::BlockChain;
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct Test(BTreeMap<String, BlockChain>);
|
||||
|
||||
impl Deref for Test {
|
||||
type Target = BTreeMap<String, BlockChain>;
|
||||
impl IntoIterator for Test {
|
||||
type Item = <BTreeMap<String, BlockChain> as IntoIterator>::Item;
|
||||
type IntoIter = <BTreeMap<String, BlockChain> as IntoIterator>::IntoIter;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.0.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ macro_rules! impl_hash {
|
||||
($name: ident, $inner: ident) => {
|
||||
/// Lenient hash json deserialization for test json files.
|
||||
#[derive(Default, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Clone)]
|
||||
pub struct $name($inner);
|
||||
pub struct $name(pub $inner);
|
||||
|
||||
impl Into<$inner> for $name {
|
||||
fn into(self) -> $inner {
|
||||
|
||||
@@ -25,3 +25,4 @@ pub mod bytes;
|
||||
pub mod blockchain;
|
||||
pub mod spec;
|
||||
pub mod vm;
|
||||
pub mod maybe;
|
||||
|
||||
83
json/src/maybe.rs
Normal file
83
json/src/maybe.rs
Normal file
@@ -0,0 +1,83 @@
|
||||
|
||||
//! Deserializer of empty string values into optionals.
|
||||
|
||||
use std::marker::PhantomData;
|
||||
use serde::{Deserialize, Deserializer, Error};
|
||||
use serde::de::Visitor;
|
||||
use serde_json::Value;
|
||||
use serde_json::value;
|
||||
|
||||
/// Deserializer of empty string values into optionals.
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum MaybeEmpty<T> {
|
||||
/// Some.
|
||||
Some(T),
|
||||
/// None.
|
||||
None,
|
||||
}
|
||||
|
||||
impl<T> Deserialize for MaybeEmpty<T> where T: Deserialize {
|
||||
fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error>
|
||||
where D: Deserializer {
|
||||
deserializer.deserialize(MaybeEmptyVisitor::new())
|
||||
}
|
||||
}
|
||||
|
||||
struct MaybeEmptyVisitor<T> {
|
||||
_phantom: PhantomData<T>
|
||||
}
|
||||
|
||||
impl<T> MaybeEmptyVisitor<T> {
|
||||
fn new() -> Self {
|
||||
MaybeEmptyVisitor {
|
||||
_phantom: PhantomData
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Visitor for MaybeEmptyVisitor<T> where T: Deserialize {
|
||||
type Value = MaybeEmpty<T>;
|
||||
|
||||
fn visit_str<E>(&mut self, value: &str) -> Result<Self::Value, E> where E: Error {
|
||||
self.visit_string(value.to_owned())
|
||||
}
|
||||
|
||||
fn visit_string<E>(&mut self, value: String) -> Result<Self::Value, E> where E: Error {
|
||||
match value.is_empty() {
|
||||
true => Ok(MaybeEmpty::None),
|
||||
false => {
|
||||
let value = Value::String(value);
|
||||
T::deserialize(&mut value::Deserializer::new(value)).map(MaybeEmpty::Some).map_err(|_| Error::custom("failed"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Into<Option<T>> for MaybeEmpty<T> {
|
||||
fn into(self) -> Option<T> {
|
||||
match self {
|
||||
MaybeEmpty::Some(s) => Some(s),
|
||||
MaybeEmpty::None => None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::str::FromStr;
|
||||
use serde_json;
|
||||
use util::hash;
|
||||
use hash::H256;
|
||||
use maybe::MaybeEmpty;
|
||||
|
||||
#[test]
|
||||
fn maybe_deserialization() {
|
||||
let s = r#"["", "5a39ed1020c04d4d84539975b893a4e7c53eab6c2965db8bc3468093a31bc5ae"]"#;
|
||||
let deserialized: Vec<MaybeEmpty<H256>> = serde_json::from_str(s).unwrap();
|
||||
assert_eq!(deserialized, vec![
|
||||
MaybeEmpty::None,
|
||||
MaybeEmpty::Some(H256(hash::H256::from_str("5a39ed1020c04d4d84539975b893a4e7c53eab6c2965db8bc3468093a31bc5ae").unwrap()))
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
use bytes::Bytes;
|
||||
use hash::Address;
|
||||
use uint::Uint;
|
||||
use maybe::MaybeEmpty;
|
||||
|
||||
/// Vm call deserialization.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
@@ -26,7 +27,7 @@ pub struct Call {
|
||||
/// Call data.
|
||||
pub data: Bytes,
|
||||
/// Call destination.
|
||||
pub destination: Address,
|
||||
pub destination: MaybeEmpty<Address>,
|
||||
/// Gas limit.
|
||||
#[serde(rename="gasLimit")]
|
||||
pub gas_limit: Uint,
|
||||
|
||||
@@ -23,7 +23,7 @@ use uint::Uint;
|
||||
pub struct Env {
|
||||
/// Address.
|
||||
#[serde(rename="currentCoinbase")]
|
||||
pub coinbase: Address,
|
||||
pub author: Address,
|
||||
/// Difficulty
|
||||
#[serde(rename="currentDifficulty")]
|
||||
pub difficulty: Uint,
|
||||
|
||||
@@ -21,9 +21,11 @@ pub mod transaction;
|
||||
pub mod vm;
|
||||
pub mod log;
|
||||
pub mod call;
|
||||
pub mod test;
|
||||
|
||||
pub use self::env::Env;
|
||||
pub use self::transaction::Transaction;
|
||||
pub use self::vm::Vm;
|
||||
pub use self::log::Log;
|
||||
pub use self::call::Call;
|
||||
pub use self::test::Test;
|
||||
|
||||
43
json/src/vm/test.rs
Normal file
43
json/src/vm/test.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Vm test deserializer.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::io::Read;
|
||||
use serde_json;
|
||||
use serde_json::Error;
|
||||
use vm::Vm;
|
||||
|
||||
/// Vm test deserializer.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct Test(BTreeMap<String, Vm>);
|
||||
|
||||
impl IntoIterator for Test {
|
||||
type Item = <BTreeMap<String, Vm> as IntoIterator>::Item;
|
||||
type IntoIter = <BTreeMap<String, Vm> as IntoIterator>::IntoIter;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.0.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl Test {
|
||||
/// Loads test from json.
|
||||
pub fn load<R>(reader: R) -> Result<Self, Error> where R: Read {
|
||||
serde_json::from_reader(reader)
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@
|
||||
use bytes::Bytes;
|
||||
use uint::Uint;
|
||||
use blockchain::State;
|
||||
use vm::{Transaction, Log, Call};
|
||||
use vm::{Transaction, Log, Call, Env};
|
||||
|
||||
/// Reporesents vm execution environment before and after exeuction of transaction.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
@@ -27,23 +27,34 @@ pub struct Vm {
|
||||
/// Contract calls made internaly by executed transaction.
|
||||
#[serde(rename="callcreates")]
|
||||
pub calls: Option<Vec<Call>>,
|
||||
/// Env info.
|
||||
pub env: Env,
|
||||
/// Executed transaction
|
||||
#[serde(rename="exec")]
|
||||
pub exec: Transaction,
|
||||
/// Gas.
|
||||
pub gas: Uint,
|
||||
pub transaction: Transaction,
|
||||
/// Gas left after transaction execution.
|
||||
#[serde(rename="gas")]
|
||||
pub gas_left: Option<Uint>,
|
||||
/// Logs created during execution of transaction.
|
||||
pub logs: Vec<Log>,
|
||||
pub logs: Option<Vec<Log>>,
|
||||
/// Transaction output.
|
||||
pub out: Bytes,
|
||||
#[serde(rename="out")]
|
||||
pub output: Option<Bytes>,
|
||||
/// Post execution vm state.
|
||||
#[serde(rename="post")]
|
||||
pub post_state: State,
|
||||
pub post_state: Option<State>,
|
||||
/// Pre execution vm state.
|
||||
#[serde(rename="pre")]
|
||||
pub pre_state: State,
|
||||
}
|
||||
|
||||
impl Vm {
|
||||
/// Returns true if transaction execution run out of gas.
|
||||
pub fn out_of_gas(&self) -> bool {
|
||||
self.calls.is_none()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json;
|
||||
|
||||
Reference in New Issue
Block a user