Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
fix: missleading parse_unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
x3ccd4828 committed Nov 19, 2021
1 parent ffb1a8b commit 525d486
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions ethers-core/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ pub fn to_checksum(addr: &Address, chain_id: Option<u8>) -> String {
pub fn format_bytes32_string(text: &str) -> Result<[u8; 32], FormatBytes32StringError> {
let str_bytes: &[u8] = text.as_bytes();
if str_bytes.len() > 32 {
return Err(FormatBytes32StringError::TextTooLong)
return Err(FormatBytes32StringError::TextTooLong);
}

let mut bytes32: [u8; 32] = [0u8; 32];
Expand Down Expand Up @@ -284,10 +284,10 @@ fn estimate_priority_fee(rewards: Vec<Vec<U256>>) -> U256 {
let mut rewards: Vec<U256> =
rewards.iter().map(|r| r[0]).filter(|r| *r > U256::zero()).collect();
if rewards.is_empty() {
return U256::zero()
return U256::zero();
}
if rewards.len() == 1 {
return rewards[0]
return rewards[0];
}
// Sort the rewards as we will eventually take the median.
rewards.sort();
Expand Down Expand Up @@ -316,8 +316,8 @@ fn estimate_priority_fee(rewards: Vec<Vec<U256>>) -> U256 {

// If we encountered a big change in fees at a certain position, then consider only
// the values >= it.
let values = if *max_change >= EIP1559_FEE_ESTIMATION_THRESHOLD_MAX_CHANGE &&
(max_change_index >= (rewards.len() / 2))
let values = if *max_change >= EIP1559_FEE_ESTIMATION_THRESHOLD_MAX_CHANGE
&& (max_change_index >= (rewards.len() / 2))
{
rewards[max_change_index..].to_vec()
} else {
Expand Down Expand Up @@ -378,11 +378,11 @@ mod tests {
let gwei = parse_units(1.5, 9).unwrap();
assert_eq!(gwei.as_u64(), 15e8 as u64);

let eth_dec_float = parse_units(1.39563324, "ether").unwrap();
assert_eq!(eth_dec_float, U256::from_dec_str("1395633240000000000").unwrap());
let eth_dec_float = parse_units(1.395633240123456789, "ether").unwrap();
assert_eq!(eth_dec_float, U256::from_dec_str("1395633240123456789").unwrap());

let eth_dec_string = parse_units("1.39563324", "ether").unwrap();
assert_eq!(eth_dec_string, U256::from_dec_str("1395633240000000000").unwrap());
let eth_dec_string = parse_units("1.395633240123456789", "ether").unwrap();
assert_eq!(eth_dec_string, U256::from_dec_str("1395633240123456789").unwrap());

let eth = parse_units(1, "ether").unwrap();
assert_eq!(eth, WEI_IN_ETHER);
Expand Down

0 comments on commit 525d486

Please sign in to comment.