Reformat the source code
This commit is contained in:
@@ -16,31 +16,31 @@
|
||||
|
||||
//! Blockchain test account deserializer.
|
||||
|
||||
use bytes::Bytes;
|
||||
use std::collections::BTreeMap;
|
||||
use uint::Uint;
|
||||
use bytes::Bytes;
|
||||
|
||||
/// Blockchain test account deserializer.
|
||||
#[derive(Debug, PartialEq, Deserialize, Clone)]
|
||||
pub struct Account {
|
||||
/// Balance.
|
||||
pub balance: Uint,
|
||||
/// Code.
|
||||
pub code: Bytes,
|
||||
/// Nonce.
|
||||
pub nonce: Uint,
|
||||
/// Storage.
|
||||
pub storage: BTreeMap<Uint, Uint>,
|
||||
/// Balance.
|
||||
pub balance: Uint,
|
||||
/// Code.
|
||||
pub code: Bytes,
|
||||
/// Nonce.
|
||||
pub nonce: Uint,
|
||||
/// Storage.
|
||||
pub storage: BTreeMap<Uint, Uint>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json;
|
||||
use blockchain::account::Account;
|
||||
use blockchain::account::Account;
|
||||
use serde_json;
|
||||
|
||||
#[test]
|
||||
fn account_deserialization() {
|
||||
let s = r#"{
|
||||
#[test]
|
||||
fn account_deserialization() {
|
||||
let s = r#"{
|
||||
"balance" : "0x09184e72a078",
|
||||
"code" : "0x600140600155",
|
||||
"nonce" : "0x00",
|
||||
@@ -48,7 +48,7 @@ mod tests {
|
||||
"0x01" : "0x9a10c2b5bb8f3c602e674006d9b21f09167df57c87a78a5ce96d4159ecb76520"
|
||||
}
|
||||
}"#;
|
||||
let _deserialized: Account = serde_json::from_str(s).unwrap();
|
||||
// TODO: validate all fields
|
||||
}
|
||||
let _deserialized: Account = serde_json::from_str(s).unwrap();
|
||||
// TODO: validate all fields
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,36 +16,35 @@
|
||||
|
||||
//! Blockchain test block deserializer.
|
||||
|
||||
use blockchain::{header::Header, transaction::Transaction};
|
||||
use bytes::Bytes;
|
||||
use blockchain::header::Header;
|
||||
use blockchain::transaction::Transaction;
|
||||
|
||||
/// Blockchain test block deserializer.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct Block {
|
||||
#[serde(rename = "blockHeader")]
|
||||
header: Option<Header>,
|
||||
rlp: Bytes,
|
||||
transactions: Option<Vec<Transaction>>,
|
||||
#[serde(rename = "uncleHeaders")]
|
||||
uncles: Option<Vec<Header>>,
|
||||
#[serde(rename = "blockHeader")]
|
||||
header: Option<Header>,
|
||||
rlp: Bytes,
|
||||
transactions: Option<Vec<Transaction>>,
|
||||
#[serde(rename = "uncleHeaders")]
|
||||
uncles: Option<Vec<Header>>,
|
||||
}
|
||||
|
||||
impl Block {
|
||||
/// Returns block rlp.
|
||||
pub fn rlp(&self) -> Vec<u8> {
|
||||
self.rlp.clone().into()
|
||||
}
|
||||
/// Returns block rlp.
|
||||
pub fn rlp(&self) -> Vec<u8> {
|
||||
self.rlp.clone().into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json;
|
||||
use blockchain::block::Block;
|
||||
use blockchain::block::Block;
|
||||
use serde_json;
|
||||
|
||||
#[test]
|
||||
fn block_deserialization() {
|
||||
let s = r#"{
|
||||
#[test]
|
||||
fn block_deserialization() {
|
||||
let s = r#"{
|
||||
"blockHeader" : {
|
||||
"bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
"coinbase" : "8888f1f195afa192cfee860698584c030f4c9db1",
|
||||
@@ -69,7 +68,7 @@ mod tests {
|
||||
"transactions" : [],
|
||||
"uncleHeaders" : []
|
||||
}"#;
|
||||
let _deserialized: Block = serde_json::from_str(s).unwrap();
|
||||
// TODO: validate all fields
|
||||
}
|
||||
let _deserialized: Block = serde_json::from_str(s).unwrap();
|
||||
// TODO: validate all fields
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,91 +16,89 @@
|
||||
|
||||
//! Blockchain deserialization.
|
||||
|
||||
use blockchain::{block::Block, header::Header, state::State};
|
||||
use bytes::Bytes;
|
||||
use hash::H256;
|
||||
use blockchain::state::State;
|
||||
use blockchain::header::Header;
|
||||
use blockchain::block::Block;
|
||||
use spec::{ForkSpec, Genesis, Seal, Ethereum};
|
||||
use spec::{Ethereum, ForkSpec, Genesis, Seal};
|
||||
|
||||
/// Json Block test possible engine kind.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub enum Engine {
|
||||
/// Default (old) behaviour.
|
||||
Ethash,
|
||||
/// No check of block's difficulty and nonce for tests.
|
||||
NoProof,
|
||||
/// Default (old) behaviour.
|
||||
Ethash,
|
||||
/// No check of block's difficulty and nonce for tests.
|
||||
NoProof,
|
||||
}
|
||||
|
||||
impl Default for Engine {
|
||||
fn default() -> Self {
|
||||
Engine::Ethash
|
||||
}
|
||||
fn default() -> Self {
|
||||
Engine::Ethash
|
||||
}
|
||||
}
|
||||
|
||||
/// Blockchain deserialization.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct BlockChain {
|
||||
/// Genesis block header.
|
||||
#[serde(rename = "genesisBlockHeader")]
|
||||
pub genesis_block: Header,
|
||||
/// Genesis block rlp.
|
||||
#[serde(rename = "genesisRLP")]
|
||||
pub genesis_rlp: Option<Bytes>,
|
||||
/// Blocks.
|
||||
pub blocks: Vec<Block>,
|
||||
/// Post state.
|
||||
pub post_state: State,
|
||||
/// Pre state.
|
||||
#[serde(rename = "pre")]
|
||||
pub pre_state: State,
|
||||
/// Hash of best block.
|
||||
#[serde(rename = "lastblockhash")]
|
||||
pub best_block: H256,
|
||||
/// Network.
|
||||
pub network: ForkSpec,
|
||||
#[serde(default)]
|
||||
#[serde(rename="sealEngine")]
|
||||
/// Engine
|
||||
pub engine: Engine,
|
||||
/// Genesis block header.
|
||||
#[serde(rename = "genesisBlockHeader")]
|
||||
pub genesis_block: Header,
|
||||
/// Genesis block rlp.
|
||||
#[serde(rename = "genesisRLP")]
|
||||
pub genesis_rlp: Option<Bytes>,
|
||||
/// Blocks.
|
||||
pub blocks: Vec<Block>,
|
||||
/// Post state.
|
||||
pub post_state: State,
|
||||
/// Pre state.
|
||||
#[serde(rename = "pre")]
|
||||
pub pre_state: State,
|
||||
/// Hash of best block.
|
||||
#[serde(rename = "lastblockhash")]
|
||||
pub best_block: H256,
|
||||
/// Network.
|
||||
pub network: ForkSpec,
|
||||
#[serde(default)]
|
||||
#[serde(rename = "sealEngine")]
|
||||
/// Engine
|
||||
pub engine: Engine,
|
||||
}
|
||||
|
||||
impl BlockChain {
|
||||
/// Returns blocks rlp.
|
||||
pub fn blocks_rlp(&self) -> Vec<Vec<u8>> {
|
||||
self.blocks.iter().map(|block| block.rlp()).collect()
|
||||
}
|
||||
/// Returns blocks rlp.
|
||||
pub fn blocks_rlp(&self) -> Vec<Vec<u8>> {
|
||||
self.blocks.iter().map(|block| block.rlp()).collect()
|
||||
}
|
||||
|
||||
/// Returns spec compatible genesis struct.
|
||||
pub fn genesis(&self) -> Genesis {
|
||||
Genesis {
|
||||
seal: Seal::Ethereum(Ethereum {
|
||||
nonce: self.genesis_block.nonce.clone(),
|
||||
mix_hash: self.genesis_block.mix_hash.clone(),
|
||||
}),
|
||||
difficulty: self.genesis_block.difficulty,
|
||||
author: Some(self.genesis_block.author.clone()),
|
||||
timestamp: Some(self.genesis_block.timestamp),
|
||||
parent_hash: Some(self.genesis_block.parent_hash.clone()),
|
||||
gas_limit: self.genesis_block.gas_limit,
|
||||
transactions_root: Some(self.genesis_block.transactions_root.clone()),
|
||||
receipts_root: Some(self.genesis_block.receipts_root.clone()),
|
||||
state_root: Some(self.genesis_block.state_root.clone()),
|
||||
gas_used: Some(self.genesis_block.gas_used),
|
||||
extra_data: Some(self.genesis_block.extra_data.clone()),
|
||||
}
|
||||
}
|
||||
/// Returns spec compatible genesis struct.
|
||||
pub fn genesis(&self) -> Genesis {
|
||||
Genesis {
|
||||
seal: Seal::Ethereum(Ethereum {
|
||||
nonce: self.genesis_block.nonce.clone(),
|
||||
mix_hash: self.genesis_block.mix_hash.clone(),
|
||||
}),
|
||||
difficulty: self.genesis_block.difficulty,
|
||||
author: Some(self.genesis_block.author.clone()),
|
||||
timestamp: Some(self.genesis_block.timestamp),
|
||||
parent_hash: Some(self.genesis_block.parent_hash.clone()),
|
||||
gas_limit: self.genesis_block.gas_limit,
|
||||
transactions_root: Some(self.genesis_block.transactions_root.clone()),
|
||||
receipts_root: Some(self.genesis_block.receipts_root.clone()),
|
||||
state_root: Some(self.genesis_block.state_root.clone()),
|
||||
gas_used: Some(self.genesis_block.gas_used),
|
||||
extra_data: Some(self.genesis_block.extra_data.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json;
|
||||
use blockchain::blockchain::BlockChain;
|
||||
use blockchain::blockchain::BlockChain;
|
||||
use serde_json;
|
||||
|
||||
#[test]
|
||||
fn blockchain_deserialization() {
|
||||
let s = r#"{
|
||||
#[test]
|
||||
fn blockchain_deserialization() {
|
||||
let s = r#"{
|
||||
"blocks" : [{
|
||||
"blockHeader" : {
|
||||
"bloom" : "00000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000040000000000000000000000000000000000000000000000000000000",
|
||||
@@ -198,7 +196,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}"#;
|
||||
let _deserialized: BlockChain = serde_json::from_str(s).unwrap();
|
||||
// TODO: validate all fields
|
||||
}
|
||||
let _deserialized: BlockChain = serde_json::from_str(s).unwrap();
|
||||
// TODO: validate all fields
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,60 +16,60 @@
|
||||
|
||||
//! Blockchain test header deserializer.
|
||||
|
||||
use hash::{H64, Address, H256, Bloom};
|
||||
use uint::Uint;
|
||||
use bytes::Bytes;
|
||||
use hash::{Address, Bloom, H256, H64};
|
||||
use uint::Uint;
|
||||
|
||||
/// Blockchain test header deserializer.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Header {
|
||||
/// Blocks bloom.
|
||||
pub bloom: Bloom,
|
||||
/// Blocks author.
|
||||
#[serde(rename = "coinbase")]
|
||||
pub author: Address,
|
||||
/// Difficulty.
|
||||
pub difficulty: Uint,
|
||||
/// Extra data.
|
||||
pub extra_data: Bytes,
|
||||
/// Gas limit.
|
||||
pub gas_limit: Uint,
|
||||
/// Gas used.
|
||||
pub gas_used: Uint,
|
||||
/// Hash.
|
||||
pub hash: H256,
|
||||
/// Mix hash.
|
||||
pub mix_hash: H256,
|
||||
/// Seal nonce.
|
||||
pub nonce: H64,
|
||||
/// Block number.
|
||||
pub number: Uint,
|
||||
/// Parent hash.
|
||||
pub parent_hash: H256,
|
||||
/// Receipt root.
|
||||
#[serde(rename = "receiptTrie")]
|
||||
pub receipts_root: H256,
|
||||
/// State root.
|
||||
pub state_root: H256,
|
||||
/// Timestamp.
|
||||
pub timestamp: Uint,
|
||||
/// Transactions root.
|
||||
#[serde(rename = "transactionsTrie")]
|
||||
pub transactions_root: H256,
|
||||
/// Uncles hash.
|
||||
#[serde(rename = "uncleHash")]
|
||||
pub uncles_hash: H256,
|
||||
/// Blocks bloom.
|
||||
pub bloom: Bloom,
|
||||
/// Blocks author.
|
||||
#[serde(rename = "coinbase")]
|
||||
pub author: Address,
|
||||
/// Difficulty.
|
||||
pub difficulty: Uint,
|
||||
/// Extra data.
|
||||
pub extra_data: Bytes,
|
||||
/// Gas limit.
|
||||
pub gas_limit: Uint,
|
||||
/// Gas used.
|
||||
pub gas_used: Uint,
|
||||
/// Hash.
|
||||
pub hash: H256,
|
||||
/// Mix hash.
|
||||
pub mix_hash: H256,
|
||||
/// Seal nonce.
|
||||
pub nonce: H64,
|
||||
/// Block number.
|
||||
pub number: Uint,
|
||||
/// Parent hash.
|
||||
pub parent_hash: H256,
|
||||
/// Receipt root.
|
||||
#[serde(rename = "receiptTrie")]
|
||||
pub receipts_root: H256,
|
||||
/// State root.
|
||||
pub state_root: H256,
|
||||
/// Timestamp.
|
||||
pub timestamp: Uint,
|
||||
/// Transactions root.
|
||||
#[serde(rename = "transactionsTrie")]
|
||||
pub transactions_root: H256,
|
||||
/// Uncles hash.
|
||||
#[serde(rename = "uncleHash")]
|
||||
pub uncles_hash: H256,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json;
|
||||
use blockchain::header::Header;
|
||||
use blockchain::header::Header;
|
||||
use serde_json;
|
||||
|
||||
#[test]
|
||||
fn header_deserialization() {
|
||||
let s = r#"{
|
||||
#[test]
|
||||
fn header_deserialization() {
|
||||
let s = r#"{
|
||||
"bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
"coinbase" : "8888f1f195afa192cfee860698584c030f4c9db1",
|
||||
"difficulty" : "0x020000",
|
||||
@@ -87,7 +87,7 @@ mod tests {
|
||||
"transactionsTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
||||
"uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
|
||||
}"#;
|
||||
let _deserialized: Header = serde_json::from_str(s).unwrap();
|
||||
// TODO: validate all fields
|
||||
}
|
||||
let _deserialized: Header = serde_json::from_str(s).unwrap();
|
||||
// TODO: validate all fields
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,14 +21,15 @@ pub mod block;
|
||||
pub mod blockchain;
|
||||
pub mod header;
|
||||
pub mod state;
|
||||
pub mod transaction;
|
||||
pub mod test;
|
||||
pub mod transaction;
|
||||
|
||||
pub use self::account::Account;
|
||||
pub use self::block::Block;
|
||||
pub use self::blockchain::BlockChain;
|
||||
pub use self::blockchain::Engine;
|
||||
pub use self::header::Header;
|
||||
pub use self::state::State;
|
||||
pub use self::test::Test;
|
||||
pub use self::transaction::Transaction;
|
||||
pub use self::{
|
||||
account::Account,
|
||||
block::Block,
|
||||
blockchain::{BlockChain, Engine},
|
||||
header::Header,
|
||||
state::State,
|
||||
test::Test,
|
||||
transaction::Transaction,
|
||||
};
|
||||
|
||||
@@ -16,19 +16,19 @@
|
||||
|
||||
//! Blockchain test state deserializer.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use hash::Address;
|
||||
use blockchain::account::Account;
|
||||
use hash::Address;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
/// Blockchain test state deserializer.
|
||||
#[derive(Debug, PartialEq, Deserialize, Clone)]
|
||||
pub struct State(BTreeMap<Address, Account>);
|
||||
|
||||
impl IntoIterator for State {
|
||||
type Item = <BTreeMap<Address, Account> as IntoIterator>::Item;
|
||||
type IntoIter = <BTreeMap<Address, Account> as IntoIterator>::IntoIter;
|
||||
type Item = <BTreeMap<Address, Account> as IntoIterator>::Item;
|
||||
type IntoIter = <BTreeMap<Address, Account> as IntoIterator>::IntoIter;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.0.into_iter()
|
||||
}
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.0.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,28 +16,29 @@
|
||||
|
||||
//! Blockchain test deserializer.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::io::Read;
|
||||
use serde_json;
|
||||
use serde_json::Error;
|
||||
use blockchain::blockchain::BlockChain;
|
||||
use serde_json::{self, Error};
|
||||
use std::{collections::BTreeMap, io::Read};
|
||||
|
||||
/// Blockchain test deserializer.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct Test(BTreeMap<String, BlockChain>);
|
||||
|
||||
impl IntoIterator for Test {
|
||||
type Item = <BTreeMap<String, BlockChain> as IntoIterator>::Item;
|
||||
type IntoIter = <BTreeMap<String, BlockChain> as IntoIterator>::IntoIter;
|
||||
type Item = <BTreeMap<String, BlockChain> as IntoIterator>::Item;
|
||||
type IntoIter = <BTreeMap<String, BlockChain> as IntoIterator>::IntoIter;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.0.into_iter()
|
||||
}
|
||||
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)
|
||||
}
|
||||
/// Loads test from json.
|
||||
pub fn load<R>(reader: R) -> Result<Self, Error>
|
||||
where
|
||||
R: Read,
|
||||
{
|
||||
serde_json::from_reader(reader)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,19 +16,19 @@
|
||||
|
||||
//! Blockchain test transaction deserialization.
|
||||
|
||||
use uint::Uint;
|
||||
use bytes::Bytes;
|
||||
use uint::Uint;
|
||||
|
||||
/// Blockchain test transaction deserialization.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Transaction {
|
||||
data: Bytes,
|
||||
gas_limit: Uint,
|
||||
gas_price: Uint,
|
||||
nonce: Uint,
|
||||
r: Uint,
|
||||
s: Uint,
|
||||
v: Uint,
|
||||
value: Uint
|
||||
data: Bytes,
|
||||
gas_limit: Uint,
|
||||
gas_price: Uint,
|
||||
nonce: Uint,
|
||||
r: Uint,
|
||||
s: Uint,
|
||||
v: Uint,
|
||||
value: Uint,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user