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

Commit

Permalink
fix rpc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rphmeier committed Jun 20, 2016
1 parent 5f1ce7f commit 3696f57
Showing 1 changed file with 42 additions and 19 deletions.
61 changes: 42 additions & 19 deletions rpc/src/v1/tests/mocked/ethcore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ use std::str::FromStr;
use jsonrpc_core::IoHandler;
use v1::{Ethcore, EthcoreClient, EthcoreSet, EthcoreSetClient};
use ethcore::miner::MinerService;
use ethcore::service::SyncMessage;
use v1::tests::helpers::TestMinerService;
use ethcore::client::{TestBlockChainClient};
use util::numbers::*;
use rustc_serialize::hex::FromHex;
use util::log::RotatingLogger;
use util::network::{NetworkConfiguration, NetworkService};
use util::network_settings::NetworkSettings;

fn miner_service() -> Arc<TestMinerService> {
Expand All @@ -50,21 +52,26 @@ fn settings() -> Arc<NetworkSettings> {
})
}

fn network_service() -> Arc<NetworkService<SyncMessage>> {
Arc::new(NetworkService::new(NetworkConfiguration::new()).unwrap())
}

fn ethcore_client(client: &Arc<TestBlockChainClient>, miner: &Arc<TestMinerService>) -> EthcoreClient<TestBlockChainClient, TestMinerService> {
EthcoreClient::new(client, miner, logger(), settings())
}

fn ethcore_set_client(miner: &Arc<TestMinerService>) -> EthcoreSetClient<TestMinerService> {
EthcoreSetClient::new(miner)
fn ethcore_set_client(miner: &Arc<TestMinerService>, net: &Arc<NetworkService<SyncMessage>>) -> EthcoreSetClient<TestMinerService> {
EthcoreSetClient::new(miner, net)
}

#[test]
fn rpc_ethcore_extra_data() {
let miner = miner_service();
let client = client_service();
let network = network_service();
let io = IoHandler::new();
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner, &network).to_delegate());

let request = r#"{"jsonrpc": "2.0", "method": "ethcore_extraData", "params": [], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":"0x01020304","id":1}"#;
Expand All @@ -79,9 +86,10 @@ fn rpc_ethcore_default_extra_data() {

let miner = miner_service();
let client = client_service();
let network = network_service();
let io = IoHandler::new();
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner, &network).to_delegate());

let request = r#"{"jsonrpc": "2.0", "method": "ethcore_defaultExtraData", "params": [], "id": 1}"#;
let response = format!(r#"{{"jsonrpc":"2.0","result":"0x{}","id":1}}"#, misc::version_data().to_hex());
Expand All @@ -93,9 +101,10 @@ fn rpc_ethcore_default_extra_data() {
fn rpc_ethcore_gas_floor_target() {
let miner = miner_service();
let client = client_service();
let network = network_service();
let io = IoHandler::new();
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner, &network).to_delegate());

let request = r#"{"jsonrpc": "2.0", "method": "ethcore_gasFloorTarget", "params": [], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":"0x3039","id":1}"#;
Expand All @@ -107,9 +116,10 @@ fn rpc_ethcore_gas_floor_target() {
fn rpc_ethcore_min_gas_price() {
let miner = miner_service();
let client = client_service();
let network = network_service();
let io = IoHandler::new();
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner, &network).to_delegate());

let request = r#"{"jsonrpc": "2.0", "method": "ethcore_minGasPrice", "params": [], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":"0x01312d00","id":1}"#;
Expand All @@ -121,9 +131,10 @@ fn rpc_ethcore_min_gas_price() {
fn rpc_ethcore_set_min_gas_price() {
let miner = miner_service();
let client = client_service();
let network = network_service();
let io = IoHandler::new();
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner, &network).to_delegate());

let request = r#"{"jsonrpc": "2.0", "method": "ethcore_setMinGasPrice", "params":["0xcd1722f3947def4cf144679da39c4c32bdc35681"], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
Expand All @@ -136,9 +147,10 @@ fn rpc_ethcore_set_min_gas_price() {
fn rpc_ethcore_set_gas_floor_target() {
let miner = miner_service();
let client = client_service();
let network = network_service();
let io = IoHandler::new();
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner, &network).to_delegate());

let request = r#"{"jsonrpc": "2.0", "method": "ethcore_setGasFloorTarget", "params":["0xcd1722f3947def4cf144679da39c4c32bdc35681"], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
Expand All @@ -151,9 +163,10 @@ fn rpc_ethcore_set_gas_floor_target() {
fn rpc_ethcore_set_extra_data() {
let miner = miner_service();
let client = client_service();
let network = network_service();
let io = IoHandler::new();
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner, &network).to_delegate());

let request = r#"{"jsonrpc": "2.0", "method": "ethcore_setExtraData", "params":["0xcd1722f3947def4cf144679da39c4c32bdc35681"], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
Expand All @@ -166,9 +179,10 @@ fn rpc_ethcore_set_extra_data() {
fn rpc_ethcore_set_author() {
let miner = miner_service();
let client = client_service();
let network = network_service();
let io = IoHandler::new();
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner, &network).to_delegate());

let request = r#"{"jsonrpc": "2.0", "method": "ethcore_setAuthor", "params":["0xcd1722f3947def4cf144679da39c4c32bdc35681"], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
Expand All @@ -181,13 +195,14 @@ fn rpc_ethcore_set_author() {
fn rpc_ethcore_dev_logs() {
let miner = miner_service();
let client = client_service();
let network = network_service();
let logger = logger();
logger.append("a".to_owned());
logger.append("b".to_owned());
let ethcore = EthcoreClient::new(&client, &miner, logger.clone(), settings()).to_delegate();
let io = IoHandler::new();
io.add_delegate(ethcore);
io.add_delegate(ethcore_set_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner, &network).to_delegate());

let request = r#"{"jsonrpc": "2.0", "method": "ethcore_devLogs", "params":[], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":["b","a"],"id":1}"#;
Expand All @@ -199,9 +214,10 @@ fn rpc_ethcore_dev_logs() {
fn rpc_ethcore_dev_logs_levels() {
let miner = miner_service();
let client = client_service();
let network = network_service();
let io = IoHandler::new();
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner, &network).to_delegate());

let request = r#"{"jsonrpc": "2.0", "method": "ethcore_devLogsLevels", "params":[], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":"rpc=trace","id":1}"#;
Expand All @@ -212,9 +228,10 @@ fn rpc_ethcore_dev_logs_levels() {
fn rpc_ethcore_set_transactions_limit() {
let miner = miner_service();
let client = client_service();
let network = network_service();
let io = IoHandler::new();
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner, &network).to_delegate());

let request = r#"{"jsonrpc": "2.0", "method": "ethcore_setTransactionsLimit", "params":[10240240], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
Expand All @@ -227,9 +244,10 @@ fn rpc_ethcore_set_transactions_limit() {
fn rpc_ethcore_transactions_limit() {
let miner = miner_service();
let client = client_service();
let network = network_service();
let io = IoHandler::new();
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner, &network).to_delegate());

let request = r#"{"jsonrpc": "2.0", "method": "ethcore_transactionsLimit", "params":[], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":1024,"id":1}"#;
Expand All @@ -241,9 +259,10 @@ fn rpc_ethcore_transactions_limit() {
fn rpc_ethcore_net_chain() {
let miner = miner_service();
let client = client_service();
let network = network_service();
let io = IoHandler::new();
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner, &network).to_delegate());

let request = r#"{"jsonrpc": "2.0", "method": "ethcore_netChain", "params":[], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":"testchain","id":1}"#;
Expand All @@ -255,9 +274,10 @@ fn rpc_ethcore_net_chain() {
fn rpc_ethcore_net_max_peers() {
let miner = miner_service();
let client = client_service();
let network = network_service();
let io = IoHandler::new();
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner, &network).to_delegate());

let request = r#"{"jsonrpc": "2.0", "method": "ethcore_netMaxPeers", "params":[], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":25,"id":1}"#;
Expand All @@ -269,9 +289,10 @@ fn rpc_ethcore_net_max_peers() {
fn rpc_ethcore_net_port() {
let miner = miner_service();
let client = client_service();
let network = network_service();
let io = IoHandler::new();
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner, &network).to_delegate());

let request = r#"{"jsonrpc": "2.0", "method": "ethcore_netPort", "params":[], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":30303,"id":1}"#;
Expand All @@ -283,9 +304,10 @@ fn rpc_ethcore_net_port() {
fn rpc_ethcore_rpc_settings() {
let miner = miner_service();
let client = client_service();
let network = network_service();
let io = IoHandler::new();
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner, &network).to_delegate());

let request = r#"{"jsonrpc": "2.0", "method": "ethcore_rpcSettings", "params":[], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":{"enabled":true,"interface":"all","port":8545},"id":1}"#;
Expand All @@ -297,9 +319,10 @@ fn rpc_ethcore_rpc_settings() {
fn rpc_ethcore_node_name() {
let miner = miner_service();
let client = client_service();
let network = network_service();
let io = IoHandler::new();
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner).to_delegate());
io.add_delegate(ethcore_set_client(&miner, &network).to_delegate());

let request = r#"{"jsonrpc": "2.0", "method": "ethcore_nodeName", "params":[], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":"mynode","id":1}"#;
Expand Down

0 comments on commit 3696f57

Please sign in to comment.