use ethjson module to load chain json tests
This commit is contained in:
@@ -19,7 +19,6 @@
|
||||
use std::collections::BTreeMap;
|
||||
use uint::Uint;
|
||||
use bytes::Bytes;
|
||||
use hash::H256;
|
||||
|
||||
/// Blockchain test account deserializer.
|
||||
#[derive(Debug, PartialEq, Deserialize, Clone)]
|
||||
|
||||
@@ -24,11 +24,11 @@ use blockchain::transaction::Transaction;
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct Block {
|
||||
#[serde(rename="blockHeader")]
|
||||
header: Header,
|
||||
header: Option<Header>,
|
||||
rlp: Bytes,
|
||||
transactions: Vec<Transaction>,
|
||||
transactions: Option<Vec<Transaction>>,
|
||||
#[serde(rename="uncleHeaders")]
|
||||
uncles: Vec<Header>,
|
||||
uncles: Option<Vec<Header>>,
|
||||
}
|
||||
|
||||
impl Block {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
//! Blockchain deserialization.
|
||||
|
||||
use bytes::Bytes;
|
||||
use hash::H256;
|
||||
use blockchain::state::State;
|
||||
use blockchain::header::Header;
|
||||
use blockchain::block::Block;
|
||||
@@ -30,7 +31,7 @@ pub struct BlockChain {
|
||||
pub genesis_block: Header,
|
||||
/// Genesis block rlp.
|
||||
#[serde(rename="genesisRLP")]
|
||||
pub genesis_rlp: Bytes,
|
||||
pub genesis_rlp: Option<Bytes>,
|
||||
/// Blocks.
|
||||
pub blocks: Vec<Block>,
|
||||
/// Post state.
|
||||
@@ -39,14 +40,12 @@ pub struct BlockChain {
|
||||
/// Pre state.
|
||||
#[serde(rename="pre")]
|
||||
pub pre_state: State,
|
||||
/// Hash of best block.
|
||||
#[serde(rename="lastblockhash")]
|
||||
pub best_block: H256
|
||||
}
|
||||
|
||||
impl BlockChain {
|
||||
/// Returns genesis block rlp.
|
||||
pub fn genesis_rlp(&self) -> Vec<u8> {
|
||||
self.genesis_rlp.clone().into()
|
||||
}
|
||||
|
||||
/// Returns blocks rlp.
|
||||
pub fn blocks_rlp(&self) -> Vec<Vec<u8>> {
|
||||
self.blocks.iter().map(|block| block.rlp()).collect()
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::ops::Deref;
|
||||
use std::io::Read;
|
||||
use serde_json;
|
||||
use serde_json::Error;
|
||||
use blockchain::blockchain::BlockChain;
|
||||
|
||||
/// Blockchain test deserializer.
|
||||
@@ -31,3 +34,10 @@ impl Deref for Test {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Test {
|
||||
/// Loads test from json.
|
||||
pub fn load<R>(reader: R) -> Result<Self, Error> where R: Read {
|
||||
serde_json::from_reader(reader)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,12 +46,8 @@ impl Visitor for BytesVisitor {
|
||||
let v = match value.len() {
|
||||
0 => vec![],
|
||||
2 if value.starts_with("0x") => vec![],
|
||||
_ if value.starts_with("0x") => try!(FromHex::from_hex(&value[2..]).map_err(|_| {
|
||||
Error::custom(format!("Invalid hex value {}.", value).as_ref())
|
||||
})),
|
||||
_ => try!(FromHex::from_hex(value).map_err(|_| {
|
||||
Error::custom(format!("Invalid hex value {}.", value).as_ref())
|
||||
}))
|
||||
_ if value.starts_with("0x") => FromHex::from_hex(&value[2..]).unwrap_or(vec![]),
|
||||
_ => FromHex::from_hex(value).unwrap_or(vec![]),
|
||||
};
|
||||
Ok(Bytes(v))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user