Fix mock tests.

This commit is contained in:
Gav Wood 2016-05-30 11:53:20 +02:00
parent af05939d74
commit 11f4e8cb73
3 changed files with 47 additions and 22 deletions

View File

@ -26,7 +26,6 @@ use ethminer::MinerService;
use ethcore::client::BlockChainClient; use ethcore::client::BlockChainClient;
use ethcore::trace::VMTrace; use ethcore::trace::VMTrace;
use ethcore::transaction::{Transaction as EthTransaction, SignedTransaction, Action}; use ethcore::transaction::{Transaction as EthTransaction, SignedTransaction, Action};
use ethcore::get_info;
use v1::traits::Ethcore; use v1::traits::Ethcore;
use v1::types::{Bytes, CallRequest}; use v1::types::{Bytes, CallRequest};
@ -81,8 +80,7 @@ fn vm_trace_to_object(t: &VMTrace) -> Value {
.map(|(i, op)| { .map(|(i, op)| {
let mut m = map![ let mut m = map![
"pc".to_owned() => to_value(&op.pc).unwrap(), "pc".to_owned() => to_value(&op.pc).unwrap(),
"inst".to_owned() => to_value(&get_info(op.instruction).name).unwrap(), "cost".to_owned() => to_value(&op.gas_cost).unwrap(),
"gas_cost".to_owned() => to_value(&op.gas_cost).unwrap(),
"stack".to_owned() => to_value(&op.stack).unwrap() "stack".to_owned() => to_value(&op.stack).unwrap()
]; ];
if next_sub.is_some() && next_sub.unwrap().parent_step == i { if next_sub.is_some() && next_sub.unwrap().parent_step == i {

View File

@ -353,6 +353,7 @@ fn rpc_eth_call() {
contracts_created: vec![], contracts_created: vec![],
output: vec![0x12, 0x34, 0xff], output: vec![0x12, 0x34, 0xff],
trace: None, trace: None,
vm_trace: None,
}); });
let request = r#"{ let request = r#"{
@ -386,6 +387,7 @@ fn rpc_eth_call_default_block() {
contracts_created: vec![], contracts_created: vec![],
output: vec![0x12, 0x34, 0xff], output: vec![0x12, 0x34, 0xff],
trace: None, trace: None,
vm_trace: None,
}); });
let request = r#"{ let request = r#"{
@ -418,6 +420,7 @@ fn rpc_eth_estimate_gas() {
contracts_created: vec![], contracts_created: vec![],
output: vec![0x12, 0x34, 0xff], output: vec![0x12, 0x34, 0xff],
trace: None, trace: None,
vm_trace: None,
}); });
let request = r#"{ let request = r#"{
@ -451,6 +454,7 @@ fn rpc_eth_estimate_gas_default_block() {
contracts_created: vec![], contracts_created: vec![],
output: vec![0x12, 0x34, 0xff], output: vec![0x12, 0x34, 0xff],
trace: None, trace: None,
vm_trace: None,
}); });
let request = r#"{ let request = r#"{

View File

@ -19,16 +19,22 @@ use std::str::FromStr;
use jsonrpc_core::IoHandler; use jsonrpc_core::IoHandler;
use v1::{Ethcore, EthcoreClient}; use v1::{Ethcore, EthcoreClient};
use ethminer::MinerService; use ethminer::MinerService;
use ethcore::client::{TestBlockChainClient};
use v1::tests::helpers::TestMinerService; use v1::tests::helpers::TestMinerService;
use util::numbers::*; use util::numbers::*;
use rustc_serialize::hex::FromHex; use rustc_serialize::hex::FromHex;
use util::log::RotatingLogger; use util::log::RotatingLogger;
use util::network_settings::NetworkSettings; use util::network_settings::NetworkSettings;
fn blockchain_client() -> Arc<TestBlockChainClient> {
let client = TestBlockChainClient::new();
Arc::new(client)
}
fn miner_service() -> Arc<TestMinerService> { fn miner_service() -> Arc<TestMinerService> {
Arc::new(TestMinerService::default()) Arc::new(TestMinerService::default())
} }
fn logger() -> Arc<RotatingLogger> { fn logger() -> Arc<RotatingLogger> {
Arc::new(RotatingLogger::new("rpc=trace".to_owned())) Arc::new(RotatingLogger::new("rpc=trace".to_owned()))
} }
@ -45,14 +51,15 @@ fn settings() -> Arc<NetworkSettings> {
}) })
} }
fn ethcore_client(miner: &Arc<TestMinerService>) -> EthcoreClient<TestMinerService> { fn ethcore_client(client: &Arc<TestBlockChainClient>, miner: &Arc<TestMinerService>) -> EthcoreClient<TestBlockChainClient, TestMinerService> {
EthcoreClient::new(&miner, logger(), settings()) EthcoreClient::new(&client, &miner, logger(), settings())
} }
#[test] #[test]
fn rpc_ethcore_extra_data() { fn rpc_ethcore_extra_data() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate(); let client = blockchain_client();
let ethcore = ethcore_client(&client, &miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore);
@ -68,7 +75,8 @@ fn rpc_ethcore_default_extra_data() {
use util::ToPretty; use util::ToPretty;
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate(); let client = blockchain_client();
let ethcore = ethcore_client(&client, &miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore);
@ -81,7 +89,8 @@ fn rpc_ethcore_default_extra_data() {
#[test] #[test]
fn rpc_ethcore_gas_floor_target() { fn rpc_ethcore_gas_floor_target() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate(); let client = blockchain_client();
let ethcore = ethcore_client(&client, &miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore);
@ -94,7 +103,8 @@ fn rpc_ethcore_gas_floor_target() {
#[test] #[test]
fn rpc_ethcore_min_gas_price() { fn rpc_ethcore_min_gas_price() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate(); let client = blockchain_client();
let ethcore = ethcore_client(&client, &miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore);
@ -107,7 +117,8 @@ fn rpc_ethcore_min_gas_price() {
#[test] #[test]
fn rpc_ethcore_set_min_gas_price() { fn rpc_ethcore_set_min_gas_price() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate(); let client = blockchain_client();
let ethcore = ethcore_client(&client, &miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore);
@ -121,7 +132,8 @@ fn rpc_ethcore_set_min_gas_price() {
#[test] #[test]
fn rpc_ethcore_set_gas_floor_target() { fn rpc_ethcore_set_gas_floor_target() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate(); let client = blockchain_client();
let ethcore = ethcore_client(&client, &miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore);
@ -135,7 +147,8 @@ fn rpc_ethcore_set_gas_floor_target() {
#[test] #[test]
fn rpc_ethcore_set_extra_data() { fn rpc_ethcore_set_extra_data() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate(); let client = blockchain_client();
let ethcore = ethcore_client(&client, &miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore);
@ -149,7 +162,8 @@ fn rpc_ethcore_set_extra_data() {
#[test] #[test]
fn rpc_ethcore_set_author() { fn rpc_ethcore_set_author() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate(); let client = blockchain_client();
let ethcore = ethcore_client(&client, &miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore);
@ -163,10 +177,11 @@ fn rpc_ethcore_set_author() {
#[test] #[test]
fn rpc_ethcore_dev_logs() { fn rpc_ethcore_dev_logs() {
let miner = miner_service(); let miner = miner_service();
let client = blockchain_client();
let logger = logger(); let logger = logger();
logger.append("a".to_owned()); logger.append("a".to_owned());
logger.append("b".to_owned()); logger.append("b".to_owned());
let ethcore = EthcoreClient::new(&miner, logger.clone(), settings()).to_delegate(); let ethcore = EthcoreClient::new(&client, &miner, logger.clone(), settings()).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore);
@ -179,7 +194,8 @@ fn rpc_ethcore_dev_logs() {
#[test] #[test]
fn rpc_ethcore_dev_logs_levels() { fn rpc_ethcore_dev_logs_levels() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate(); let client = blockchain_client();
let ethcore = ethcore_client(&client, &miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore);
@ -191,7 +207,8 @@ fn rpc_ethcore_dev_logs_levels() {
#[test] #[test]
fn rpc_ethcore_set_transactions_limit() { fn rpc_ethcore_set_transactions_limit() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate(); let client = blockchain_client();
let ethcore = ethcore_client(&client, &miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore);
@ -205,7 +222,8 @@ fn rpc_ethcore_set_transactions_limit() {
#[test] #[test]
fn rpc_ethcore_transactions_limit() { fn rpc_ethcore_transactions_limit() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate(); let client = blockchain_client();
let ethcore = ethcore_client(&client, &miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore);
@ -218,7 +236,8 @@ fn rpc_ethcore_transactions_limit() {
#[test] #[test]
fn rpc_ethcore_net_chain() { fn rpc_ethcore_net_chain() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate(); let client = blockchain_client();
let ethcore = ethcore_client(&client, &miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore);
@ -231,7 +250,8 @@ fn rpc_ethcore_net_chain() {
#[test] #[test]
fn rpc_ethcore_net_max_peers() { fn rpc_ethcore_net_max_peers() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate(); let client = blockchain_client();
let ethcore = ethcore_client(&client, &miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore);
@ -244,7 +264,8 @@ fn rpc_ethcore_net_max_peers() {
#[test] #[test]
fn rpc_ethcore_net_port() { fn rpc_ethcore_net_port() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate(); let client = blockchain_client();
let ethcore = ethcore_client(&client, &miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore);
@ -257,7 +278,8 @@ fn rpc_ethcore_net_port() {
#[test] #[test]
fn rpc_ethcore_rpc_settings() { fn rpc_ethcore_rpc_settings() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate(); let client = blockchain_client();
let ethcore = ethcore_client(&client, &miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore);
@ -270,7 +292,8 @@ fn rpc_ethcore_rpc_settings() {
#[test] #[test]
fn rpc_ethcore_node_name() { fn rpc_ethcore_node_name() {
let miner = miner_service(); let miner = miner_service();
let ethcore = ethcore_client(&miner).to_delegate(); let client = blockchain_client();
let ethcore = ethcore_client(&client, &miner).to_delegate();
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(ethcore); io.add_delegate(ethcore);