Skip to content

Commit

Permalink
Merge pull request #36 from aurora-is-near/chore-clippy-warnings
Browse files Browse the repository at this point in the history
chore: fix clippy warnings
  • Loading branch information
diegofigs committed Jan 28, 2025
2 parents 0c8a62f + 12ad134 commit e7e227f
Show file tree
Hide file tree
Showing 23 changed files with 70 additions and 46 deletions.
2 changes: 1 addition & 1 deletion dao/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod tests {
assert_eq!(
vars.get("NETWORK_NAME"),
Some(&"mainnet_aurora_plus".to_string())
)
);
}

#[test]
Expand Down
11 changes: 9 additions & 2 deletions dao/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub struct TestData {
pub content: String,
}

#[allow(clippy::let_and_return)]
#[allow(clippy::uninlined_format_args)]
impl TestData {
pub fn load(conn: &Connection, db_id: i32) -> Result<Vec<TestData>, rusqlite::Error> {
let test_data_query = format!(
Expand All @@ -40,6 +42,8 @@ pub struct TestDataGroup {
pub data: Vec<TestData>,
}

#[allow(clippy::needless_pass_by_value)]
#[allow(clippy::unnecessary_wraps)]
impl TestDataGroup {
pub fn load(conn: &Connection, db_id: i32) -> Result<Vec<TestDataGroup>, rusqlite::Error> {
let test_data: Vec<TestData> = TestData::load(conn, db_id).unwrap();
Expand Down Expand Up @@ -78,6 +82,8 @@ pub struct TestTask {
pub data_groups: Vec<TestDataGroup>,
}

#[allow(clippy::needless_pass_by_value)]
#[allow(clippy::uninlined_format_args)]
impl TestTask {
pub fn load(conn: &Connection, db_id: i32) -> Result<Vec<TestTask>, rusqlite::Error> {
let test_tasks_query = format!(
Expand Down Expand Up @@ -143,13 +149,14 @@ pub struct TestRun {
pub tasks: Vec<TestTask>,
}

#[allow(clippy::needless_pass_by_value)]
#[allow(clippy::uninlined_format_args)]
impl TestRun {
pub fn new(conn: &Connection, network_name: String) -> Result<TestRun, rusqlite::Error> {
//TODO: use https://github.com/SeaQL/sea-query/ for more user friendly queries formatting
let test_run_query = format!(
"SELECT * FROM {} WHERE test_run_network = '{}' ORDER BY test_run_db_id DESC LIMIT 1",
RUNS_TABLE,
network_name.as_str()
RUNS_TABLE, network_name
)
.clone();
debug!("Selecting test runs: {}", test_run_query);
Expand Down
58 changes: 33 additions & 25 deletions dao/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ pub use dotenv::dotenv;
pub use std::collections::HashMap;
pub use std::{env, path::Path, path::PathBuf};

#[allow(clippy::unreadable_literal)]
const MAINNET_AURORA_CHAIN_ID: i64 = 1313161554;
#[allow(clippy::unreadable_literal)]
const TESTNET_AURORA_CHAIN_ID: i64 = 1313161555;
#[allow(clippy::unreadable_literal)]
const SEPOLIA_CHAIN_ID: i64 = 11155111;
const ROPSTEN_CHAIN_ID: i64 = 3;
const GOERLI_CHAIN_ID: i64 = 5;

#[must_use]
pub fn load_env_file() -> HashMap<String, String> {
dotenv().ok();
let env_vars: HashMap<String, String> = env::vars()
Expand All @@ -16,11 +20,13 @@ pub fn load_env_file() -> HashMap<String, String> {
env_vars
}

#[must_use]
pub fn get_env_var(var: &str) -> Option<String> {
let vars = load_env_file();
Some(vars.get(var)?.to_string())
}

#[must_use]
pub fn get_full_db_path() -> Option<PathBuf> {
let db_dir = "../relayer-test-data-generator/db/test-data.sqlite3".to_string();
Some(Path::join(
Expand All @@ -29,51 +35,53 @@ pub fn get_full_db_path() -> Option<PathBuf> {
))
}

#[must_use]
pub fn get_chain_id(network_name: &str) -> Option<i64> {
match network_name {
"sepolia" => Some(SEPOLIA_CHAIN_ID),
"ropsten" => Some(ROPSTEN_CHAIN_ID),
"goerli" => Some(GOERLI_CHAIN_ID),
"testnet_aurora_plus" => Some(TESTNET_AURORA_CHAIN_ID),
"testnet_aurora" => Some(TESTNET_AURORA_CHAIN_ID),
"mainnet_aurora_plus" => Some(MAINNET_AURORA_CHAIN_ID),
"wss_mainnet_aurora_plus" => Some(MAINNET_AURORA_CHAIN_ID),
"mainnet_aurora_plus_rpc_url" => Some(MAINNET_AURORA_CHAIN_ID),
"new_mainnet_aurora_plus" => Some(MAINNET_AURORA_CHAIN_ID),
"mainnet_aurora" => Some(MAINNET_AURORA_CHAIN_ID),
"testnet_aurora_plus" | "testnet_aurora" => Some(TESTNET_AURORA_CHAIN_ID),
"mainnet_aurora_plus"
| "wss_mainnet_aurora_plus"
| "mainnet_aurora_plus_rpc_url"
| "new_mainnet_aurora_plus"
| "mainnet_aurora" => Some(MAINNET_AURORA_CHAIN_ID),
_ => Some(0),
}
}

#[must_use]
pub fn get_client_version(network_name: &str) -> Option<String> {
static AURORA_WEB3_CLIENT_VERSION: &str = "Aurora";
match network_name {
"sepolia" => Some(AURORA_WEB3_CLIENT_VERSION.to_string()),
"ropsten" => Some("erigon/2022.99.99/linux-amd64/go1.18.3".to_string()), // https://rpc.ankr.com/eth_ropsten
"goerli" => Some("Geth/v1.10.23-omnibus-b38477ec/linux-amd64/go1.18.5".to_string()), // infura
"testnet_aurora_plus" => Some(AURORA_WEB3_CLIENT_VERSION.to_string()),
"testnet_aurora" => Some(AURORA_WEB3_CLIENT_VERSION.to_string()),
"mainnet_aurora_plus" => Some(AURORA_WEB3_CLIENT_VERSION.to_string()),
"wss_mainnet_aurora_plus" => Some(AURORA_WEB3_CLIENT_VERSION.to_string()),
"mainnet_aurora_plus_rpc_url" => Some(AURORA_WEB3_CLIENT_VERSION.to_string()),
"new_mainnet_aurora_plus" => Some(AURORA_WEB3_CLIENT_VERSION.to_string()),
"mainnet_aurora" => Some(AURORA_WEB3_CLIENT_VERSION.to_string()),
_ => Some("".to_string()),
"sepolia"
| "testnet_aurora_plus"
| "testnet_aurora"
| "mainnet_aurora_plus"
| "wss_mainnet_aurora_plus"
| "mainnet_aurora_plus_rpc_url"
| "new_mainnet_aurora_plus"
| "mainnet_aurora" => Some(AURORA_WEB3_CLIENT_VERSION.to_string()),
_ => Some(String::new()),
}
}

#[must_use]
pub fn get_protocol_version(network: &str) -> Option<i32> {
match network {
"sepolia" => Some(65),
"ropsten" => Some(0), // this one is unknown!
"goerli" => Some(65),
"testnet_aurora_plus" => Some(65), // 0x41
"testnet_aurora" => Some(65), // 0x41
"mainnet_aurora_plus" => Some(65), // 0x41
"wss_mainnet_aurora_plus" => Some(65), // 0x41
"mainnet_aurora_plus_rpc_url" => Some(65), // 0x41
"new_mainnet_aurora_plus" => Some(65), // 0x41
"mainnet_aurora" => Some(65), // 0x41
"goerli"
| "sepolia"
| "testnet_aurora_plus"
| "testnet_aurora"
| "mainnet_aurora_plus"
| "wss_mainnet_aurora_plus"
| "mainnet_aurora_plus_rpc_url"
| "new_mainnet_aurora_plus"
| "mainnet_aurora" => Some(65), // 0x41
_ => None,
}
}
8 changes: 3 additions & 5 deletions dynamic_apis_tests/tests/it/configs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,19 @@ pub struct Configs {
pub protocol_version: String,
}

#[allow(clippy::manual_let_else)]
impl Configs {
pub fn load() -> Result<Configs, rusqlite::Error> {
let rpc_url = match get_env_var("RPC_URL") {
Some(value) => value,
None => panic!("Environment variable RPC_URL is not set"),
};
let api_key = match get_env_var("AURORA_PLUS_API_KEY") {
Some(value) => value,
None => "".to_owned(),
};
let api_key = get_env_var("AURORA_PLUS_API_KEY").unwrap_or_default();
let network = match get_env_var("NETWORK_NAME") {
Some(value) => value,
None => panic!("Environment variable NETWORK_NAME is not set"),
};
let url = format!("{}{}", rpc_url, api_key);
let url = format!("{rpc_url}{api_key}");
let full_db_path = get_full_db_path().unwrap();
let chain_id = get_chain_id(&network).unwrap().to_string();
let client_version = get_client_version(&network).unwrap();
Expand Down
1 change: 1 addition & 0 deletions dynamic_apis_tests/tests/it/eth_block_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use tracing::info;
use crate::common::init;
use crate::configs::Configs;

#[allow(clippy::needless_range_loop)]
#[tokio::test]
async fn test_eth_block_number() -> anyhow::Result<()> {
let _guard = init();
Expand Down
1 change: 1 addition & 0 deletions dynamic_apis_tests/tests/it/eth_get_block_by_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use tracing::info;
use crate::common::init;
use crate::configs::Configs;

#[allow(clippy::needless_range_loop)]
#[tokio::test]
async fn test_eth_get_block_by_hash() -> anyhow::Result<()> {
let _guard = init();
Expand Down
1 change: 1 addition & 0 deletions dynamic_apis_tests/tests/it/eth_get_block_by_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use tracing::info;
use crate::common::init;
use crate::configs::Configs;

#[allow(clippy::needless_range_loop)]
#[tokio::test]
async fn test_eth_get_block_by_number() -> anyhow::Result<()> {
let _guard = init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use tracing::info;
use crate::common::init;
use crate::configs::Configs;

#[allow(clippy::needless_range_loop)]
#[tokio::test]
async fn test_eth_get_block_transaction_count_by_hash() -> anyhow::Result<()> {
let _guard = init();
Expand Down Expand Up @@ -57,8 +58,7 @@ async fn test_eth_get_block_transaction_count_by_hash() -> anyhow::Result<()> {
.await;
assert!(
response.is_err(),
"Expected an error response, but got {:?}",
response
"Expected an error response, but got {response:?}"
);
}
Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use tracing::info;
use crate::common::init;
use crate::configs::Configs;

#[allow(clippy::needless_range_loop)]
#[tokio::test]
async fn test_eth_get_block_transaction_count_by_number() -> anyhow::Result<()> {
let _guard = init();
Expand Down
2 changes: 1 addition & 1 deletion dynamic_apis_tests/tests/it/eth_get_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async fn test_eth_get_logs() -> anyhow::Result<()> {
.unwrap();
let transactions = TransactionReceipt::load(vec![receipt]).unwrap();
for log in &transactions[0].logs {
let topics: Vec<String> = log.topics.to_vec();
let topics: Vec<String> = log.topics.clone();
let log_filter = LogFilter {
topics: vec![topics[0].clone()],
address: log.address.to_string(),
Expand Down
6 changes: 3 additions & 3 deletions dynamic_apis_tests/tests/it/eth_get_storage_at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async fn test_eth_get_storage_at() -> anyhow::Result<()> {
let response: Result<String, _> = client.request("eth_getStorageAt", params).await;
let res = response.unwrap();
let total_supply = i32::from_str_radix(&res[2..res.len()], 16).unwrap();
let expected_total_supply = 1000000;
let expected_total_supply = 1_000_000;
info!("Asserting total_supply is {}", total_supply);
assert_eq!(total_supply, expected_total_supply);
let expected_token_name = String::from("Watermelon");
Expand All @@ -50,7 +50,7 @@ async fn test_eth_get_storage_at() -> anyhow::Result<()> {
hex::decode(&token_name[2..token_name.len()]).expect("Decoding failed");
let token_name_str = match std::str::from_utf8(&decoded_token_name) {
Ok(v) => v,
Err(e) => panic!("Invalid UTF-8 sequence: {}", e),
Err(e) => panic!("Invalid UTF-8 sequence: {e}"),
};
info!("Asserting token name is: {:?}", token_name_str);
assert!(token_name_str.contains(&expected_token_name));
Expand All @@ -67,7 +67,7 @@ async fn test_eth_get_storage_at() -> anyhow::Result<()> {
hex::decode(&token_symbol[2..token_symbol.len()]).expect("Decoding failed");
let token_symbol_str = match std::str::from_utf8(&decoded_token_symbol) {
Ok(v) => v,
Err(e) => panic!("Invalid UTF-8 sequence: {}", e),
Err(e) => panic!("Invalid UTF-8 sequence: {e}"),
};
info!("Asserting token symbol is: {:?}", token_symbol_str);
assert!(token_symbol_str.contains(&expected_token_symbol));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ async fn test_eth_get_transaction_by_block_hash_and_index() -> anyhow::Result<()
.await;
assert!(
response.is_err(),
"Expected an error response, but got {:?}",
response
"Expected an error response, but got {response:?}"
);
info!("assert no transaction @ invalid transaction index");
let invalid_transaction_index = 50;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ async fn test_eth_get_transaction_by_block_number_and_index() -> anyhow::Result<
.await;
assert!(
response.is_err(),
"Expected an error response, but got {:?}",
response
"Expected an error response, but got {response:?}"
);
info!("assert no transaction @ invalid transaction index");
let invalid_transaction_index = 50;
Expand Down
1 change: 1 addition & 0 deletions dynamic_apis_tests/tests/it/eth_get_transaction_receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ async fn test_eth_get_transaction_receipt() -> anyhow::Result<()> {
Ok(())
}

#[allow(clippy::struct_field_names)]
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all(serialize = "snake_case", deserialize = "camelCase"))]
pub struct Log {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use tracing::info;
use crate::common::init;
use crate::configs::Configs;

#[allow(clippy::needless_range_loop)]
#[tokio::test]
async fn test_eth_get_uncle_by_block_hash_and_index() -> anyhow::Result<()> {
let _guard = init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use tracing::info;
use crate::common::init;
use crate::configs::Configs;

#[allow(clippy::needless_range_loop)]
#[tokio::test]
async fn test_eth_get_uncle_by_block_number_and_index() -> anyhow::Result<()> {
let _guard = init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::configs::Configs;

use crate::utils::hex_string_to_i32;

#[allow(clippy::needless_range_loop)]
#[tokio::test]
async fn test_eth_get_uncle_count_by_block_hash() -> anyhow::Result<()> {
let _guard = init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::configs::Configs;

use crate::utils::hex_string_to_i32;

#[allow(clippy::needless_range_loop)]
#[tokio::test]
async fn test_eth_get_uncle_count_by_block_number() -> anyhow::Result<()> {
let _guard = init();
Expand Down
2 changes: 1 addition & 1 deletion dynamic_apis_tests/tests/it/eth_get_work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async fn test_eth_get_work() -> anyhow::Result<()> {
// info!("{}", result);
let does_exist: Vec<bool> = goerli_responses
.iter()
.map(|v| result.contains(&v.to_string()))
.map(|v| result.contains(&(*v).to_string()))
.collect();
info!("Unsupported method ? {:?}", does_exist.contains(&true));
}
Expand Down
2 changes: 1 addition & 1 deletion dynamic_apis_tests/tests/it/eth_new_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async fn test_eth_new_filter() -> anyhow::Result<()> {
.unwrap();
let transactions = TransactionReceipt::load(vec![receipt]).unwrap();
for log in &transactions[0].logs {
let topics: Vec<String> = log.topics.to_vec();
let topics: Vec<String> = log.topics.clone();
let log_filter = LogFilter {
topics: vec![topics[0].clone()],
address: log.address.to_string(),
Expand Down
2 changes: 2 additions & 0 deletions dynamic_apis_tests/tests/it/eth_send_raw_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,15 @@ async fn test_eth_send_raw_transaction_wtm() -> anyhow::Result<()> {
Ok(())
}

#[allow(clippy::unnecessary_wraps)]
pub fn get_absolute_path(relative_path: &str) -> Option<PathBuf> {
Some(Path::join(
env::current_dir().unwrap().as_path(),
Path::new(relative_path).to_str().unwrap(),
))
}

#[allow(clippy::unnecessary_wraps)]
pub fn read_bytes_from_file(file: &str) -> Result<Bytes, AbiError> {
let bytecode_path = get_absolute_path(file).unwrap();
let bytecode_text = std::fs::read_to_string(&bytecode_path).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion dynamic_apis_tests/tests/it/eth_submit_hash_rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn test_eth_submit_hash_rate() -> anyhow::Result<()> {
// info!("{}", result);
let does_exist: Vec<bool> = goerli_responses
.iter()
.map(|v| result.contains(&v.to_string()))
.map(|v| result.contains(&(*v).to_string()))
.collect();
info!("Unsupported method ? {:?}", does_exist.contains(&true));
}
Expand Down
2 changes: 2 additions & 0 deletions dynamic_apis_tests/tests/it/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ extern crate serde;
extern crate serde_derive;
extern crate serde_json;

#[allow(clippy::needless_pass_by_value)]
pub fn hex_string_to_i32(s: String) -> i32 {
i32::from_str_radix(&s[2..s.len()], 16).unwrap()
}

#[allow(clippy::needless_pass_by_value)]
pub fn hex_string_to_i64(s: String) -> i64 {
i64::from_str_radix(&s[2..s.len()], 16).unwrap()
}

0 comments on commit e7e227f

Please sign in to comment.