diff --git a/dao/src/lib.rs b/dao/src/lib.rs index 3a2b1b0..3b8e318 100644 --- a/dao/src/lib.rs +++ b/dao/src/lib.rs @@ -23,7 +23,7 @@ mod tests { assert_eq!( vars.get("NETWORK_NAME"), Some(&"mainnet_aurora_plus".to_string()) - ) + ); } #[test] diff --git a/dao/src/models.rs b/dao/src/models.rs index 18a6402..d2a57fd 100644 --- a/dao/src/models.rs +++ b/dao/src/models.rs @@ -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, rusqlite::Error> { let test_data_query = format!( @@ -40,6 +42,8 @@ pub struct TestDataGroup { pub data: Vec, } +#[allow(clippy::needless_pass_by_value)] +#[allow(clippy::unnecessary_wraps)] impl TestDataGroup { pub fn load(conn: &Connection, db_id: i32) -> Result, rusqlite::Error> { let test_data: Vec = TestData::load(conn, db_id).unwrap(); @@ -78,6 +82,8 @@ pub struct TestTask { pub data_groups: Vec, } +#[allow(clippy::needless_pass_by_value)] +#[allow(clippy::uninlined_format_args)] impl TestTask { pub fn load(conn: &Connection, db_id: i32) -> Result, rusqlite::Error> { let test_tasks_query = format!( @@ -143,13 +149,14 @@ pub struct TestRun { pub tasks: Vec, } +#[allow(clippy::needless_pass_by_value)] +#[allow(clippy::uninlined_format_args)] impl TestRun { pub fn new(conn: &Connection, network_name: String) -> Result { //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); diff --git a/dao/src/utils.rs b/dao/src/utils.rs index 73ecc82..bcf855c 100644 --- a/dao/src/utils.rs +++ b/dao/src/utils.rs @@ -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 { dotenv().ok(); let env_vars: HashMap = env::vars() @@ -16,11 +20,13 @@ pub fn load_env_file() -> HashMap { env_vars } +#[must_use] pub fn get_env_var(var: &str) -> Option { let vars = load_env_file(); Some(vars.get(var)?.to_string()) } +#[must_use] pub fn get_full_db_path() -> Option { let db_dir = "../relayer-test-data-generator/db/test-data.sqlite3".to_string(); Some(Path::join( @@ -29,51 +35,53 @@ pub fn get_full_db_path() -> Option { )) } +#[must_use] pub fn get_chain_id(network_name: &str) -> Option { 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 { 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 { 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, } } diff --git a/dynamic_apis_tests/tests/it/configs/mod.rs b/dynamic_apis_tests/tests/it/configs/mod.rs index 09b0f8f..c9913f6 100644 --- a/dynamic_apis_tests/tests/it/configs/mod.rs +++ b/dynamic_apis_tests/tests/it/configs/mod.rs @@ -13,21 +13,19 @@ pub struct Configs { pub protocol_version: String, } +#[allow(clippy::manual_let_else)] impl Configs { pub fn load() -> Result { 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(); diff --git a/dynamic_apis_tests/tests/it/eth_block_number.rs b/dynamic_apis_tests/tests/it/eth_block_number.rs index 77d8baa..e8d94d8 100644 --- a/dynamic_apis_tests/tests/it/eth_block_number.rs +++ b/dynamic_apis_tests/tests/it/eth_block_number.rs @@ -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(); diff --git a/dynamic_apis_tests/tests/it/eth_get_block_by_hash.rs b/dynamic_apis_tests/tests/it/eth_get_block_by_hash.rs index 67ec22d..e36940b 100644 --- a/dynamic_apis_tests/tests/it/eth_get_block_by_hash.rs +++ b/dynamic_apis_tests/tests/it/eth_get_block_by_hash.rs @@ -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(); diff --git a/dynamic_apis_tests/tests/it/eth_get_block_by_number.rs b/dynamic_apis_tests/tests/it/eth_get_block_by_number.rs index a676339..89c137f 100644 --- a/dynamic_apis_tests/tests/it/eth_get_block_by_number.rs +++ b/dynamic_apis_tests/tests/it/eth_get_block_by_number.rs @@ -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(); diff --git a/dynamic_apis_tests/tests/it/eth_get_block_transaction_count_by_hash.rs b/dynamic_apis_tests/tests/it/eth_get_block_transaction_count_by_hash.rs index d58b082..d95bb18 100644 --- a/dynamic_apis_tests/tests/it/eth_get_block_transaction_count_by_hash.rs +++ b/dynamic_apis_tests/tests/it/eth_get_block_transaction_count_by_hash.rs @@ -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(); @@ -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(()) diff --git a/dynamic_apis_tests/tests/it/eth_get_block_transaction_count_by_number.rs b/dynamic_apis_tests/tests/it/eth_get_block_transaction_count_by_number.rs index 435b506..2e23cf9 100644 --- a/dynamic_apis_tests/tests/it/eth_get_block_transaction_count_by_number.rs +++ b/dynamic_apis_tests/tests/it/eth_get_block_transaction_count_by_number.rs @@ -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(); diff --git a/dynamic_apis_tests/tests/it/eth_get_logs.rs b/dynamic_apis_tests/tests/it/eth_get_logs.rs index 131b5d1..8ac3cf5 100644 --- a/dynamic_apis_tests/tests/it/eth_get_logs.rs +++ b/dynamic_apis_tests/tests/it/eth_get_logs.rs @@ -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 = log.topics.to_vec(); + let topics: Vec = log.topics.clone(); let log_filter = LogFilter { topics: vec![topics[0].clone()], address: log.address.to_string(), diff --git a/dynamic_apis_tests/tests/it/eth_get_storage_at.rs b/dynamic_apis_tests/tests/it/eth_get_storage_at.rs index e4c1f43..3672653 100644 --- a/dynamic_apis_tests/tests/it/eth_get_storage_at.rs +++ b/dynamic_apis_tests/tests/it/eth_get_storage_at.rs @@ -34,7 +34,7 @@ async fn test_eth_get_storage_at() -> anyhow::Result<()> { let response: Result = 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"); @@ -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)); @@ -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)); diff --git a/dynamic_apis_tests/tests/it/eth_get_transaction_by_block_hash_and_index.rs b/dynamic_apis_tests/tests/it/eth_get_transaction_by_block_hash_and_index.rs index fc22a3b..cab3bfd 100644 --- a/dynamic_apis_tests/tests/it/eth_get_transaction_by_block_hash_and_index.rs +++ b/dynamic_apis_tests/tests/it/eth_get_transaction_by_block_hash_and_index.rs @@ -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; diff --git a/dynamic_apis_tests/tests/it/eth_get_transaction_by_block_number_and_index.rs b/dynamic_apis_tests/tests/it/eth_get_transaction_by_block_number_and_index.rs index 083d821..677043c 100644 --- a/dynamic_apis_tests/tests/it/eth_get_transaction_by_block_number_and_index.rs +++ b/dynamic_apis_tests/tests/it/eth_get_transaction_by_block_number_and_index.rs @@ -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; diff --git a/dynamic_apis_tests/tests/it/eth_get_transaction_receipt.rs b/dynamic_apis_tests/tests/it/eth_get_transaction_receipt.rs index e2aec0d..6b2bb03 100644 --- a/dynamic_apis_tests/tests/it/eth_get_transaction_receipt.rs +++ b/dynamic_apis_tests/tests/it/eth_get_transaction_receipt.rs @@ -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 { diff --git a/dynamic_apis_tests/tests/it/eth_get_uncle_by_block_hash_and_index.rs b/dynamic_apis_tests/tests/it/eth_get_uncle_by_block_hash_and_index.rs index 14be4f5..7be57f1 100644 --- a/dynamic_apis_tests/tests/it/eth_get_uncle_by_block_hash_and_index.rs +++ b/dynamic_apis_tests/tests/it/eth_get_uncle_by_block_hash_and_index.rs @@ -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(); diff --git a/dynamic_apis_tests/tests/it/eth_get_uncle_by_block_number_and_index.rs b/dynamic_apis_tests/tests/it/eth_get_uncle_by_block_number_and_index.rs index 2780e8c..e429c75 100644 --- a/dynamic_apis_tests/tests/it/eth_get_uncle_by_block_number_and_index.rs +++ b/dynamic_apis_tests/tests/it/eth_get_uncle_by_block_number_and_index.rs @@ -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(); diff --git a/dynamic_apis_tests/tests/it/eth_get_uncle_count_by_block_hash.rs b/dynamic_apis_tests/tests/it/eth_get_uncle_count_by_block_hash.rs index d9bdbe3..549be64 100644 --- a/dynamic_apis_tests/tests/it/eth_get_uncle_count_by_block_hash.rs +++ b/dynamic_apis_tests/tests/it/eth_get_uncle_count_by_block_hash.rs @@ -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(); diff --git a/dynamic_apis_tests/tests/it/eth_get_uncle_count_by_block_number.rs b/dynamic_apis_tests/tests/it/eth_get_uncle_count_by_block_number.rs index 3f87d48..ebc32f3 100644 --- a/dynamic_apis_tests/tests/it/eth_get_uncle_count_by_block_number.rs +++ b/dynamic_apis_tests/tests/it/eth_get_uncle_count_by_block_number.rs @@ -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(); diff --git a/dynamic_apis_tests/tests/it/eth_get_work.rs b/dynamic_apis_tests/tests/it/eth_get_work.rs index 37d6343..49356ed 100644 --- a/dynamic_apis_tests/tests/it/eth_get_work.rs +++ b/dynamic_apis_tests/tests/it/eth_get_work.rs @@ -34,7 +34,7 @@ async fn test_eth_get_work() -> anyhow::Result<()> { // info!("{}", result); let does_exist: Vec = 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)); } diff --git a/dynamic_apis_tests/tests/it/eth_new_filter.rs b/dynamic_apis_tests/tests/it/eth_new_filter.rs index 387a4bd..c22291a 100644 --- a/dynamic_apis_tests/tests/it/eth_new_filter.rs +++ b/dynamic_apis_tests/tests/it/eth_new_filter.rs @@ -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 = log.topics.to_vec(); + let topics: Vec = log.topics.clone(); let log_filter = LogFilter { topics: vec![topics[0].clone()], address: log.address.to_string(), diff --git a/dynamic_apis_tests/tests/it/eth_send_raw_transaction.rs b/dynamic_apis_tests/tests/it/eth_send_raw_transaction.rs index f250715..7b11cd8 100644 --- a/dynamic_apis_tests/tests/it/eth_send_raw_transaction.rs +++ b/dynamic_apis_tests/tests/it/eth_send_raw_transaction.rs @@ -237,6 +237,7 @@ async fn test_eth_send_raw_transaction_wtm() -> anyhow::Result<()> { Ok(()) } +#[allow(clippy::unnecessary_wraps)] pub fn get_absolute_path(relative_path: &str) -> Option { Some(Path::join( env::current_dir().unwrap().as_path(), @@ -244,6 +245,7 @@ pub fn get_absolute_path(relative_path: &str) -> Option { )) } +#[allow(clippy::unnecessary_wraps)] pub fn read_bytes_from_file(file: &str) -> Result { let bytecode_path = get_absolute_path(file).unwrap(); let bytecode_text = std::fs::read_to_string(&bytecode_path).unwrap(); diff --git a/dynamic_apis_tests/tests/it/eth_submit_hash_rate.rs b/dynamic_apis_tests/tests/it/eth_submit_hash_rate.rs index d5035ed..028bfff 100644 --- a/dynamic_apis_tests/tests/it/eth_submit_hash_rate.rs +++ b/dynamic_apis_tests/tests/it/eth_submit_hash_rate.rs @@ -38,7 +38,7 @@ async fn test_eth_submit_hash_rate() -> anyhow::Result<()> { // info!("{}", result); let does_exist: Vec = 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)); } diff --git a/dynamic_apis_tests/tests/it/utils/mod.rs b/dynamic_apis_tests/tests/it/utils/mod.rs index 1003ba8..2315ccf 100644 --- a/dynamic_apis_tests/tests/it/utils/mod.rs +++ b/dynamic_apis_tests/tests/it/utils/mod.rs @@ -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() }