Skip to content

Commit

Permalink
fix(rpc): use hex arg for feeHistory (paradigmxyz#8506)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored and mw2000 committed Jun 5, 2024
1 parent 1014059 commit 38bbd33
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 50 deletions.
2 changes: 1 addition & 1 deletion crates/rpc/rpc-api/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ pub trait EthApi {
#[method(name = "feeHistory")]
async fn fee_history(
&self,
block_count: u64,
block_count: U64,
newest_block: BlockNumberOrTag,
reward_percentiles: Option<Vec<f64>>,
) -> RpcResult<FeeHistory>;
Expand Down
73 changes: 31 additions & 42 deletions crates/rpc/rpc-builder/tests/it/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use reth_rpc_api::{
};
use reth_rpc_builder::RethRpcModule;
use reth_rpc_types::{
trace::filter::TraceFilter, Filter, Index, Log, PendingTransactionFilterKind, RichBlock,
SyncStatus, Transaction, TransactionReceipt, TransactionRequest,
trace::filter::TraceFilter, FeeHistory, Filter, Index, Log, PendingTransactionFilterKind,
RichBlock, SyncStatus, Transaction, TransactionReceipt, TransactionRequest,
};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_json::Value;
Expand Down Expand Up @@ -167,7 +167,7 @@ where
EthApiClient::block_number(client).await.unwrap();
EthApiClient::get_code(client, address, None).await.unwrap();
EthApiClient::send_raw_transaction(client, tx).await.unwrap();
EthApiClient::fee_history(client, 0, block_number, None).await.unwrap();
EthApiClient::fee_history(client, U64::from(0), block_number, None).await.unwrap();
EthApiClient::balance(client, address, None).await.unwrap();
EthApiClient::transaction_count(client, address, None).await.unwrap();
EthApiClient::storage_at(client, address, U256::default().into(), None).await.unwrap();
Expand Down Expand Up @@ -552,7 +552,6 @@ async fn test_eth_logs_args() {

#[tokio::test(flavor = "multi_thread")]
async fn test_eth_get_block_by_number_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();

// Launch HTTP server with the specified RPC module
Expand Down Expand Up @@ -582,7 +581,6 @@ async fn test_eth_get_block_by_number_rpc_call() {

#[tokio::test(flavor = "multi_thread")]
async fn test_eth_get_block_by_hash_rpc_call() {
// Initialize test tracing for logging
reth_tracing::init_test_tracing();

// Launch HTTP server with the specified RPC module
Expand Down Expand Up @@ -616,7 +614,6 @@ async fn test_eth_get_block_by_hash_rpc_call() {

#[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
Expand Down Expand Up @@ -675,7 +672,6 @@ async fn test_eth_get_code_rpc_call() {

#[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
Expand All @@ -697,7 +693,6 @@ async fn test_eth_block_number_rpc_call() {

#[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
Expand All @@ -719,7 +714,6 @@ async fn test_eth_chain_id_rpc_call() {

#[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
Expand All @@ -741,7 +735,6 @@ async fn test_eth_syncing_rpc_call() {

#[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
Expand All @@ -763,7 +756,6 @@ async fn test_eth_protocol_version_rpc_call() {

#[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
Expand All @@ -784,7 +776,6 @@ async fn test_eth_coinbase_rpc_call() {

#[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
Expand All @@ -806,7 +797,6 @@ async fn test_eth_accounts_rpc_call() {

#[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
Expand Down Expand Up @@ -844,7 +834,6 @@ async fn test_eth_get_block_transaction_count_by_hash_rpc_call() {

#[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
Expand Down Expand Up @@ -886,7 +875,6 @@ async fn test_eth_get_block_transaction_count_by_number_rpc_call() {

#[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
Expand Down Expand Up @@ -919,7 +907,6 @@ async fn test_eth_get_uncle_count_by_block_hash_rpc_call() {

#[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
Expand Down Expand Up @@ -953,7 +940,6 @@ async fn test_eth_get_uncle_count_by_block_number_rpc_call() {

#[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
Expand Down Expand Up @@ -995,7 +981,6 @@ async fn test_eth_get_block_receipts_rpc_call() {

#[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
Expand Down Expand Up @@ -1041,7 +1026,6 @@ async fn test_eth_get_uncle_by_block_hash_and_index_rpc_call() {

#[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
Expand Down Expand Up @@ -1083,7 +1067,6 @@ async fn test_eth_get_uncle_by_block_number_and_index_rpc_call() {

#[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
Expand Down Expand Up @@ -1121,7 +1104,6 @@ async fn test_eth_get_transaction_by_hash_rpc_call() {

#[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
Expand Down Expand Up @@ -1167,7 +1149,6 @@ async fn test_eth_get_transaction_by_block_hash_and_index_rpc_call() {

#[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
Expand Down Expand Up @@ -1209,7 +1190,6 @@ async fn test_eth_get_transaction_by_block_number_and_index_rpc_call() {

#[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
Expand Down Expand Up @@ -1251,7 +1231,6 @@ async fn test_eth_get_transaction_receipt_rpc_call() {

#[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
Expand Down Expand Up @@ -1302,7 +1281,6 @@ async fn test_eth_get_balance_rpc_call() {

#[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
Expand Down Expand Up @@ -1369,7 +1347,6 @@ async fn test_eth_get_storage_at_rpc_call() {

#[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
Expand Down Expand Up @@ -1427,20 +1404,32 @@ async fn test_eth_get_transaction_count_rpc_call() {
.await;
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_rpc_builder_basic() {
let rpc_string = RawRpcParamsBuilder::default()
.method("eth_getBalance")
.add_param("0xaa00000000000000000000000000000000000000")
.add_param("0x898753d8fdd8d92c1907ca21e68c7970abd290c647a202091181deec3f30a0b2")
.set_id(1)
.build();

let expected = r#"{"jsonrpc":"2.0","id":1,"method":"eth_getBalance","params":["0xaa00000000000000000000000000000000000000","0x898753d8fdd8d92c1907ca21e68c7970abd290c647a202091181deec3f30a0b2"]}"#;
assert_eq!(rpc_string, expected, "RPC string did not match expected format.");
}
#[test]
fn test_rpc_builder_basic() {
let rpc_string = RawRpcParamsBuilder::default()
.method("eth_getBalance")
.add_param("0xaa00000000000000000000000000000000000000")
.add_param("0x898753d8fdd8d92c1907ca21e68c7970abd290c647a202091181deec3f30a0b2")
.set_id(1)
.build();

let expected = r#"{"jsonrpc":"2.0","id":1,"method":"eth_getBalance","params":["0xaa00000000000000000000000000000000000000","0x898753d8fdd8d92c1907ca21e68c7970abd290c647a202091181deec3f30a0b2"]}"#;
assert_eq!(rpc_string, expected, "RPC string did not match expected format.");
}

#[tokio::test(flavor = "multi_thread")]
async fn test_eth_fee_history_raw() {
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 by number with proper fields
test_rpc_call_ok::<Option<FeeHistory>>(
&client,
"eth_feeHistory",
rpc_params!["0x0", "latest", [0]],
)
.await;
}
14 changes: 7 additions & 7 deletions crates/rpc/rpc/src/eth/api/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,12 @@ where
/// Handler for: `eth_feeHistory`
async fn fee_history(
&self,
block_count: u64,
block_count: U64,
newest_block: BlockNumberOrTag,
reward_percentiles: Option<Vec<f64>>,
) -> Result<FeeHistory> {
trace!(target: "rpc::eth", ?block_count, ?newest_block, ?reward_percentiles, "Serving eth_feeHistory");
return Ok(Self::fee_history(self, block_count, newest_block, reward_percentiles).await?)
return Ok(Self::fee_history(self, block_count.to(), newest_block, reward_percentiles).await?)
}

/// Handler for: `eth_mining`
Expand Down Expand Up @@ -438,7 +438,7 @@ mod tests {
use reth_network_api::noop::NoopNetwork;
use reth_primitives::{
constants::ETHEREUM_BLOCK_GAS_LIMIT, BaseFeeParams, Block, BlockNumberOrTag, Header,
TransactionSigned, B256,
TransactionSigned, B256, U64,
};
use reth_provider::{
test_utils::{MockEthProvider, NoopProvider},
Expand Down Expand Up @@ -572,7 +572,7 @@ mod tests {
async fn test_fee_history_empty() {
let response = <EthApi<_, _, _, _> as EthApiServer>::fee_history(
&build_test_eth_api(NoopProvider::default()),
1,
U64::from(1),
BlockNumberOrTag::Latest,
None,
)
Expand All @@ -594,7 +594,7 @@ mod tests {

let response = <EthApi<_, _, _, _> as EthApiServer>::fee_history(
&eth_api,
newest_block + 1,
U64::from(newest_block + 1),
newest_block.into(),
Some(vec![10.0]),
)
Expand All @@ -617,7 +617,7 @@ mod tests {

let response = <EthApi<_, _, _, _> as EthApiServer>::fee_history(
&eth_api,
1,
U64::from(1),
(newest_block + 1000).into(),
Some(vec![10.0]),
)
Expand All @@ -640,7 +640,7 @@ mod tests {

let response = <EthApi<_, _, _, _> as EthApiServer>::fee_history(
&eth_api,
0,
U64::from(0),
newest_block.into(),
None,
)
Expand Down

0 comments on commit 38bbd33

Please sign in to comment.