Skip to content

Commit

Permalink
test: add a rpc test confirming that we support batched requests (#1638)
Browse files Browse the repository at this point in the history
  • Loading branch information
oac1771 authored Jan 17, 2025
1 parent c0e6d13 commit 314309c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.python-version
.DS_Store
*rusty-tags.vi

.vscode/
# Ignore downloaded consensus specs test data
testing/ef-tests/mainnet*

2 changes: 1 addition & 1 deletion testing/ethportal-peertest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ethereum_ssz.workspace = true
ethportal-api.workspace = true
futures.workspace = true
hex.workspace = true
jsonrpsee = { workspace = true, features = ["async-client", "client", "macros", "server"]}
jsonrpsee = { workspace = true, features = ["async-client", "client", "macros", "server"] }
portalnet.workspace = true
portal-bridge.workspace = true
rand.workspace = true
Expand Down
52 changes: 50 additions & 2 deletions testing/ethportal-peertest/tests/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use alloy::{
primitives::U256,
providers::{IpcConnect, Provider, ProviderBuilder, RootProvider},
pubsub::PubSubFrontend,
rpc::types::{BlockNumberOrTag, BlockTransactions, BlockTransactionsKind, Header as RpcHeader},
rpc::{
client::ClientBuilder,
types::{BlockNumberOrTag, BlockTransactions, BlockTransactionsKind, Header as RpcHeader},
},
transports::RpcError,
};
use ethportal_api::{
Expand All @@ -16,14 +19,15 @@ use ethportal_api::{
ContentValue, Header, HistoryContentKey, HistoryContentValue, HistoryNetworkApiClient,
};
use jsonrpsee::async_client::Client;
use portalnet::constants::DEFAULT_WEB3_IPC_PATH;
use portalnet::constants::{DEFAULT_WEB3_HTTP_ADDRESS, DEFAULT_WEB3_IPC_PATH};
use rpc::RpcServerHandle;
use serde_yaml::Value;
use serial_test::serial;
use ssz::Decode;

mod utils;
use trin::cli::TrinConfig;
use url::Url;
use utils::init_tracing;

async fn setup_web3_server() -> (RpcServerHandle, RootProvider<PubSubFrontend>, Client) {
Expand Down Expand Up @@ -62,6 +66,50 @@ async fn setup_web3_server() -> (RpcServerHandle, RootProvider<PubSubFrontend>,
(web3_server, web3_client, native_client)
}

#[tokio::test(flavor = "multi_thread")]
#[serial]
async fn test_batch_call() {
init_tracing();

let test_ip_addr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
let test_discovery_port = 8999;
let external_addr = format!("{test_ip_addr}:{test_discovery_port}");

let trin_config = TrinConfig::new_from([
"trin",
"--external-address",
external_addr.as_str(),
"--web3-transport",
"http",
"--ephemeral",
"--discovery-port",
&test_discovery_port.to_string(),
"--bootnodes",
"none",
])
.unwrap();

let web3_server = trin::run_trin(trin_config).await.unwrap();

let url = Url::parse(DEFAULT_WEB3_HTTP_ADDRESS).unwrap();
let client = ClientBuilder::default().http(url);

let mut batch = client.new_batch();

let client_version_future = batch
.add_call::<(), serde_json::Value>("web3_clientVersion", &())
.unwrap();
let node_info_future = batch
.add_call::<(), serde_json::Value>("discv5_nodeInfo", &())
.unwrap();

batch.send().await.unwrap();
client_version_future.await.unwrap();
node_info_future.await.unwrap();

web3_server.stop().unwrap();
}

#[tokio::test(flavor = "multi_thread")]
#[serial]
async fn test_eth_chain_id() {
Expand Down

0 comments on commit 314309c

Please sign in to comment.