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

rpctest executable #757

Merged
merged 18 commits into from
Mar 19, 2016
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ethminer = { path = "miner" }
ethcore-devtools = { path = "devtools" }
ethcore-rpc = { path = "rpc", optional = true }
ethjson = { path = "json" }
serde_json = "0.7.0"

[features]
default = ["rpc"]
Expand All @@ -40,6 +41,10 @@ travis-nightly = ["ethcore/json-tests", "dev"]
path = "parity/main.rs"
name = "parity"

[[bin]]
path = "parity/rpctest.rs"
name = "rpctest"

[profile.release]
debug = false
lto = false
1 change: 1 addition & 0 deletions ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ clippy = { version = "0.0.50", optional = true }
crossbeam = "0.1.5"
lazy_static = "0.1"
ethcore-devtools = { path = "../devtools" }
ethjson = { path = "../json" }

[features]
jit = ["evmjit"]
Expand Down
2 changes: 1 addition & 1 deletion ethcore/res/ethereum/frontier_like_test.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"engineName": "Frontier (Test)",
"name": "Frontier (Test)",
"engineName": "Ethash",
"params": {
"accountStartNonce": "0x00",
Expand Down
2 changes: 1 addition & 1 deletion ethcore/res/ethereum/frontier_test.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"engineName": "Frontier (Test)",
"name": "Frontier (Test)",
"engineName": "Ethash",
"params": {
"accountStartNonce": "0x00",
Expand Down
3 changes: 2 additions & 1 deletion ethcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ extern crate time;
extern crate env_logger;
extern crate num_cpus;
extern crate crossbeam;
extern crate ethjson;

#[cfg(test)] extern crate ethcore_devtools as devtools;
#[cfg(feature = "jit" )] extern crate evmjit;
Expand All @@ -100,13 +101,13 @@ pub mod spec;
pub mod transaction;
pub mod views;
pub mod receipt;
pub mod pod_state;

mod common;
mod basic_types;
#[macro_use] mod evm;
mod env_info;
mod pod_account;
mod pod_state;
mod account_diff;
mod state_diff;
mod engine;
Expand Down
16 changes: 16 additions & 0 deletions ethcore/src/pod_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use util::*;
use account::*;
use account_db::*;
use ethjson;

#[derive(Debug,Clone,PartialEq,Eq)]
/// An account, expressed as Plain-Old-Data (hence the name).
Expand Down Expand Up @@ -73,6 +74,21 @@ impl PodAccount {
}
}

impl From<ethjson::blockchain::Account> for PodAccount {
fn from(a: ethjson::blockchain::Account) -> Self {
PodAccount {
balance: a.balance.into(),
nonce: a.nonce.into(),
code: a.code.into(),
storage: a.storage.into_iter().fold(BTreeMap::new(), |mut acc, (key, value)| {
let key: U256 = key.into();
acc.insert(H256::from(key), value.into());
acc
})
}
}
}

impl fmt::Display for PodAccount {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "(bal={}; nonce={}; code={} bytes, #{}; storage={} items)", self.balance, self.nonce, self.code.len(), self.code.sha3(), self.storage.len())
Expand Down
14 changes: 13 additions & 1 deletion ethcore/src/pod_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

//! State of all accounts in the system expressed in Plain Old Data.

use util::*;
use pod_account::*;
use ethjson;

#[derive(Debug,Clone,PartialEq,Eq,Default)]
/// State of all accounts in the system expressed in Plain Old Data.
#[derive(Debug,Clone,PartialEq,Eq,Default)]
pub struct PodState (BTreeMap<Address, PodAccount>);

impl PodState {
Expand Down Expand Up @@ -64,6 +67,15 @@ impl FromJson for PodState {
}
}

impl From<ethjson::blockchain::State> for PodState {
fn from(s: ethjson::blockchain::State) -> PodState {
PodState(s.0.into_iter().fold(BTreeMap::new(), |mut acc, (key, value)| {
acc.insert(key.into(), PodAccount::from(value));
acc
}))
}
}

impl fmt::Display for PodState {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for (add, acc) in &self.0 {
Expand Down
91 changes: 91 additions & 0 deletions ethcore/src/spec/genesis.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// 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/>.

use util::rlp::*;
use util::numbers::{Uint, U256};
use util::hash::{H64, Address, H256};
use ethjson;

/// Genesis seal type.
pub enum Seal {
/// Classic ethereum seal.
Ethereum {
/// Seal nonce.
nonce: H64,
/// Seal mix hash.
mix_hash: H256,
},
/// Generic seal.
Generic {
/// Number of seal fields.
fields: usize,
/// Seal rlp.
rlp: Vec<u8>,
},
}

/// Genesis components.
pub struct Genesis {
/// Seal.
pub seal: Seal,
/// Difficulty.
pub difficulty: U256,
/// Author.
pub author: Address,
/// Timestamp.
pub timestamp: u64,
/// Parent hash.
pub parent_hash: H256,
/// Gas limit.
pub gas_limit: U256,
/// Transactions root.
pub transactions_root: H256,
/// Receipts root.
pub receipts_root: H256,
/// State root.
pub state_root: Option<H256>,
/// Gas used.
pub gas_used: U256,
/// Extra data.
pub extra_data: Vec<u8>,
}

impl From<ethjson::spec::Genesis> for Genesis {
fn from(g: ethjson::spec::Genesis) -> Self {
Genesis {
seal: match (g.nonce, g.mix_hash) {
(Some(nonce), Some(mix_hash)) => Seal::Ethereum {
nonce: nonce.into(),
mix_hash: mix_hash.into(),
},
_ => Seal::Generic {
fields: g.seal_fields.unwrap(),
rlp: g.seal_rlp.unwrap().into(),
}
},
difficulty: g.difficulty.into(),
author: g.author.into(),
timestamp: g.timestamp.into(),
parent_hash: g.parent_hash.into(),
gas_limit: g.gas_limit.into(),
transactions_root: g.transactions_root.map_or_else(|| SHA3_NULL_RLP.clone(), Into::into),
receipts_root: g.receipts_root.map_or_else(|| SHA3_NULL_RLP.clone(), Into::into),
state_root: g.state_root.map(Into::into),
gas_used: g.gas_used.map_or_else(U256::zero, Into::into),
extra_data: g.extra_data.map_or_else(Vec::new, Into::into),
}
}
}
23 changes: 23 additions & 0 deletions ethcore/src/spec/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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/>.

//! Blockchain params.

mod genesis;
pub mod spec;

pub use self::spec::*;
pub use self::genesis::Genesis;
32 changes: 30 additions & 2 deletions ethcore/src/spec.rs → ethcore/src/spec/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use engine::*;
use pod_state::*;
use null_engine::*;
use account_db::*;
use ethereum;
use super::genesis::{Seal as GenesisSeal, Genesis};

/// Convert JSON value to equivalent RLP representation.
// TODO: handle container types.
Expand Down Expand Up @@ -106,7 +108,7 @@ impl Spec {
pub fn to_engine(self) -> Result<Box<Engine>, Error> {
match self.engine_name.as_ref() {
"NullEngine" => Ok(NullEngine::new_boxed(self)),
"Ethash" => Ok(super::ethereum::Ethash::new_boxed(self)),
"Ethash" => Ok(ethereum::Ethash::new_boxed(self)),
_ => Err(Error::UnknownEngineName(self.engine_name.clone()))
}
}
Expand Down Expand Up @@ -197,6 +199,32 @@ impl Spec {
self.state_root_memo = RwLock::new(genesis.find("stateRoot").and_then(|_| Some(H256::from_json(&genesis["stateRoot"]))));
}

/// Overwrite the genesis components.
pub fn overwrite_genesis_params(&mut self, g: Genesis) {
let (seal_fields, seal_rlp) = match g.seal {
GenesisSeal::Generic { fields, rlp } => (fields, rlp),
GenesisSeal::Ethereum { nonce, mix_hash } => {
let mut s = RlpStream::new();
s.append(&mix_hash);
s.append(&nonce);
(2, s.out())
}
};

self.parent_hash = g.parent_hash;
self.transactions_root = g.transactions_root;
self.receipts_root = g.receipts_root;
self.author = g.author;
self.difficulty = g.difficulty;
self.gas_limit = g.gas_limit;
self.gas_used = g.gas_used;
self.timestamp = g.timestamp;
self.extra_data = g.extra_data;
self.seal_fields = seal_fields;
self.seal_rlp = seal_rlp;
self.state_root_memo = RwLock::new(g.state_root);
}

/// Alter the value of the genesis state.
pub fn set_genesis_state(&mut self, s: PodState) {
self.genesis_state = s;
Expand Down Expand Up @@ -304,7 +332,7 @@ impl Spec {
}

/// Create a new Spec which conforms to the Morden chain except that it's a NullEngine consensus.
pub fn new_test() -> Spec { Self::from_json_utf8(include_bytes!("../res/null_morden.json")) }
pub fn new_test() -> Spec { Self::from_json_utf8(include_bytes!("../../res/null_morden.json")) }
}

#[cfg(test)]
Expand Down
17 changes: 11 additions & 6 deletions json/src/blockchain/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@
use std::collections::BTreeMap;
use uint::Uint;
use bytes::Bytes;
use hash::H256;

/// Blockchain test account deserializer.
#[derive(Debug, PartialEq, Deserialize)]
#[derive(Debug, PartialEq, Deserialize, Clone)]
pub struct Account {
balance: Uint,
code: Bytes,
nonce: Uint,
storage: BTreeMap<Uint, Bytes>,
/// Balance.
pub balance: Uint,
/// Code.
pub code: Bytes,
/// Nonce.
pub nonce: Uint,
/// Storage.
pub storage: BTreeMap<Uint, H256>,
}

#[cfg(test)]
Expand All @@ -35,7 +40,7 @@ mod tests {
use blockchain::account::Account;

#[test]
fn header_deserialization() {
fn account_deserialization() {
let s = r#"{
"balance" : "0x09184e72a078",
"code" : "0x600140600155",
Expand Down
7 changes: 7 additions & 0 deletions json/src/blockchain/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ pub struct Block {
uncles: Vec<Header>,
}

impl Block {
/// Returns block rlp.
pub fn rlp(&self) -> Vec<u8> {
self.rlp.clone().into()
}
}

#[cfg(test)]
mod tests {
use serde_json;
Expand Down