From fee3152511d79cc53ffd7f9b71c01f09287242f8 Mon Sep 17 00:00:00 2001 From: George W <140627974+grw-ms@users.noreply.github.com> Date: Thu, 7 Sep 2023 19:30:48 +0200 Subject: [PATCH] feat: impl `eth_syncing` (#104) * eth_api: Implement syncing method * tests: test eth_syncing * docs: mark eth_syncing as SUPPORTED * docs: add eth_syncing to test_endpoints.http * docs: add example for eth_syncing --- SUPPORTED_APIS.md | 26 +++++++++++++++++++++++++- src/node.rs | 16 +++++++++++++++- test_endpoints.http | 11 +++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/SUPPORTED_APIS.md b/SUPPORTED_APIS.md index 1969a403..1485b263 100644 --- a/SUPPORTED_APIS.md +++ b/SUPPORTED_APIS.md @@ -70,7 +70,7 @@ The `status` options are: | `ETH` | `eth_submitHashrate` | `NOT IMPLEMENTED` | Used for submitting mining hashrate | | `ETH` | `eth_submitWork` | `NOT IMPLEMENTED` | Used for submitting a proof-of-work solution | | `ETH` | `eth_subscribe` | `NOT IMPLEMENTED` | Starts a subscription to a particular event | -| `ETH` | `eth_syncing` | `NOT IMPLEMENTED`
[GitHub Issue #49](https://github.com/matter-labs/era-test-node/issues/49) | Returns an object containing data about the sync status or `false` when not syncing | +| [`ETH`](#eth-namespace) | [`eth_syncing`](#eth_syncing) | `SUPPORTED` | Returns an object containing data about the sync status or `false` when not syncing | | `ETH` | `eth_uninstallFilter` | `NOT IMPLEMENTED`
[GitHub Issue #38](https://github.com/matter-labs/era-test-node/issues/38) | Uninstalls a filter with given id | | `ETH` | `eth_unsubscribe` | `NOT IMPLEMENTED` | Cancel a subscription to a particular event | | `EVM` | `evm_addAccount` | `NOT IMPLEMENTED` | Adds any arbitrary account | @@ -683,6 +683,30 @@ curl --request POST \ }' ``` +### `eth_syncing` + +[source](src/node.rs) + +Returns syncing status of the node. This will always return `false`. + +#### Arguments + ++ _NONE_ + +#### Status + +`SUPPORTED` + +#### Example + +```bash +curl --request POST \ + --url http://localhost:8011/ \ + --header 'content-type: application/json' \ + --data '{"jsonrpc": "2.0","id": "1","method": "eth_syncing","params": [] +}' +``` + ## `HARDHAT NAMESPACE` ### `hardhat_setBalance` diff --git a/src/node.rs b/src/node.rs index 12afbfc7..c6352452 100644 --- a/src/node.rs +++ b/src/node.rs @@ -1715,7 +1715,7 @@ impl EthNamespaceT for &self, ) -> jsonrpc_core::BoxFuture> { - not_implemented("syncing") + Ok(zksync_basic_types::web3::types::SyncState::NotSyncing).into_boxed_future() } fn accounts( @@ -1765,3 +1765,17 @@ impl EthNamespaceT for not_implemented("fee history") } } + +#[cfg(test)] +mod tests { + use crate::{http_fork_source::HttpForkSource, node::InMemoryNode}; + use zksync_core::api_server::web3::backend_jsonrpc::namespaces::eth::EthNamespaceT; + use zksync_web3_decl::types::SyncState; + + #[tokio::test] + async fn test_eth_syncing() { + let node = InMemoryNode::::default(); + let syncing = node.syncing().await.expect("failed syncing"); + assert!(matches!(syncing, SyncState::NotSyncing)); + } +} diff --git a/test_endpoints.http b/test_endpoints.http index 584afa46..c5105738 100644 --- a/test_endpoints.http +++ b/test_endpoints.http @@ -265,6 +265,17 @@ content-type: application/json POST http://localhost:8011 content-type: application/json +{ + "jsonrpc": "2.0", + "id": "2", + "method": "eth_syncing", + "params": [] +} + +### +POST http://localhost:8011 +content-type: application/json + { "jsonrpc": "2.0", "id": "2",