Skip to content

Commit

Permalink
support zks_L1ChainId
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaztec committed Feb 23, 2024
1 parent d6ad110 commit 7f7e02a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
25 changes: 24 additions & 1 deletion SUPPORTED_APIS.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ The `status` options are:
| [`ZKS`](#zks-namespace) | [`zks_getTokenPrice`](#zks_getTokenPrice) | `SUPPORTED` | Gets the USD price of a token <br />_(`ETH` is hard-coded to `1_500`, while some others are `1`)_ |
| [`ZKS`](#zks-namespace) | [`zks_getTransactionDetails`](#zks_gettransactiondetails) | `SUPPORTED` | Returns data from a specific transaction given by the transaction hash |
| `ZKS` | `zks_L1BatchNumber` | `NOT IMPLEMENTED` | Returns the latest L1 batch number |
| `ZKS` | `zks_L1ChainId` | `NOT IMPLEMENTED` | Returns the chain id of the underlying L1 |
| [`ZKS`](#zks-namespace) | [`zks_L1ChainId`](#zks_l1chainid) | `IMPLEMENTED` | Returns the chain id of the underlying L1 |

## `CONFIG NAMESPACE`

Expand Down Expand Up @@ -1979,3 +1979,26 @@ curl --request POST \
"params": ["0x364d6D0333432C3Ac016Ca832fb8594A8cE43Ca6"]
}'
```

### `zks_L1ChainId`

[source](src/node/zks.rs)

Returns the chain id of the underlying L1.

#### 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": "zks_L1ChainId","params": []}'
```
11 changes: 10 additions & 1 deletion src/node/zks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> ZksNamespa
}

fn l1_chain_id(&self) -> RpcResult<zksync_basic_types::U64> {
not_implemented("zks_L1ChainId")
use crate::namespaces::EthNamespaceT;
self.chain_id()
}

fn get_confirmed_tokens(
Expand Down Expand Up @@ -515,6 +516,7 @@ mod tests {

use crate::cache::CacheConfig;
use crate::fork::ForkDetails;
use crate::node::TEST_NODE_NETWORK_ID;
use crate::testing;
use crate::testing::{ForkBlockConfig, MockServer};
use crate::{http_fork_source::HttpForkSource, node::InMemoryNode};
Expand Down Expand Up @@ -1043,6 +1045,13 @@ mod tests {
assert_eq!(&balances[0].name, "Ether");
}

#[tokio::test]
async fn test_get_l1_chain_id() {
let node = InMemoryNode::<HttpForkSource>::default();
let chain_id = node.l1_chain_id().await.expect("get chain id").as_u32();
assert_eq!(TEST_NODE_NETWORK_ID, chain_id);
}

#[tokio::test]
async fn test_get_all_account_balances_forked() {
let cbeth_address = Address::from_str("0x75af292c1c9a37b3ea2e6041168b4e48875b9ed5")
Expand Down
11 changes: 11 additions & 0 deletions test_endpoints.http
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,17 @@ content-type: application/json
POST http://localhost:8011
content-type: application/json

{
"jsonrpc": "2.0",
"id": "1",
"method": "zks_L1ChainId",
"params": []
}

###
POST http://localhost:8011
content-type: application/json

{
"jsonrpc": "2.0",
"id": "1",
Expand Down

0 comments on commit 7f7e02a

Please sign in to comment.