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

Add RPC eth_symbol test (eip-3014) #11885

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions rpc/src/v1/impls/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
Ok(self.client.signing_chain_id().map(U64::from))
}

fn symbol(&self) -> Result<String> {
// TODO: symbol should be configurable
Ok("ETH".to_string())
}

fn hashrate(&self) -> Result<U256> {
Ok(self.external_miner.hashrate())
}
Expand Down
5 changes: 5 additions & 0 deletions rpc/src/v1/impls/light/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ where
Ok(self.client.signing_chain_id().map(U64::from))
}

fn symbol(&self) -> Result<String> {
// TODO: symbol should be configurable
Ok("ETH".to_string())
}

fn hashrate(&self) -> Result<U256> {
Ok(Default::default())
}
Expand Down
9 changes: 9 additions & 0 deletions rpc/src/v1/tests/mocked/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ fn rpc_eth_chain_id() {
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
}

#[test]
fn rpc_eth_symbol() {
let tester = EthTester::default();
let request = r#"{"jsonrpc": "2.0", "method": "eth_symbol", "params": [], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":null,"id":1}"#;

assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
}

#[test]
fn rpc_eth_hashrate() {
let tester = EthTester::default();
Expand Down
4 changes: 4 additions & 0 deletions rpc/src/v1/traits/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ pub trait Eth {
#[rpc(name = "eth_chainId")]
fn chain_id(&self) -> Result<Option<U64>>;

/// Returns native coin symbol.
#[rpc(name = "eth_symbol")]
fn symbol(&self) -> Result<String>;

/// Returns current gas_price.
#[rpc(name = "eth_gasPrice")]
fn gas_price(&self) -> BoxFuture<U256>;
Expand Down