Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test(rpc): Test support for different api modules #1288

Merged
merged 9 commits into from
Feb 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
207 changes: 171 additions & 36 deletions crates/rpc/rpc-builder/tests/it/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

use crate::utils::{launch_http, launch_http_ws, launch_ws};
use jsonrpsee::core::client::{ClientT, SubscriptionClientT};
use reth_primitives::{NodeRecord, H256, BlockNumber, U256, H64};
use reth_rpc_api::{clients::AdminApiClient, EthApiClient};
use reth_primitives::{NodeRecord, H256, BlockNumber, U256, H64, rpc::{BlockId, BlockNumber as RpcBlockNumber }};
use reth_rpc_api::DebugApiClient;
use reth_rpc_api::clients::{AdminApiClient, EthApiClient};
use reth_rpc_builder::RethRpcModule;
use jsonrpsee::core::error::Error;
use jsonrpsee::types::error::{CallError, ErrorCode};
Expand Down Expand Up @@ -44,43 +45,69 @@ where C: ClientT + SubscriptionClientT + Sync {

// Unimplemented
assert!(is_unimplemented(EthApiClient::syncing(client).await.err().unwrap()));
EthApiClient::author(client).await.unwrap_err();
EthApiClient::block_by_hash(client, H256::default(), false).await.unwrap_err();
EthApiClient::block_by_number(client, BlockNumber::default(), false).await.unwrap_err();
EthApiClient::block_transaction_count_by_hash(client, H256::default()).await.unwrap_err();
EthApiClient::block_transaction_count_by_number(client, BlockNumber::default()).await.unwrap_err();
EthApiClient::block_uncles_count_by_hash(client, H256::default()).await.unwrap_err();
EthApiClient::block_uncles_count_by_number(client, BlockNumber::default()).await.unwrap_err();
// EthApiClient::uncle_by_block_hash_and_index(client, H256::default(), Index::default()).await.unwrap_err();
// EthApiClient::uncle_by_block_number_and_index(client).await.unwrap_err();
// EthApiClient::transaction_by_hash(client, H256::default()).await.unwrap_err();
// EthApiClient::transaction_by_block_hash_and_index(client).await.unwrap_err();
// EthApiClient::transaction_by_block_number_and_index(client).await.unwrap_err();
EthApiClient::transaction_receipt(client, H256::default()).await.unwrap_err();
// EthApiClient::balance(client).await.unwrap_err();
// EthApiClient::storage_at(client).await.unwrap_err();
// EthApiClient::transaction_count(client).await.unwrap_err();
// EthApiClient::get_code(client).await.unwrap_err();
// EthApiClient::call(client).await.unwrap_err();
// EthApiClient::create_access_list(client).await.unwrap_err();
// EthApiClient::estimate_gas(client).await.unwrap_err();
EthApiClient::gas_price(client).await.unwrap_err();
EthApiClient::fee_history(client, U256::default(), BlockNumber::default(), None).await.unwrap_err();
EthApiClient::max_priority_fee_per_gas(client).await.unwrap_err();
EthApiClient::is_mining(client).await.unwrap_err();
EthApiClient::hashrate(client).await.unwrap_err();
EthApiClient::get_work(client).await.unwrap_err();
EthApiClient::submit_hashrate(client, U256::default(), H256::default()).await.unwrap_err();
EthApiClient::submit_work(client, H64::default(), H256::default(), H256::default()).await.unwrap_err();
// EthApiClient::send_transaction(client).await.unwrap_err();
// EthApiClient::send_raw_transaction(client).await.unwrap_err();
// EthApiClient::sign(client).await.unwrap_err();
// EthApiClient::sign_transaction(client).await.unwrap_err();
// EthApiClient::sign_typed_data(client).await.unwrap_err();
// EthApiClient::get_proof(client).await.unwrap_err();
assert!(is_unimplemented(EthApiClient::author(client).await.err().unwrap()));
assert!(is_unimplemented(EthApiClient::block_by_hash(client, H256::default(), false).await.err().unwrap()));
assert!(is_unimplemented(EthApiClient::block_by_number(client, BlockNumber::default(), false).await.err().unwrap()));
assert!(is_unimplemented(EthApiClient::block_transaction_count_by_hash(client, H256::default()).await.err().unwrap()));
assert!(is_unimplemented(EthApiClient::block_transaction_count_by_number(client, BlockNumber::default()).await.err().unwrap()));
assert!(is_unimplemented(EthApiClient::block_uncles_count_by_hash(client, H256::default()).await.err().unwrap()));
assert!(is_unimplemented(EthApiClient::block_uncles_count_by_number(client, BlockNumber::default()).await.err().unwrap()));
// EthApiClient::uncle_by_block_hash_and_index(client, H256::default(), Index::default()).await.err().unwrap()));
// EthApiClient::uncle_by_block_number_and_index(client).await.err().unwrap()));
// EthApiClient::transaction_by_hash(client, H256::default()).await.err().unwrap()));
// EthApiClient::transaction_by_block_hash_and_index(client).await.err().unwrap()));
// EthApiClient::transaction_by_block_number_and_index(client).await.err().unwrap()));
assert!(is_unimplemented(EthApiClient::transaction_receipt(client, H256::default()).await.err().unwrap()));
// EthApiClient::balance(client).await.err().unwrap()));
// EthApiClient::storage_at(client).await.err().unwrap()));
// EthApiClient::transaction_count(client).await.err().unwrap()));
// EthApiClient::get_code(client).await.err().unwrap()));
// EthApiClient::call(client).await.err().unwrap()));
// EthApiClient::create_access_list(client).await.err().unwrap()));
// EthApiClient::estimate_gas(client).await.err().unwrap()));
assert!(is_unimplemented(EthApiClient::gas_price(client).await.err().unwrap()));
assert!(is_unimplemented(EthApiClient::fee_history(client, U256::default(), BlockNumber::default(), None).await.err().unwrap()));
assert!(is_unimplemented(EthApiClient::max_priority_fee_per_gas(client).await.err().unwrap()));
assert!(is_unimplemented(EthApiClient::is_mining(client).await.err().unwrap()));
assert!(is_unimplemented(EthApiClient::hashrate(client).await.err().unwrap()));
assert!(is_unimplemented(EthApiClient::get_work(client).await.err().unwrap()));
assert!(is_unimplemented(EthApiClient::submit_hashrate(client, U256::default(), H256::default()).await.err().unwrap()));
assert!(is_unimplemented(EthApiClient::submit_work(client, H64::default(), H256::default(), H256::default()).await.err().unwrap()));
// EthApiClient::send_transaction(client).await.err().unwrap()));
// EthApiClient::send_raw_transaction(client).await.err().unwrap()));
// EthApiClient::sign(client).await.err().unwrap()));
// EthApiClient::sign_transaction(client).await.err().unwrap()));
// EthApiClient::sign_typed_data(client).await.err().unwrap()));
// EthApiClient::get_proof(client).await.err().unwrap()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are they currently commented?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattsse maybe you were looking at an older version of the PR?


}

async fn test_basic_debug_calls<C>(client: &C)
where C: ClientT + SubscriptionClientT + Sync {
let block_id = BlockId::Number(RpcBlockNumber::default());

assert!(is_unimplemented(DebugApiClient::raw_block(client, block_id).await.err().unwrap()));
assert!(is_unimplemented(DebugApiClient::raw_transaction(client, H256::default()).await.err().unwrap()));
assert!(is_unimplemented(DebugApiClient::raw_header(client, block_id).await.err().unwrap()));
assert!(is_unimplemented(DebugApiClient::raw_receipts(client, block_id).await.err().unwrap()));
assert!(is_unimplemented(DebugApiClient::bad_blocks(client).await.err().unwrap()));
}

async fn test_basic_net_calls<C>(client: &C)
where C: ClientT + SubscriptionClientT + Sync {

}

async fn test_basic_trace_calls<C>(client: &C)
where C: ClientT + SubscriptionClientT + Sync {

}

async fn test_basic_web3_calls<C>(client: &C)
where C: ClientT + SubscriptionClientT + Sync {

}


#[tokio::test(flavor = "multi_thread")]
async fn test_call_admin_functions_http() {
Expand Down Expand Up @@ -135,3 +162,111 @@ async fn test_call_eth_functions_http_and_ws() {
let client = handle.http_client().unwrap();
test_basic_eth_calls(&client).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_call_debug_functions_http() {
reth_tracing::init_test_tracing();

let handle = launch_http(vec![RethRpcModule::Debug]).await;
let client = handle.http_client().unwrap();
test_basic_debug_calls(&client).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_call_debug_functions_ws() {
reth_tracing::init_test_tracing();

let handle = launch_ws(vec![RethRpcModule::Debug]).await;
let client = handle.ws_client().await.unwrap();
test_basic_debug_calls(&client).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_call_debug_functions_http_and_ws() {
reth_tracing::init_test_tracing();

let handle = launch_http_ws(vec![RethRpcModule::Debug]).await;
let client = handle.http_client().unwrap();
test_basic_debug_calls(&client).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_call_net_functions_http() {
reth_tracing::init_test_tracing();

let handle = launch_http(vec![RethRpcModule::Net]).await;
let client = handle.http_client().unwrap();
test_basic_net_calls(&client).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_call_net_functions_ws() {
reth_tracing::init_test_tracing();

let handle = launch_ws(vec![RethRpcModule::Net]).await;
let client = handle.ws_client().await.unwrap();
test_basic_net_calls(&client).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_call_net_functions_http_and_ws() {
reth_tracing::init_test_tracing();

let handle = launch_http_ws(vec![RethRpcModule::Net]).await;
let client = handle.http_client().unwrap();
test_basic_net_calls(&client).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_call_trace_functions_http() {
reth_tracing::init_test_tracing();

let handle = launch_http(vec![RethRpcModule::Trace]).await;
let client = handle.http_client().unwrap();
test_basic_trace_calls(&client).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_call_trace_functions_ws() {
reth_tracing::init_test_tracing();

let handle = launch_ws(vec![RethRpcModule::Trace]).await;
let client = handle.ws_client().await.unwrap();
test_basic_trace_calls(&client).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_call_trace_functions_http_and_ws() {
reth_tracing::init_test_tracing();

let handle = launch_http_ws(vec![RethRpcModule::Trace]).await;
let client = handle.http_client().unwrap();
test_basic_trace_calls(&client).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_call_web3_functions_http() {
reth_tracing::init_test_tracing();

let handle = launch_http(vec![RethRpcModule::Web3]).await;
let client = handle.http_client().unwrap();
test_basic_web3_calls(&client).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_call_web3_functions_ws() {
reth_tracing::init_test_tracing();

let handle = launch_ws(vec![RethRpcModule::Web3]).await;
let client = handle.ws_client().await.unwrap();
test_basic_web3_calls(&client).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_call_web3_functions_http_and_ws() {
reth_tracing::init_test_tracing();

let handle = launch_http_ws(vec![RethRpcModule::Web3]).await;
let client = handle.http_client().unwrap();
test_basic_web3_calls(&client).await;
}