Skip to content

Commit 314309c

Browse files
authored
test: add a rpc test confirming that we support batched requests (#1638)
1 parent c0e6d13 commit 314309c

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
.python-version
55
.DS_Store
66
*rusty-tags.vi
7-
7+
.vscode/
88
# Ignore downloaded consensus specs test data
99
testing/ef-tests/mainnet*
10+

testing/ethportal-peertest/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ethereum_ssz.workspace = true
2020
ethportal-api.workspace = true
2121
futures.workspace = true
2222
hex.workspace = true
23-
jsonrpsee = { workspace = true, features = ["async-client", "client", "macros", "server"]}
23+
jsonrpsee = { workspace = true, features = ["async-client", "client", "macros", "server"] }
2424
portalnet.workspace = true
2525
portal-bridge.workspace = true
2626
rand.workspace = true

testing/ethportal-peertest/tests/rpc_server.rs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use alloy::{
77
primitives::U256,
88
providers::{IpcConnect, Provider, ProviderBuilder, RootProvider},
99
pubsub::PubSubFrontend,
10-
rpc::types::{BlockNumberOrTag, BlockTransactions, BlockTransactionsKind, Header as RpcHeader},
10+
rpc::{
11+
client::ClientBuilder,
12+
types::{BlockNumberOrTag, BlockTransactions, BlockTransactionsKind, Header as RpcHeader},
13+
},
1114
transports::RpcError,
1215
};
1316
use ethportal_api::{
@@ -16,14 +19,15 @@ use ethportal_api::{
1619
ContentValue, Header, HistoryContentKey, HistoryContentValue, HistoryNetworkApiClient,
1720
};
1821
use jsonrpsee::async_client::Client;
19-
use portalnet::constants::DEFAULT_WEB3_IPC_PATH;
22+
use portalnet::constants::{DEFAULT_WEB3_HTTP_ADDRESS, DEFAULT_WEB3_IPC_PATH};
2023
use rpc::RpcServerHandle;
2124
use serde_yaml::Value;
2225
use serial_test::serial;
2326
use ssz::Decode;
2427

2528
mod utils;
2629
use trin::cli::TrinConfig;
30+
use url::Url;
2731
use utils::init_tracing;
2832

2933
async fn setup_web3_server() -> (RpcServerHandle, RootProvider<PubSubFrontend>, Client) {
@@ -62,6 +66,50 @@ async fn setup_web3_server() -> (RpcServerHandle, RootProvider<PubSubFrontend>,
6266
(web3_server, web3_client, native_client)
6367
}
6468

69+
#[tokio::test(flavor = "multi_thread")]
70+
#[serial]
71+
async fn test_batch_call() {
72+
init_tracing();
73+
74+
let test_ip_addr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
75+
let test_discovery_port = 8999;
76+
let external_addr = format!("{test_ip_addr}:{test_discovery_port}");
77+
78+
let trin_config = TrinConfig::new_from([
79+
"trin",
80+
"--external-address",
81+
external_addr.as_str(),
82+
"--web3-transport",
83+
"http",
84+
"--ephemeral",
85+
"--discovery-port",
86+
&test_discovery_port.to_string(),
87+
"--bootnodes",
88+
"none",
89+
])
90+
.unwrap();
91+
92+
let web3_server = trin::run_trin(trin_config).await.unwrap();
93+
94+
let url = Url::parse(DEFAULT_WEB3_HTTP_ADDRESS).unwrap();
95+
let client = ClientBuilder::default().http(url);
96+
97+
let mut batch = client.new_batch();
98+
99+
let client_version_future = batch
100+
.add_call::<(), serde_json::Value>("web3_clientVersion", &())
101+
.unwrap();
102+
let node_info_future = batch
103+
.add_call::<(), serde_json::Value>("discv5_nodeInfo", &())
104+
.unwrap();
105+
106+
batch.send().await.unwrap();
107+
client_version_future.await.unwrap();
108+
node_info_future.await.unwrap();
109+
110+
web3_server.stop().unwrap();
111+
}
112+
65113
#[tokio::test(flavor = "multi_thread")]
66114
#[serial]
67115
async fn test_eth_chain_id() {

0 commit comments

Comments
 (0)