More raw rpc request testing (#6554)

This commit is contained in:
Thomas Coratger
2024-02-12 13:22:51 +01:00
committed by GitHub
parent 43b795163c
commit f2f1f09552

View File

@ -8,12 +8,13 @@ use jsonrpsee::{
error::Error,
params::ArrayParams,
},
http_client::HttpClient,
rpc_params,
types::error::ErrorCode,
};
use reth_primitives::{
hex_literal::hex, Address, BlockId, BlockNumberOrTag, Bytes, NodeRecord, TxHash, B256, B64,
U256,
U256, U64,
};
use reth_rpc_api::{
clients::{AdminApiClient, EthApiClient},
@ -23,9 +24,9 @@ use reth_rpc_api::{
use reth_rpc_builder::RethRpcModule;
use reth_rpc_types::{
trace::filter::TraceFilter, Filter, Index, Log, PendingTransactionFilterKind, RichBlock,
TransactionRequest,
SyncStatus, Transaction, TransactionReceipt, TransactionRequest,
};
use serde::{Deserialize, Serialize};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashSet;
@ -39,6 +40,31 @@ fn is_unimplemented(err: Error) -> bool {
}
}
async fn test_rpc_call_ok<R>(client: &HttpClient, method_name: &str, params: ArrayParams)
where
R: DeserializeOwned,
{
// Make the RPC request
match client.request::<R, _>(method_name, params).await {
Ok(_) => {} // If the request is successful, do nothing
Err(e) => {
// If an error occurs, panic with the error message
panic!("Expected successful response, got error: {:?}", e);
}
}
}
async fn test_rpc_call_err<R>(client: &HttpClient, method_name: &str, params: ArrayParams)
where
R: DeserializeOwned + std::fmt::Debug,
{
// Make the RPC request
if let Ok(resp) = client.request::<R, _>(method_name, params).await {
// Panic if an unexpected successful response is received
panic!("Expected error response, got successful response: {:?}", resp);
};
}
/// Represents a builder for creating JSON-RPC requests.
#[derive(Clone, Serialize, Deserialize)]
pub struct RawRpcParamsBuilder {
@ -536,36 +562,24 @@ async fn test_eth_get_block_by_number_rpc_call() {
let client = handle.http_client().unwrap();
// Requesting block by number with proper fields
match client
.request::<Option<RichBlock>, _>(
"eth_getBlockByNumber",
rpc_params!["0x1b4", true], // Block number and full transaction object flag
)
.await
{
Ok(_) => {}
Err(e) => {
// Panic if an error is encountered
panic!("Expected successful response, got error: {:?}", e);
}
};
test_rpc_call_ok::<Option<RichBlock>>(
&client,
"eth_getBlockByNumber",
rpc_params!["0x1b4", true], // Block number and full transaction object flag
)
.await;
// Requesting block by number with wrong fields
if let Ok(resp) = client
.request::<Option<RichBlock>, _>("eth_getBlockByNumber", rpc_params!["0x1b4", "0x1b4"])
.await
{
// Panic if an unexpected successful response is received
panic!("Expected error response, got successful response: {:?}", resp);
};
test_rpc_call_err::<Option<RichBlock>>(
&client,
"eth_getBlockByNumber",
rpc_params!["0x1b4", "0x1b4"],
)
.await;
// Requesting block by number with missing fields
if let Ok(resp) =
client.request::<Option<RichBlock>, _>("eth_getBlockByNumber", rpc_params!["0x1b4"]).await
{
// Panic if an unexpected successful response is received
panic!("Expected error response, got successful response: {:?}", resp);
};
test_rpc_call_err::<Option<RichBlock>>(&client, "eth_getBlockByNumber", rpc_params!["0x1b4"])
.await;
}
#[tokio::test(flavor = "multi_thread")]
@ -578,51 +592,843 @@ async fn test_eth_get_block_by_hash_rpc_call() {
let client = handle.http_client().unwrap();
// Requesting block by hash with proper fields
match client
.request::<Option<RichBlock>, _>(
"eth_getBlockByHash",
rpc_params![
"0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae",
false
],
)
.await
{
Ok(_) => {}
Err(e) => {
// Panic if an error is encountered
panic!("Expected successful response, got error: {:?}", e);
}
};
test_rpc_call_ok::<Option<RichBlock>>(
&client,
"eth_getBlockByHash",
rpc_params!["0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae", false],
)
.await;
// Requesting block by hash with wrong fields
if let Ok(resp) = client
.request::<Option<RichBlock>, _>(
"eth_getBlockByHash",
rpc_params![
"0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae",
"0x1b4"
],
)
.await
{
// Panic if an unexpected successful response is received
panic!("Expected error response, got successful response: {:?}", resp);
};
test_rpc_call_err::<Option<RichBlock>>(
&client,
"eth_getBlockByHash",
rpc_params!["0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae", "0x1b4"],
)
.await;
// Requesting block by hash with missing fields
if let Ok(resp) = client
.request::<Option<RichBlock>, _>(
"eth_getBlockByHash",
rpc_params!["0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae"],
test_rpc_call_err::<Option<RichBlock>>(
&client,
"eth_getBlockByHash",
rpc_params!["0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae"],
)
.await;
}
#[tokio::test(flavor = "multi_thread")]
async fn test_eth_get_code_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();
// Launch HTTP server with the specified RPC module
let handle = launch_http(vec![RethRpcModule::Eth]).await;
let client = handle.http_client().unwrap();
// Requesting code at a given address with proper fields
test_rpc_call_ok::<Bytes>(
&client,
"eth_getCode",
rpc_params![
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"0x2" // 2
],
)
.await;
// Define test cases with different default block parameters
let default_block_params = vec!["earliest", "latest", "pending"];
// Iterate over test cases
for param in default_block_params {
// Requesting code at a given address with default block parameter
test_rpc_call_ok::<Bytes>(
&client,
"eth_getCode",
rpc_params!["0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", param],
)
.await
{
// Panic if an unexpected successful response is received
panic!("Expected error response, got successful response: {:?}", resp);
.await;
}
// Without block number which is optional
test_rpc_call_ok::<Bytes>(
&client,
"eth_getCode",
rpc_params!["0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"],
)
.await;
// Requesting code at a given address with invalid default block parameter
test_rpc_call_err::<Bytes>(
&client,
"eth_getCode",
rpc_params!["0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", "finalized"],
)
.await;
// Requesting code at a given address with wrong fields
test_rpc_call_err::<Bytes>(
&client,
"eth_getCode",
rpc_params!["0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", false],
)
.await;
}
#[tokio::test(flavor = "multi_thread")]
async fn test_eth_block_number_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();
// Launch HTTP server with the specified RPC module
let handle = launch_http(vec![RethRpcModule::Eth]).await;
let client = handle.http_client().unwrap();
// Requesting block number without any parameter
test_rpc_call_ok::<U256>(&client, "eth_blockNumber", rpc_params![]).await;
// Define test cases with different default block parameters
let invalid_default_block_params = vec!["finalized", "0x2"];
// Iterate over test cases
for param in invalid_default_block_params {
// Requesting block number with invalid parameter should not throw an error
test_rpc_call_ok::<U256>(&client, "eth_blockNumber", rpc_params![param]).await;
}
}
#[tokio::test(flavor = "multi_thread")]
async fn test_eth_chain_id_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();
// Launch HTTP server with the specified RPC module
let handle = launch_http(vec![RethRpcModule::Eth]).await;
let client = handle.http_client().unwrap();
// Requesting chain ID without any parameter
test_rpc_call_ok::<Option<U64>>(&client, "eth_chainId", rpc_params![]).await;
// Define test cases with different invalid parameters
let invalid_params = vec!["finalized", "0x2"];
// Iterate over test cases
for param in invalid_params {
// Requesting chain ID with invalid parameter should not throw an error
test_rpc_call_ok::<Option<U64>>(&client, "eth_chainId", rpc_params![param]).await;
}
}
#[tokio::test(flavor = "multi_thread")]
async fn test_eth_syncing_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();
// Launch HTTP server with the specified RPC module
let handle = launch_http(vec![RethRpcModule::Eth]).await;
let client = handle.http_client().unwrap();
// Requesting syncing status
test_rpc_call_ok::<Option<SyncStatus>>(&client, "eth_syncing", rpc_params![]).await;
// Define test cases with invalid parameters
let invalid_params = vec!["latest", "earliest", "pending", "0x2"];
// Iterate over test cases
for param in invalid_params {
// Requesting syncing status with invalid parameter should not throw an error
test_rpc_call_ok::<Option<SyncStatus>>(&client, "eth_syncing", rpc_params![param]).await;
}
}
#[tokio::test(flavor = "multi_thread")]
async fn test_eth_protocol_version_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();
// Launch HTTP server with the specified RPC module
let handle = launch_http(vec![RethRpcModule::Eth]).await;
let client = handle.http_client().unwrap();
// Requesting protocol version without any parameter
test_rpc_call_ok::<U64>(&client, "eth_protocolVersion", rpc_params![]).await;
// Define test cases with invalid parameters
let invalid_params = vec!["latest", "earliest", "pending", "0x2"];
// Iterate over test cases
for param in invalid_params {
// Requesting protocol version with invalid parameter should not throw an error
test_rpc_call_ok::<U64>(&client, "eth_protocolVersion", rpc_params![param]).await;
}
}
#[tokio::test(flavor = "multi_thread")]
async fn test_eth_coinbase_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();
// Launch HTTP server with the specified RPC module
let handle = launch_http(vec![RethRpcModule::Eth]).await;
let client = handle.http_client().unwrap();
// Requesting coinbase address without any parameter should return Unimplemented
match client.request::<Address, _>("eth_coinbase", rpc_params![]).await {
Ok(_) => {
// If there's a response, it's unexpected, panic
panic!("Expected Unimplemented error, got successful response");
}
Err(err) => {
assert!(is_unimplemented(err));
}
};
}
#[tokio::test(flavor = "multi_thread")]
async fn test_eth_accounts_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();
// Launch HTTP server with the specified RPC module
let handle = launch_http(vec![RethRpcModule::Eth]).await;
let client = handle.http_client().unwrap();
// Requesting accounts without any parameter
test_rpc_call_ok::<Option<Vec<Address>>>(&client, "eth_accounts", rpc_params![]).await;
// Define test cases with invalid parameters
let invalid_params = vec!["latest", "earliest", "pending", "0x2"];
// Iterate over test cases
for param in invalid_params {
// Requesting accounts with invalid parameter should not throw an error
test_rpc_call_ok::<Option<Vec<Address>>>(&client, "eth_accounts", rpc_params![param]).await;
}
}
#[tokio::test(flavor = "multi_thread")]
async fn test_eth_get_block_transaction_count_by_hash_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();
// Launch HTTP server with the specified RPC module
let handle = launch_http(vec![RethRpcModule::Eth]).await;
let client = handle.http_client().unwrap();
// Requesting transaction count by block hash with proper fields
test_rpc_call_ok::<Option<U256>>(
&client,
"eth_getBlockTransactionCountByHash",
rpc_params!["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"],
)
.await;
// Requesting transaction count by block hash with additional fields
test_rpc_call_ok::<Option<U256>>(
&client,
"eth_getBlockTransactionCountByHash",
rpc_params!["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238", true],
)
.await;
// Requesting transaction count by block hash with missing fields
test_rpc_call_err::<Option<U256>>(&client, "eth_getBlockTransactionCountByHash", rpc_params![])
.await;
// Requesting transaction count by block hash with wrong field
test_rpc_call_err::<Option<U256>>(
&client,
"eth_getBlockTransactionCountByHash",
rpc_params![true],
)
.await;
}
#[tokio::test(flavor = "multi_thread")]
async fn test_eth_get_block_transaction_count_by_number_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();
// Launch HTTP server with the specified RPC module
let handle = launch_http(vec![RethRpcModule::Eth]).await;
let client = handle.http_client().unwrap();
// Requesting transaction count by block number with proper fields
test_rpc_call_ok::<Option<U256>>(
&client,
"eth_getBlockTransactionCountByNumber",
rpc_params!["0xe8"],
)
.await;
// Requesting transaction count by block number with additional fields
test_rpc_call_ok::<Option<U256>>(
&client,
"eth_getBlockTransactionCountByNumber",
rpc_params!["0xe8", true],
)
.await;
// Requesting transaction count by block number with missing fields
test_rpc_call_err::<Option<U256>>(
&client,
"eth_getBlockTransactionCountByNumber",
rpc_params![],
)
.await;
// Requesting transaction count by block number with wrong field
test_rpc_call_err::<Option<U256>>(
&client,
"eth_getBlockTransactionCountByNumber",
rpc_params![true],
)
.await;
}
#[tokio::test(flavor = "multi_thread")]
async fn test_eth_get_uncle_count_by_block_hash_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();
// Launch HTTP server with the specified RPC module
let handle = launch_http(vec![RethRpcModule::Eth]).await;
let client = handle.http_client().unwrap();
// Requesting uncle count by block hash with proper fields
test_rpc_call_ok::<Option<U256>>(
&client,
"eth_getUncleCountByBlockHash",
rpc_params!["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"],
)
.await;
// Requesting uncle count by block hash with additional fields
test_rpc_call_ok::<Option<U256>>(
&client,
"eth_getUncleCountByBlockHash",
rpc_params!["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238", true],
)
.await;
// Requesting uncle count by block hash with missing fields
test_rpc_call_err::<Option<U256>>(&client, "eth_getUncleCountByBlockHash", rpc_params![]).await;
// Requesting uncle count by block hash with wrong field
test_rpc_call_err::<Option<U256>>(&client, "eth_getUncleCountByBlockHash", rpc_params![true])
.await;
}
#[tokio::test(flavor = "multi_thread")]
async fn test_eth_get_uncle_count_by_block_number_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();
// Launch HTTP server with the specified RPC module
let handle = launch_http(vec![RethRpcModule::Eth]).await;
let client = handle.http_client().unwrap();
// Requesting uncle count by block number with proper fields
test_rpc_call_ok::<Option<U256>>(
&client,
"eth_getUncleCountByBlockNumber",
rpc_params!["0xe8"],
)
.await;
// Requesting uncle count by block number with additional fields
test_rpc_call_ok::<Option<U256>>(
&client,
"eth_getUncleCountByBlockNumber",
rpc_params!["0xe8", true],
)
.await;
// Requesting uncle count by block number with missing fields
test_rpc_call_err::<Option<U256>>(&client, "eth_getUncleCountByBlockNumber", rpc_params![])
.await;
// Requesting uncle count by block number with wrong field
test_rpc_call_err::<Option<U256>>(&client, "eth_getUncleCountByBlockNumber", rpc_params![true])
.await;
}
#[tokio::test(flavor = "multi_thread")]
async fn test_eth_get_block_receipts_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();
// Launch HTTP server with the specified RPC module
let handle = launch_http(vec![RethRpcModule::Eth]).await;
let client = handle.http_client().unwrap();
// Requesting block receipts by block hash with proper fields
test_rpc_call_ok::<Option<Vec<TransactionReceipt>>>(
&client,
"eth_getBlockReceipts",
rpc_params!["0xe8"],
)
.await;
// Requesting block receipts by block hash with additional fields
test_rpc_call_ok::<Option<Vec<TransactionReceipt>>>(
&client,
"eth_getBlockReceipts",
rpc_params!["0xe8", true],
)
.await;
// Requesting block receipts by block hash with missing fields
test_rpc_call_err::<Option<Vec<TransactionReceipt>>>(
&client,
"eth_getBlockReceipts",
rpc_params![],
)
.await;
// Requesting block receipts by block hash with wrong field
test_rpc_call_err::<Option<Vec<TransactionReceipt>>>(
&client,
"eth_getBlockReceipts",
rpc_params![true],
)
.await;
}
#[tokio::test(flavor = "multi_thread")]
async fn test_eth_get_uncle_by_block_hash_and_index_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();
// Launch HTTP server with the specified RPC module
let handle = launch_http(vec![RethRpcModule::Eth]).await;
let client = handle.http_client().unwrap();
// Requesting uncle by block hash and index with proper fields
test_rpc_call_ok::<Option<RichBlock>>(
&client,
"eth_getUncleByBlockHashAndIndex",
rpc_params!["0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "0x0"],
)
.await;
// Requesting uncle by block hash and index with additional fields
test_rpc_call_ok::<Option<RichBlock>>(
&client,
"eth_getUncleByBlockHashAndIndex",
rpc_params![
"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
"0x0",
true
],
)
.await;
// Requesting uncle by block hash and index with missing fields
test_rpc_call_err::<Option<RichBlock>>(
&client,
"eth_getUncleByBlockHashAndIndex",
rpc_params![],
)
.await;
// Requesting uncle by block hash and index with wrong fields
test_rpc_call_err::<Option<RichBlock>>(
&client,
"eth_getUncleByBlockHashAndIndex",
rpc_params![true],
)
.await;
}
#[tokio::test(flavor = "multi_thread")]
async fn test_eth_get_uncle_by_block_number_and_index_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();
// Launch HTTP server with the specified RPC module
let handle = launch_http(vec![RethRpcModule::Eth]).await;
let client = handle.http_client().unwrap();
// Requesting uncle by block number and index with proper fields
test_rpc_call_ok::<Option<RichBlock>>(
&client,
"eth_getUncleByBlockNumberAndIndex",
rpc_params!["0x29c", "0x0"],
)
.await;
// Requesting uncle by block number and index with additional fields
test_rpc_call_ok::<Option<RichBlock>>(
&client,
"eth_getUncleByBlockNumberAndIndex",
rpc_params!["0x29c", "0x0", true],
)
.await;
// Requesting uncle by block number and index with missing fields
test_rpc_call_err::<Option<RichBlock>>(
&client,
"eth_getUncleByBlockNumberAndIndex",
rpc_params![],
)
.await;
// Requesting uncle by block number and index with wrong fields
test_rpc_call_err::<Option<RichBlock>>(
&client,
"eth_getUncleByBlockNumberAndIndex",
rpc_params![true],
)
.await;
}
#[tokio::test(flavor = "multi_thread")]
async fn test_eth_get_transaction_by_hash_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();
// Launch HTTP server with the specified RPC module
let handle = launch_http(vec![RethRpcModule::Eth]).await;
let client = handle.http_client().unwrap();
// Requesting transaction by hash with proper fields
test_rpc_call_ok::<Option<Transaction>>(
&client,
"eth_getTransactionByHash",
rpc_params!["0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b"],
)
.await;
// Requesting transaction by hash with additional fields
test_rpc_call_ok::<Option<Transaction>>(
&client,
"eth_getTransactionByHash",
rpc_params!["0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b", true],
)
.await;
// Requesting transaction by hash with missing fields
test_rpc_call_err::<Option<Transaction>>(&client, "eth_getTransactionByHash", rpc_params![])
.await;
// Requesting transaction by hash with wrong fields
test_rpc_call_err::<Option<Transaction>>(
&client,
"eth_getTransactionByHash",
rpc_params![true],
)
.await;
}
#[tokio::test(flavor = "multi_thread")]
async fn test_eth_get_transaction_by_block_hash_and_index_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();
// Launch HTTP server with the specified RPC module
let handle = launch_http(vec![RethRpcModule::Eth]).await;
let client = handle.http_client().unwrap();
// Requesting transaction by block hash and index with proper fields
test_rpc_call_ok::<Option<Transaction>>(
&client,
"eth_getTransactionByBlockHashAndIndex",
rpc_params!["0x1dad0df7c027bcc86d06b3a6709ff78decd732c37b73123453ba7d9463eae60d", "0x0"],
)
.await;
// Requesting transaction by block hash and index with additional fields
test_rpc_call_ok::<Option<Transaction>>(
&client,
"eth_getTransactionByBlockHashAndIndex",
rpc_params![
"0x1dad0df7c027bcc86d06b3a6709ff78decd732c37b73123453ba7d9463eae60d",
"0x0",
true
],
)
.await;
// Requesting transaction by block hash and index with missing fields
test_rpc_call_err::<Option<Transaction>>(
&client,
"eth_getTransactionByBlockHashAndIndex",
rpc_params![],
)
.await;
// Requesting transaction by block hash and index with wrong fields
test_rpc_call_err::<Option<Transaction>>(
&client,
"eth_getTransactionByBlockHashAndIndex",
rpc_params![true],
)
.await;
}
#[tokio::test(flavor = "multi_thread")]
async fn test_eth_get_transaction_by_block_number_and_index_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();
// Launch HTTP server with the specified RPC module
let handle = launch_http(vec![RethRpcModule::Eth]).await;
let client = handle.http_client().unwrap();
// Requesting transaction by block number and index with proper fields
test_rpc_call_ok::<Option<Transaction>>(
&client,
"eth_getTransactionByBlockNumberAndIndex",
rpc_params!["0x29c", "0x0"],
)
.await;
// Requesting transaction by block number and index with additional fields
test_rpc_call_ok::<Option<Transaction>>(
&client,
"eth_getTransactionByBlockNumberAndIndex",
rpc_params!["0x29c", "0x0", true],
)
.await;
// Requesting transaction by block number and index with missing fields
test_rpc_call_err::<Option<Transaction>>(
&client,
"eth_getTransactionByBlockNumberAndIndex",
rpc_params![],
)
.await;
// Requesting transaction by block number and index with wrong fields
test_rpc_call_err::<Option<Transaction>>(
&client,
"eth_getTransactionByBlockNumberAndIndex",
rpc_params![true],
)
.await;
}
#[tokio::test(flavor = "multi_thread")]
async fn test_eth_get_transaction_receipt_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();
// Launch HTTP server with the specified RPC module
let handle = launch_http(vec![RethRpcModule::Eth]).await;
let client = handle.http_client().unwrap();
// Requesting transaction receipt by transaction hash with proper fields
test_rpc_call_ok::<Option<TransactionReceipt>>(
&client,
"eth_getTransactionReceipt",
rpc_params!["0x85d995eba9763907fdf35cd2034144dd9d53ce32cbec21349d4b12823c6860c5"],
)
.await;
// Requesting transaction receipt by transaction hash with additional fields
test_rpc_call_ok::<Option<TransactionReceipt>>(
&client,
"eth_getTransactionReceipt",
rpc_params!["0x85d995eba9763907fdf35cd2034144dd9d53ce32cbec21349d4b12823c6860c5", true],
)
.await;
// Requesting transaction receipt by transaction hash with missing fields
test_rpc_call_err::<Option<TransactionReceipt>>(
&client,
"eth_getTransactionReceipt",
rpc_params![],
)
.await;
// Requesting transaction receipt by transaction hash with wrong fields
test_rpc_call_err::<Option<TransactionReceipt>>(
&client,
"eth_getTransactionReceipt",
rpc_params![true],
)
.await;
}
#[tokio::test(flavor = "multi_thread")]
async fn test_eth_get_balance_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();
// Launch HTTP server with the specified RPC module
let handle = launch_http(vec![RethRpcModule::Eth]).await;
let client = handle.http_client().unwrap();
// Vec of block number items
let block_number = vec!["latest", "earliest", "pending", "0x2"];
// Iterate over test cases
for param in block_number {
// Requesting balance by address with proper fields
test_rpc_call_ok::<U256>(
&client,
"eth_getBalance",
rpc_params!["0x407d73d8a49eeb85d32cf465507dd71d507100c1", param],
)
.await;
}
// Requesting balance by address with additional fields
test_rpc_call_ok::<U256>(
&client,
"eth_getBalance",
rpc_params!["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest", true],
)
.await;
// Requesting balance by address without block number which is optional
test_rpc_call_ok::<U256>(
&client,
"eth_getBalance",
rpc_params!["0x407d73d8a49eeb85d32cf465507dd71d507100c1"],
)
.await;
// Requesting balance by address with no field
test_rpc_call_err::<U256>(&client, "eth_getBalance", rpc_params![]).await;
// Requesting balance by address with wrong fields
test_rpc_call_err::<U256>(
&client,
"eth_getBalance",
rpc_params![true], // Incorrect parameters
)
.await;
}
#[tokio::test(flavor = "multi_thread")]
async fn test_eth_get_storage_at_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();
// Launch HTTP server with the specified RPC module
let handle = launch_http(vec![RethRpcModule::Eth]).await;
let client = handle.http_client().unwrap();
// Vec of block number items
let block_number = vec!["latest", "earliest", "pending", "0x2"];
// Iterate over test cases
for param in block_number {
// Requesting storage at a given address with proper fields
test_rpc_call_ok::<Bytes>(
&client,
"eth_getStorageAt",
rpc_params![
"0x295a70b2de5e3953354a6a8344e616ed314d7251", // Address
"0x0", // Position in the storage
param // Block number or tag
],
)
.await;
}
// Requesting storage at a given address with additional fields
test_rpc_call_ok::<Bytes>(
&client,
"eth_getStorageAt",
rpc_params![
"0x295a70b2de5e3953354a6a8344e616ed314d7251", // Address
"0x0", // Position in the storage
"latest", // Block number or tag
true // Additional field
],
)
.await;
// Requesting storage at a given address without block number which is optional
test_rpc_call_ok::<Bytes>(
&client,
"eth_getStorageAt",
rpc_params![
"0x295a70b2de5e3953354a6a8344e616ed314d7251", // Address
"0x0" // Position in the storage
],
)
.await;
// Requesting storage at a given address with no field
test_rpc_call_err::<Bytes>(&client, "eth_getStorageAt", rpc_params![]).await;
// Requesting storage at a given address with wrong fields
test_rpc_call_err::<Bytes>(
&client,
"eth_getStorageAt",
rpc_params![
"0x295a70b2de5e3953354a6a8344e616ed314d7251", // Address
"0x0", // Position in the storage
"not_valid_block_number" // Block number or tag
],
)
.await;
}
#[tokio::test(flavor = "multi_thread")]
async fn test_eth_get_transaction_count_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();
// Launch HTTP server with the specified RPC module
let handle = launch_http(vec![RethRpcModule::Eth]).await;
let client = handle.http_client().unwrap();
// Vec of block number items
let block_number = vec!["latest", "earliest", "pending", "0x2"];
// Iterate over test cases
for param in block_number {
// Requesting transaction count by address with proper fields
test_rpc_call_ok::<U256>(
&client,
"eth_getTransactionCount",
rpc_params![
"0x407d73d8a49eeb85d32cf465507dd71d507100c1", // Address
param // Block number or tag
],
)
.await;
}
// Requesting transaction count by address with additional fields
test_rpc_call_ok::<U256>(
&client,
"eth_getTransactionCount",
rpc_params![
"0x407d73d8a49eeb85d32cf465507dd71d507100c1", // Address
"latest", // Block number or tag
true // Additional field
],
)
.await;
// Requesting transaction count by address without block number which is optional
test_rpc_call_ok::<U256>(
&client,
"eth_getTransactionCount",
rpc_params![
"0x407d73d8a49eeb85d32cf465507dd71d507100c1" // Address
],
)
.await;
// Requesting transaction count by address with no field
test_rpc_call_err::<U256>(&client, "eth_getTransactionCount", rpc_params![]).await;
// Requesting transaction count by address with wrong fields
test_rpc_call_err::<U256>(
&client,
"eth_getTransactionCount",
rpc_params!["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "not_valid_block_number"], // Incorrect parameters
)
.await;
}
#[cfg(test)]
mod tests {
use super::*;