merge master

This commit is contained in:
Nikolay Volf 2016-01-28 18:48:18 +04:00
commit 8a9995bbb3
28 changed files with 298 additions and 118 deletions

1
.gitmodules vendored
View File

@ -1,3 +1,4 @@
[submodule "res/ethereum/tests"] [submodule "res/ethereum/tests"]
path = res/ethereum/tests path = res/ethereum/tests
url = git@github.com:ethereum/tests url = git@github.com:ethereum/tests
branch = develop

View File

@ -17,7 +17,7 @@ heapsize = "0.2.0"
rust-crypto = "0.2.34" rust-crypto = "0.2.34"
time = "0.1" time = "0.1"
#interpolate_idents = { git = "https://github.com/SkylerLipthay/interpolate_idents" } #interpolate_idents = { git = "https://github.com/SkylerLipthay/interpolate_idents" }
evmjit = { path = "rust-evmjit", optional = true } evmjit = { path = "evmjit", optional = true }
ethash = { path = "ethash" } ethash = { path = "ethash" }
num_cpus = "0.2" num_cpus = "0.2"
clippy = "0.0.37" clippy = "0.0.37"

View File

@ -15,6 +15,7 @@ ctrlc = "1.0"
ethcore-util = { path = "../util" } ethcore-util = { path = "../util" }
ethcore-rpc = { path = "../rpc", optional = true } ethcore-rpc = { path = "../rpc", optional = true }
ethcore = { path = ".." } ethcore = { path = ".." }
clippy = "0.0.37"
[features] [features]
rpc = ["ethcore-rpc"] rpc = ["ethcore-rpc"]

View File

@ -1,6 +1,9 @@
//! Ethcore client application.
#![warn(missing_docs)]
#![feature(plugin)] #![feature(plugin)]
#![plugin(docopt_macros)] #![plugin(docopt_macros)]
// required for serde, move it to a separate library #![plugin(clippy)]
extern crate docopt; extern crate docopt;
extern crate rustc_serialize; extern crate rustc_serialize;
extern crate ethcore_util as util; extern crate ethcore_util as util;
@ -35,7 +38,7 @@ Options:
-h --help Show this screen. -h --help Show this screen.
"); ");
fn setup_log(init: &String) { fn setup_log(init: &str) {
let mut builder = LogBuilder::new(); let mut builder = LogBuilder::new();
builder.filter(None, LogLevelFilter::Info); builder.filter(None, LogLevelFilter::Info);
@ -50,19 +53,19 @@ fn setup_log(init: &String) {
#[cfg(feature = "rpc")] #[cfg(feature = "rpc")]
fn setup_rpc_server(client: Arc<Client>) { fn setup_rpc_server(client: Arc<Client>, sync: Arc<EthSync>) {
use rpc::*; use rpc::v1::*;
let mut server = HttpServer::new(1); let mut server = rpc::HttpServer::new(1);
server.add_delegate(Web3Client::new().to_delegate()); server.add_delegate(Web3Client::new().to_delegate());
server.add_delegate(EthClient::new(client.clone()).to_delegate()); server.add_delegate(EthClient::new(client.clone()).to_delegate());
server.add_delegate(EthFilterClient::new(client).to_delegate()); server.add_delegate(EthFilterClient::new(client).to_delegate());
server.add_delegate(NetClient::new().to_delegate()); server.add_delegate(NetClient::new(sync).to_delegate());
server.start_async("127.0.0.1:3030"); server.start_async("127.0.0.1:3030");
} }
#[cfg(not(feature = "rpc"))] #[cfg(not(feature = "rpc"))]
fn setup_rpc_server(_client: Arc<Client>) { fn setup_rpc_server(_client: Arc<Client>, _sync: Arc<EthSync>) {
} }
fn main() { fn main() {
@ -78,7 +81,7 @@ fn main() {
let mut net_settings = NetworkConfiguration::new(); let mut net_settings = NetworkConfiguration::new();
net_settings.boot_nodes = init_nodes; net_settings.boot_nodes = init_nodes;
let mut service = ClientService::start(spec, net_settings).unwrap(); let mut service = ClientService::start(spec, net_settings).unwrap();
setup_rpc_server(service.client()); setup_rpc_server(service.client(), service.sync());
let io_handler = Arc::new(ClientIoHandler { client: service.client(), info: Default::default(), sync: service.sync() }); let io_handler = Arc::new(ClientIoHandler { client: service.client(), info: Default::default(), sync: service.sync() });
service.io().register_handler(io_handler).expect("Error registering IO handler"); service.io().register_handler(io_handler).expect("Error registering IO handler");

@ -1 +1 @@
Subproject commit e838fd90998fc5502d0b7c9427a4c231f9a6953d Subproject commit c670b1d8c9f09593a6758ab2c099360e16c7c25b

View File

@ -3,7 +3,7 @@ description = "Ethcore jsonrpc"
name = "ethcore-rpc" name = "ethcore-rpc"
version = "0.1.0" version = "0.1.0"
license = "GPL-3.0" license = "GPL-3.0"
authors = ["Marek Kotewicz <marek.kotewicz@gmail.com"] authors = ["Ethcore <admin@ethcore.io"]
[lib] [lib]
@ -15,4 +15,5 @@ jsonrpc-core = "1.1"
jsonrpc-http-server = "1.1" jsonrpc-http-server = "1.1"
ethcore-util = { path = "../util" } ethcore-util = { path = "../util" }
ethcore = { path = ".." } ethcore = { path = ".." }
clippy = "0.0.37"

View File

@ -1,19 +0,0 @@
//! Net rpc implementation.
use jsonrpc_core::*;
use traits::Net;
pub struct NetClient;
impl NetClient {
pub fn new() -> Self { NetClient }
}
impl Net for NetClient {
fn version(&self, _: Params) -> Result<Value, Error> {
Ok(Value::U64(63))
}
fn peer_count(&self, _params: Params) -> Result<Value, Error> {
Ok(Value::U64(0))
}
}

View File

@ -1,6 +1,8 @@
//! Ethcore rpc.
#![warn(missing_docs)]
#![feature(custom_derive, custom_attribute, plugin)] #![feature(custom_derive, custom_attribute, plugin)]
#![feature(slice_patterns)]
#![plugin(serde_macros)] #![plugin(serde_macros)]
#![plugin(clippy)]
extern crate serde; extern crate serde;
extern crate serde_json; extern crate serde_json;
@ -11,23 +13,16 @@ extern crate ethcore;
use self::jsonrpc_core::{IoHandler, IoDelegate}; use self::jsonrpc_core::{IoHandler, IoDelegate};
macro_rules! rpcerr { pub mod v1;
() => (Err(Error::internal_error()))
}
pub mod traits;
mod impls;
mod types;
pub use self::traits::{Web3, Eth, EthFilter, Net};
pub use self::impls::*;
/// Http server.
pub struct HttpServer { pub struct HttpServer {
handler: IoHandler, handler: IoHandler,
threads: usize threads: usize
} }
impl HttpServer { impl HttpServer {
/// Construct new http server object with given number of threads.
pub fn new(threads: usize) -> HttpServer { pub fn new(threads: usize) -> HttpServer {
HttpServer { HttpServer {
handler: IoHandler::new(), handler: IoHandler::new(),
@ -35,10 +30,12 @@ impl HttpServer {
} }
} }
/// Add io delegate.
pub fn add_delegate<D>(&mut self, delegate: IoDelegate<D>) where D: Send + Sync + 'static { pub fn add_delegate<D>(&mut self, delegate: IoDelegate<D>) where D: Send + Sync + 'static {
self.handler.add_delegate(delegate); self.handler.add_delegate(delegate);
} }
/// Start server asynchronously in new thread
pub fn start_async(self, addr: &str) { pub fn start_async(self, addr: &str) {
let server = jsonrpc_http_server::Server::new(self.handler, self.threads); let server = jsonrpc_http_server::Server::new(self.handler, self.threads);
server.start_async(addr) server.start_async(addr)

View File

@ -1,66 +0,0 @@
//! Eth rpc interface.
use std::sync::Arc;
use jsonrpc_core::*;
/// Eth rpc interface.
pub trait Eth: Sized + Send + Sync + 'static {
/// Returns protocol version.
fn protocol_version(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
/// Returns block author.
fn author(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
/// Returns current gas_price.
fn gas_price(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
/// Returns highest block number.
fn block_number(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
/// Returns block with given index / hash.
fn block(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
/// Returns true if client is actively mining new blocks.
fn is_mining(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
/// Returns the number of hashes per second that the node is mining with.
fn hashrate(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
/// Returns the number of transactions in a block.
fn block_transaction_count(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
/// Should be used to convert object to io delegate.
fn to_delegate(self) -> IoDelegate<Self> {
let mut delegate = IoDelegate::new(Arc::new(self));
delegate.add_method("eth_protocolVersion", Eth::protocol_version);
delegate.add_method("eth_coinbase", Eth::author);
delegate.add_method("eth_gasPrice", Eth::gas_price);
delegate.add_method("eth_blockNumber", Eth::block_number);
delegate.add_method("eth_getBlockByHash", Eth::block);
delegate.add_method("eth_getBlockByNumber", Eth::block);
delegate.add_method("eth_mining", Eth::is_mining);
delegate.add_method("eth_hashrate", Eth::hashrate);
delegate.add_method("eth_getBlockTransactionCountByNumber", Eth::block_transaction_count);
delegate
}
}
// TODO: do filters api properly
pub trait EthFilter: Sized + Send + Sync + 'static {
/// Returns id of new block filter
fn new_block_filter(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
/// Returns id of new block filter
fn new_pending_transaction_filter(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
/// Returns filter changes since last poll
fn filter_changes(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
/// Should be used to convert object to io delegate.
fn to_delegate(self) -> IoDelegate<Self> {
let mut delegate = IoDelegate::new(Arc::new(self));
delegate.add_method("eth_newBlockFilter", EthFilter::new_block_filter);
delegate.add_method("eth_newPendingTransactionFilter", EthFilter::new_pending_transaction_filter);
delegate.add_method("eth_getFilterChanges", EthFilter::filter_changes);
delegate
}
}

View File

@ -1,3 +1,4 @@
//! Eth rpc implementation.
use std::sync::Arc; use std::sync::Arc;
use jsonrpc_core::*; use jsonrpc_core::*;
use util::hash::*; use util::hash::*;
@ -5,14 +6,16 @@ use util::uint::*;
use util::sha3::*; use util::sha3::*;
use ethcore::client::*; use ethcore::client::*;
use ethcore::views::*; use ethcore::views::*;
use traits::{Eth, EthFilter}; use v1::traits::{Eth, EthFilter};
use types::Block; use v1::types::Block;
/// Eth rpc implementation.
pub struct EthClient { pub struct EthClient {
client: Arc<Client>, client: Arc<Client>,
} }
impl EthClient { impl EthClient {
/// Creates new EthClient.
pub fn new(client: Arc<Client>) -> Self { pub fn new(client: Arc<Client>) -> Self {
EthClient { EthClient {
client: client client: client
@ -100,11 +103,13 @@ impl Eth for EthClient {
} }
} }
/// Eth filter rpc implementation.
pub struct EthFilterClient { pub struct EthFilterClient {
client: Arc<Client> client: Arc<Client>
} }
impl EthFilterClient { impl EthFilterClient {
/// Creates new Eth filter client.
pub fn new(client: Arc<Client>) -> Self { pub fn new(client: Arc<Client>) -> Self {
EthFilterClient { EthFilterClient {
client: client client: client

29
rpc/src/v1/impls/net.rs Normal file
View File

@ -0,0 +1,29 @@
//! Net rpc implementation.
use std::sync::Arc;
use jsonrpc_core::*;
use ethcore::sync::EthSync;
use v1::traits::Net;
/// Net rpc implementation.
pub struct NetClient {
sync: Arc<EthSync>
}
impl NetClient {
/// Creates new NetClient.
pub fn new(sync: Arc<EthSync>) -> Self {
NetClient {
sync: sync
}
}
}
impl Net for NetClient {
fn version(&self, _: Params) -> Result<Value, Error> {
Ok(Value::U64(self.sync.status().protocol_version as u64))
}
fn peer_count(&self, _params: Params) -> Result<Value, Error> {
Ok(Value::U64(self.sync.status().num_peers as u64))
}
}

View File

@ -1,9 +1,12 @@
//! Web3 rpc implementation.
use jsonrpc_core::*; use jsonrpc_core::*;
use traits::Web3; use v1::traits::Web3;
/// Web3 rpc implementation.
pub struct Web3Client; pub struct Web3Client;
impl Web3Client { impl Web3Client {
/// Creates new Web3Client.
pub fn new() -> Self { Web3Client } pub fn new() -> Self { Web3Client }
} }

10
rpc/src/v1/mod.rs Normal file
View File

@ -0,0 +1,10 @@
//! Ethcore rpc v1.
//!
//! Compliant with ethereum rpc.
pub mod traits;
mod impls;
mod types;
pub use self::traits::{Web3, Eth, EthFilter, Net};
pub use self::impls::*;

163
rpc/src/v1/traits/eth.rs Normal file
View File

@ -0,0 +1,163 @@
//! Eth rpc interface.
use std::sync::Arc;
use jsonrpc_core::*;
/// Eth rpc interface.
pub trait Eth: Sized + Send + Sync + 'static {
/// Returns protocol version.
fn protocol_version(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns the number of hashes per second that the node is mining with.
fn hashrate(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns block author.
fn author(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns true if client is actively mining new blocks.
fn is_mining(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns current gas_price.
fn gas_price(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns accounts list.
fn accounts(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns highest block number.
fn block_number(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns balance of the given account.
fn balance(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns content of the storage at given address.
fn storage_at(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns block with given index / hash.
fn block(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns the number of transactions sent from given address at given time (block number).
fn transaction_count(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns the number of transactions in a block.
fn block_transaction_count(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns the number of uncles in a given block.
fn block_uncles_count(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns the code at given address at given time (block number).
fn code_at(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Sends transaction.
fn send_transaction(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Call contract.
fn call(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Estimate gas needed for execution of given contract.
fn estimate_gas(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns transaction at given block and index.
fn transaction_at(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns transaction receipt.
fn transaction_receipt(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns an uncles at given block and index.
fn uncle_at(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns available compilers.
fn compilers(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Compiles lll code.
fn compile_lll(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Compiles solidity.
fn compile_solidity(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Compiles serpent.
fn compile_serpent(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns logs matching given filter object.
fn logs(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns the hash of the current block, the seedHash, and the boundary condition to be met.
fn work(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Used for submitting a proof-of-work solution.
fn submit_work(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Used for submitting mining hashrate.
fn submit_hashrate(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Should be used to convert object to io delegate.
fn to_delegate(self) -> IoDelegate<Self> {
let mut delegate = IoDelegate::new(Arc::new(self));
delegate.add_method("eth_protocolVersion", Eth::protocol_version);
delegate.add_method("eth_hashrate", Eth::hashrate);
delegate.add_method("eth_coinbase", Eth::author);
delegate.add_method("eth_mining", Eth::is_mining);
delegate.add_method("eth_gasPrice", Eth::gas_price);
delegate.add_method("eth_accounts", Eth::accounts);
delegate.add_method("eth_blockNumber", Eth::block_number);
delegate.add_method("eth_balance", Eth::balance);
delegate.add_method("eth_getStorageAt", Eth::storage_at);
delegate.add_method("eth_getTransactionCount", Eth::transaction_count);
delegate.add_method("eth_getBlockTransactionCountByHash", Eth::block_transaction_count);
delegate.add_method("eth_getBlockTransactionCountByNumber", Eth::block_transaction_count);
delegate.add_method("eth_getUncleCountByBlockHash", Eth::block_uncles_count);
delegate.add_method("eth_getUncleCountByBlockNumber", Eth::block_uncles_count);
delegate.add_method("eth_code", Eth::code_at);
delegate.add_method("eth_sendTransaction", Eth::send_transaction);
delegate.add_method("eth_call", Eth::call);
delegate.add_method("eth_estimateGas", Eth::estimate_gas);
delegate.add_method("eth_getBlockByHash", Eth::block);
delegate.add_method("eth_getBlockByNumber", Eth::block);
delegate.add_method("eth_getTransactionByBlockHashAndIndex", Eth::transaction_at);
delegate.add_method("eth_getTransactionByBlockNumberAndIndex", Eth::transaction_at);
delegate.add_method("eth_getTransactionReceipt", Eth::transaction_receipt);
delegate.add_method("eth_getUncleByBlockHashAndIndex", Eth::uncle_at);
delegate.add_method("eth_getUncleByBlockNumberAndIndex", Eth::uncle_at);
delegate.add_method("eth_getCompilers", Eth::compilers);
delegate.add_method("eth_compileLLL", Eth::compile_lll);
delegate.add_method("eth_compileSolidity", Eth::compile_solidity);
delegate.add_method("eth_compileSerpent", Eth::compile_serpent);
delegate.add_method("eth_getLogs", Eth::logs);
delegate.add_method("eth_getWork", Eth::work);
delegate.add_method("eth_submitWork", Eth::submit_work);
delegate.add_method("eth_submitHashrate", Eth::submit_hashrate);
delegate
}
}
/// Eth filters rpc api (polling).
// TODO: do filters api properly
pub trait EthFilter: Sized + Send + Sync + 'static {
/// Returns id of new filter.
fn new_filter(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns id of new block filter.
fn new_block_filter(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns id of new block filter.
fn new_pending_transaction_filter(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns filter changes since last poll.
fn filter_changes(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns filter logs.
fn filter_logs(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Uninstalls filter.
fn uninstall_filter(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Should be used to convert object to io delegate.
fn to_delegate(self) -> IoDelegate<Self> {
let mut delegate = IoDelegate::new(Arc::new(self));
delegate.add_method("eth_newFilter", EthFilter::new_filter);
delegate.add_method("eth_newBlockFilter", EthFilter::new_block_filter);
delegate.add_method("eth_newPendingTransactionFilter", EthFilter::new_pending_transaction_filter);
delegate.add_method("eth_getFilterChanges", EthFilter::filter_changes);
delegate.add_method("eth_getFilterLogs", EthFilter::filter_logs);
delegate.add_method("eth_uninstallFilter", EthFilter::uninstall_filter);
delegate
}
}

View File

@ -1,4 +1,9 @@
//! Ethereum rpc interfaces. //! Ethereum rpc interfaces.
macro_rules! rpc_unimplemented {
() => (Err(Error::internal_error()))
}
pub mod web3; pub mod web3;
pub mod eth; pub mod eth;
pub mod net; pub mod net;

View File

@ -5,16 +5,21 @@ use jsonrpc_core::*;
/// Net rpc interface. /// Net rpc interface.
pub trait Net: Sized + Send + Sync + 'static { pub trait Net: Sized + Send + Sync + 'static {
/// Returns protocol version. /// Returns protocol version.
fn version(&self, _: Params) -> Result<Value, Error> { rpcerr!() } fn version(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns number of peers connected to node. /// Returns number of peers connected to node.
fn peer_count(&self, _: Params) -> Result<Value, Error> { rpcerr!() } fn peer_count(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns true if client is actively listening for network connections.
/// Otherwise false.
fn is_listening(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Should be used to convert object to io delegate. /// Should be used to convert object to io delegate.
fn to_delegate(self) -> IoDelegate<Self> { fn to_delegate(self) -> IoDelegate<Self> {
let mut delegate = IoDelegate::new(Arc::new(self)); let mut delegate = IoDelegate::new(Arc::new(self));
delegate.add_method("net_version", Net::version); delegate.add_method("net_version", Net::version);
delegate.add_method("net_peerCount", Net::peer_count); delegate.add_method("net_peerCount", Net::peer_count);
delegate.add_method("net_listening", Net::is_listening);
delegate delegate
} }
} }

View File

@ -5,7 +5,7 @@ use jsonrpc_core::*;
/// Web3 rpc interface. /// Web3 rpc interface.
pub trait Web3: Sized + Send + Sync + 'static { pub trait Web3: Sized + Send + Sync + 'static {
/// Returns current client version. /// Returns current client version.
fn client_version(&self, _: Params) -> Result<Value, Error> { rpcerr!() } fn client_version(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Should be used to convert object to io delegate. /// Should be used to convert object to io delegate.
fn to_delegate(self) -> IoDelegate<Self> { fn to_delegate(self) -> IoDelegate<Self> {

View File

@ -215,7 +215,13 @@ impl<'a> Ext for Externalities<'a> {
fn suicide(&mut self, refund_address: &Address) { fn suicide(&mut self, refund_address: &Address) {
let address = self.origin_info.address.clone(); let address = self.origin_info.address.clone();
let balance = self.balance(&address); let balance = self.balance(&address);
self.state.transfer_balance(&address, refund_address, &balance); if &address == refund_address {
// TODO [todr] To be consisted with CPP client we set balance to 0 in that case.
self.state.sub_balance(&address, &balance);
} else {
trace!("Suiciding {} -> {} (xfer: {})", address, refund_address, balance);
self.state.transfer_balance(&address, refund_address, &balance);
}
self.substate.suicides.insert(address); self.substate.suicides.insert(address);
} }

View File

@ -5,7 +5,12 @@ use block::Block;
use ethereum; use ethereum;
use super::helpers::*; use super::helpers::*;
fn do_json_test(json_data: &[u8]) -> Vec<String> { pub enum ChainEra {
Frontier,
Homestead,
}
pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
let json = Json::from_str(::std::str::from_utf8(json_data).unwrap()).expect("Json is invalid"); let json = Json::from_str(::std::str::from_utf8(json_data).unwrap()).expect("Json is invalid");
let mut failed = Vec::new(); let mut failed = Vec::new();
@ -22,7 +27,10 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
flush(format!(" - {}...", name)); flush(format!(" - {}...", name));
let blocks: Vec<(Bytes, bool)> = test["blocks"].as_array().unwrap().iter().map(|e| (xjson!(&e["rlp"]), e.find("blockHeader").is_some())).collect(); let blocks: Vec<(Bytes, bool)> = test["blocks"].as_array().unwrap().iter().map(|e| (xjson!(&e["rlp"]), e.find("blockHeader").is_some())).collect();
let mut spec = ethereum::new_frontier_like_test(); let mut spec = match era {
ChainEra::Frontier => ethereum::new_frontier_test(),
ChainEra::Homestead => ethereum::new_homestead_test(),
};
let s = PodState::from_json(test.find("pre").unwrap()); let s = PodState::from_json(test.find("pre").unwrap());
spec.set_genesis_state(s); spec.set_genesis_state(s);
spec.overwrite_genesis(test.find("genesisBlockHeader").unwrap()); spec.overwrite_genesis(test.find("genesisBlockHeader").unwrap());
@ -50,6 +58,10 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
failed failed
} }
fn do_json_test(json_data: &[u8]) -> Vec<String> {
json_chain_test(json_data, ChainEra::Frontier)
}
declare_test!{BlockchainTests_bcBlockGasLimitTest, "BlockchainTests/bcBlockGasLimitTest"} declare_test!{BlockchainTests_bcBlockGasLimitTest, "BlockchainTests/bcBlockGasLimitTest"}
declare_test!{BlockchainTests_bcForkBlockTest, "BlockchainTests/bcForkBlockTest"} declare_test!{BlockchainTests_bcForkBlockTest, "BlockchainTests/bcForkBlockTest"}
declare_test!{BlockchainTests_bcForkStressTest, "BlockchainTests/bcForkStressTest"} declare_test!{BlockchainTests_bcForkStressTest, "BlockchainTests/bcForkStressTest"}
@ -65,3 +77,6 @@ declare_test!{BlockchainTests_bcUncleHeaderValiditiy, "BlockchainTests/bcUncleHe
declare_test!{BlockchainTests_bcUncleTest, "BlockchainTests/bcUncleTest"} declare_test!{BlockchainTests_bcUncleTest, "BlockchainTests/bcUncleTest"}
declare_test!{BlockchainTests_bcValidBlockTest, "BlockchainTests/bcValidBlockTest"} declare_test!{BlockchainTests_bcValidBlockTest, "BlockchainTests/bcValidBlockTest"}
declare_test!{BlockchainTests_bcWalletTest, "BlockchainTests/bcWalletTest"} declare_test!{BlockchainTests_bcWalletTest, "BlockchainTests/bcWalletTest"}
declare_test!{BlockchainTests_RandomTests_bl10251623GO, "BlockchainTests/RandomTests/bl10251623GO"}
declare_test!{BlockchainTests_RandomTests_bl201507071825GO, "BlockchainTests/RandomTests/bl201507071825GO"}

View File

@ -0,0 +1,20 @@
use super::test_common::*;
use super::chain::{ChainEra, json_chain_test};
fn do_json_test(json_data: &[u8]) -> Vec<String> {
json_chain_test(json_data, ChainEra::Homestead)
}
declare_test!{BlockchainTests_Homestead_bcBlockGasLimitTest, "BlockchainTests/Homestead/bcBlockGasLimitTest"}
declare_test!{BlockchainTests_Homestead_bcForkStressTest, "BlockchainTests/Homestead/bcForkStressTest"}
declare_test!{BlockchainTests_Homestead_bcGasPricerTest, "BlockchainTests/Homestead/bcGasPricerTest"}
declare_test!{BlockchainTests_Homestead_bcInvalidHeaderTest, "BlockchainTests/Homestead/bcInvalidHeaderTest"}
declare_test!{BlockchainTests_Homestead_bcInvalidRLPTest, "BlockchainTests/Homestead/bcInvalidRLPTest"}
declare_test!{BlockchainTests_Homestead_bcMultiChainTest, "BlockchainTests/Homestead/bcMultiChainTest"}
declare_test!{BlockchainTests_Homestead_bcRPC_API_Test, "BlockchainTests/Homestead/bcRPC_API_Test"}
declare_test!{BlockchainTests_Homestead_bcStateTest, "BlockchainTests/Homestead/bcStateTest"}
declare_test!{BlockchainTests_Homestead_bcTotalDifficultyTest, "BlockchainTests/Homestead/bcTotalDifficultyTest"}
declare_test!{BlockchainTests_Homestead_bcUncleHeaderValiditiy, "BlockchainTests/Homestead/bcUncleHeaderValiditiy"}
declare_test!{BlockchainTests_Homestead_bcUncleTest, "BlockchainTests/Homestead/bcUncleTest"}
declare_test!{BlockchainTests_Homestead_bcValidBlockTest, "BlockchainTests/Homestead/bcValidBlockTest"}
declare_test!{BlockchainTests_Homestead_bcWalletTest, "BlockchainTests/Homestead/bcWalletTest"}

View File

@ -6,4 +6,5 @@ mod executive;
mod state; mod state;
mod client; mod client;
mod chain; mod chain;
pub mod helpers; pub mod helpers;
mod homestead_chain;

View File

@ -26,7 +26,7 @@ crossbeam = "0.2"
slab = { git = "https://github.com/arkpar/slab.git" } slab = { git = "https://github.com/arkpar/slab.git" }
sha3 = { path = "sha3" } sha3 = { path = "sha3" }
serde = "0.6.7" serde = "0.6.7"
clippy = "*" # Always newest, since we use nightly clippy = "0.0.37"
[dev-dependencies] [dev-dependencies]
json-tests = { path = "json-tests" } json-tests = { path = "json-tests" }