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

eth_feeHistory Implementation #204

Merged
merged 28 commits into from
Mar 10, 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
Prev Previous commit
Next Next commit
fee history formating
  • Loading branch information
sfyll committed Mar 9, 2023
commit 2b26f40a7664ef4afe3f03ca3b7a26a995d22510
102 changes: 70 additions & 32 deletions tests/feehistory.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use config::{CliConfig, Config};
use env_logger::Env;
use eyre::Result;
use helios::{prelude::*};
use config::{CliConfig, Config};

use helios::prelude::*;

#[tokio::test]
async fn feehistory() -> Result<()> {
@@ -12,7 +11,7 @@ async fn feehistory() -> Result<()> {
// Load the config from the global config file
let config_path = home::home_dir().unwrap().join(".helios/helios.toml");
let config = Config::from_file(&config_path, "mainnet", &CliConfig::default());

let mut client: Client<FileDB> = match ClientBuilder::new().config(config).build() {
Ok(client) => client,
Err(err) => {
@@ -29,49 +28,88 @@ async fn feehistory() -> Result<()> {
log::info!("head_block_num: {}", &head_block_num);
let block = BlockTag::Latest;
let block_number = BlockTag::Number(head_block_num);
log::info!(
"block {:?} and block_number {:?}",
block, block_number
);
log::info!("block {:?} and block_number {:?}", block, block_number);
let my_array: Vec<f64> = vec![];

//below test are lacking access to ExecutionPayload which would give visibility into which blocks we know about

//test one block query from latest
let fee_history = client.get_fee_history(1, head_block_num, &my_array).await?.unwrap();
let fee_history = client
.get_fee_history(1, head_block_num, &my_array)
.await?
.unwrap();
assert_eq!(fee_history.base_fee_per_gas.len(), 2);
assert_eq!(fee_history.oldest_block.as_u64(), head_block_num);

//test 10000 delta, will return as much as we can
let fee_history = match client.get_fee_history(10_000, head_block_num, &my_array).await? {
let fee_history = match client
.get_fee_history(10_000, head_block_num, &my_array)
.await?
{
Some(fee_history) => fee_history,
None => panic!("returned empty gas fee, inputs where the following:
Block amount {:?}, head_block_num {:?}, my_array {:?}", 10_000, head_block_num, &my_array),
None => panic!(
"returned empty gas fee, inputs where the following:
Block amount {:?}, head_block_num {:?}, my_array {:?}",
10_000, head_block_num, &my_array
),
};
assert!(fee_history.base_fee_per_gas.len() > 0, "fee_history.base_fee_per_gas.len() {:?}", fee_history.base_fee_per_gas.len());
assert!(
fee_history.base_fee_per_gas.len() > 0,
"fee_history.base_fee_per_gas.len() {:?}",
fee_history.base_fee_per_gas.len()
);

//test 10000 block away, will return none
let fee_history = client.get_fee_history(1, head_block_num - 10_000, &my_array).await?;
assert!(fee_history.is_none(), "fee_history.is_none() {:?}", fee_history.is_none());

//test 10000 block away, will return none
let fee_history = client
.get_fee_history(1, head_block_num - 10_000, &my_array)
.await?;
assert!(
fee_history.is_none(),
"fee_history.is_none() {:?}",
fee_history.is_none()
);

//test 20 block away, should return array of size 21, our 20 block of interest + the next one
//test 20 block away, should return array of size 21, our 20 block of interest + the next one
//oldest block should be 19 block away, including it
let fee_history = client.get_fee_history(20, head_block_num, &my_array).await?.unwrap();
assert_eq!(fee_history.base_fee_per_gas.len(), 21, "fee_history.base_fee_per_gas.len() {:?} vs 21", fee_history.base_fee_per_gas.len());
assert_eq!(fee_history.oldest_block.as_u64(), head_block_num - 19,
"fee_history.oldest_block.as_u64() {:?} vs head_block_num {:?} - 19",
fee_history.oldest_block.as_u64(), head_block_num);
let fee_history = client
.get_fee_history(20, head_block_num, &my_array)
.await?
.unwrap();
assert_eq!(
fee_history.base_fee_per_gas.len(),
21,
"fee_history.base_fee_per_gas.len() {:?} vs 21",
fee_history.base_fee_per_gas.len()
);
assert_eq!(
fee_history.oldest_block.as_u64(),
head_block_num - 19,
"fee_history.oldest_block.as_u64() {:?} vs head_block_num {:?} - 19",
fee_history.oldest_block.as_u64(),
head_block_num
);

//test whatever blocks ahead, but that will fetch one block behind.
//test whatever blocks ahead, but that will fetch one block behind.
//This should returns an answer of size two as we'll cap this request to newest block we know
// we refresh paramaters to make sure head_block_num is in line with newest block of our payload
let head_block_num = client.get_block_number().await?;
let fee_history = client.get_fee_history(1, head_block_num+1000, &my_array).await?.unwrap();
assert_eq!(fee_history.base_fee_per_gas.len(), 2, "fee_history.base_fee_per_gas.len() {:?} vs 2", fee_history.base_fee_per_gas.len());
assert_eq!(fee_history.oldest_block.as_u64(), head_block_num,
"fee_history.oldest_block.as_u64() {:?} vs head_block_num {:?}",
fee_history.oldest_block.as_u64(), head_block_num);
let fee_history = client
.get_fee_history(1, head_block_num + 1000, &my_array)
.await?
.unwrap();
assert_eq!(
fee_history.base_fee_per_gas.len(),
2,
"fee_history.base_fee_per_gas.len() {:?} vs 2",
fee_history.base_fee_per_gas.len()
);
assert_eq!(
fee_history.oldest_block.as_u64(),
head_block_num,
"fee_history.oldest_block.as_u64() {:?} vs head_block_num {:?}",
fee_history.oldest_block.as_u64(),
head_block_num
);

Ok(())
}
}