Merge pull request #822 from ethcore/netidfix

Use network id for the web3_net_version return.
This commit is contained in:
Gav Wood 2016-03-26 11:25:09 +01:00
commit af14c68acc
5 changed files with 13 additions and 7 deletions

View File

@ -36,7 +36,7 @@ impl<S> NetClient<S> where S: SyncProvider {
impl<S> Net for NetClient<S> where S: SyncProvider + 'static {
fn version(&self, _: Params) -> Result<Value, Error> {
Ok(Value::String(format!("{}", take_weak!(self.sync).status().protocol_version).to_owned()))
Ok(Value::String(format!("{}", take_weak!(self.sync).status().network_id).to_owned()))
}
fn peer_count(&self, _params: Params) -> Result<Value, Error> {

View File

@ -40,7 +40,7 @@ fn accounts_provider() -> Arc<TestAccountProvider> {
fn sync_provider() -> Arc<TestSyncProvider> {
Arc::new(TestSyncProvider::new(Config {
protocol_version: 65,
network_id: U256::from(3),
num_peers: 120,
}))
}
@ -83,7 +83,7 @@ impl Default for EthTester {
#[test]
fn rpc_eth_protocol_version() {
let request = r#"{"jsonrpc": "2.0", "method": "eth_protocolVersion", "params": [], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":"65","id":1}"#;
let response = r#"{"jsonrpc":"2.0","result":"63","id":1}"#;
assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned()));
}

View File

@ -16,13 +16,14 @@
//! Test implementation of SyncProvider.
use util::U256;
use ethsync::{SyncProvider, SyncStatus, SyncState};
use std::sync::{RwLock};
/// TestSyncProvider config.
pub struct Config {
/// Protocol version.
pub protocol_version: u8,
pub network_id: U256,
/// Number of peers.
pub num_peers: usize,
}
@ -39,7 +40,8 @@ impl TestSyncProvider {
TestSyncProvider {
status: RwLock::new(SyncStatus {
state: SyncState::NotSynced,
protocol_version: config.protocol_version,
network_id: config.network_id,
protocol_version: 63,
start_block_number: 0,
last_imported_block_number: None,
highest_block_number: None,

View File

@ -18,10 +18,11 @@ use std::sync::Arc;
use jsonrpc_core::IoHandler;
use v1::{Net, NetClient};
use v1::tests::helpers::{Config, TestSyncProvider};
use util::numbers::*;
fn sync_provider() -> Arc<TestSyncProvider> {
Arc::new(TestSyncProvider::new(Config {
protocol_version: 65,
network_id: U256::from(3),
num_peers: 120,
}))
}
@ -34,7 +35,7 @@ fn rpc_net_version() {
io.add_delegate(net);
let request = r#"{"jsonrpc": "2.0", "method": "net_version", "params": [], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":"65","id":1}"#;
let response = r#"{"jsonrpc":"2.0","result":"3","id":1}"#;
assert_eq!(io.handle_request(request), Some(response.to_owned()));
}

View File

@ -125,6 +125,8 @@ pub struct SyncStatus {
pub state: SyncState,
/// Syncing protocol version. That's the maximum protocol version we connect to.
pub protocol_version: u8,
/// The underlying p2p network version.
pub network_id: U256,
/// BlockChain height for the moment the sync started.
pub start_block_number: BlockNumber,
/// Last fully downloaded and imported block number (if any).
@ -249,6 +251,7 @@ impl ChainSync {
SyncStatus {
state: self.state.clone(),
protocol_version: 63,
network_id: self.network_id,
start_block_number: self.starting_block,
last_imported_block_number: self.last_imported_block,
highest_block_number: self.highest_block,