Skip to content

Commit

Permalink
feat: impl eth_syncing (#104)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
grw-ms authored Sep 7, 2023
1 parent 14ef9bb commit fee3152
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
26 changes: 25 additions & 1 deletion SUPPORTED_APIS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`<br />[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`<br />[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 |
Expand Down Expand Up @@ -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`
Expand Down
16 changes: 15 additions & 1 deletion src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ impl<S: Send + Sync + 'static + ForkSource + std::fmt::Debug> EthNamespaceT for
&self,
) -> jsonrpc_core::BoxFuture<jsonrpc_core::Result<zksync_basic_types::web3::types::SyncState>>
{
not_implemented("syncing")
Ok(zksync_basic_types::web3::types::SyncState::NotSyncing).into_boxed_future()
}

fn accounts(
Expand Down Expand Up @@ -1765,3 +1765,17 @@ impl<S: Send + Sync + 'static + ForkSource + std::fmt::Debug> 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::<HttpForkSource>::default();
let syncing = node.syncing().await.expect("failed syncing");
assert!(matches!(syncing, SyncState::NotSyncing));
}
}
11 changes: 11 additions & 0 deletions test_endpoints.http
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit fee3152

Please sign in to comment.