Skip to content

Commit e7e227f

Browse files
committedJan 28, 2025
Merge pull request #36 from aurora-is-near/chore-clippy-warnings
chore: fix clippy warnings
2 parents 0c8a62f + 12ad134 commit e7e227f

23 files changed

+70
-46
lines changed
 

‎dao/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ mod tests {
2323
assert_eq!(
2424
vars.get("NETWORK_NAME"),
2525
Some(&"mainnet_aurora_plus".to_string())
26-
)
26+
);
2727
}
2828

2929
#[test]

‎dao/src/models.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ pub struct TestData {
1414
pub content: String,
1515
}
1616

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

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

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

152+
#[allow(clippy::needless_pass_by_value)]
153+
#[allow(clippy::uninlined_format_args)]
146154
impl TestRun {
147155
pub fn new(conn: &Connection, network_name: String) -> Result<TestRun, rusqlite::Error> {
148156
//TODO: use https://github.com/SeaQL/sea-query/ for more user friendly queries formatting
149157
let test_run_query = format!(
150158
"SELECT * FROM {} WHERE test_run_network = '{}' ORDER BY test_run_db_id DESC LIMIT 1",
151-
RUNS_TABLE,
152-
network_name.as_str()
159+
RUNS_TABLE, network_name
153160
)
154161
.clone();
155162
debug!("Selecting test runs: {}", test_run_query);

‎dao/src/utils.rs

+33-25
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ pub use dotenv::dotenv;
22
pub use std::collections::HashMap;
33
pub use std::{env, path::Path, path::PathBuf};
44

5+
#[allow(clippy::unreadable_literal)]
56
const MAINNET_AURORA_CHAIN_ID: i64 = 1313161554;
7+
#[allow(clippy::unreadable_literal)]
68
const TESTNET_AURORA_CHAIN_ID: i64 = 1313161555;
9+
#[allow(clippy::unreadable_literal)]
710
const SEPOLIA_CHAIN_ID: i64 = 11155111;
811
const ROPSTEN_CHAIN_ID: i64 = 3;
912
const GOERLI_CHAIN_ID: i64 = 5;
1013

14+
#[must_use]
1115
pub fn load_env_file() -> HashMap<String, String> {
1216
dotenv().ok();
1317
let env_vars: HashMap<String, String> = env::vars()
@@ -16,11 +20,13 @@ pub fn load_env_file() -> HashMap<String, String> {
1620
env_vars
1721
}
1822

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

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

38+
#[must_use]
3239
pub fn get_chain_id(network_name: &str) -> Option<i64> {
3340
match network_name {
3441
"sepolia" => Some(SEPOLIA_CHAIN_ID),
3542
"ropsten" => Some(ROPSTEN_CHAIN_ID),
3643
"goerli" => Some(GOERLI_CHAIN_ID),
37-
"testnet_aurora_plus" => Some(TESTNET_AURORA_CHAIN_ID),
38-
"testnet_aurora" => Some(TESTNET_AURORA_CHAIN_ID),
39-
"mainnet_aurora_plus" => Some(MAINNET_AURORA_CHAIN_ID),
40-
"wss_mainnet_aurora_plus" => Some(MAINNET_AURORA_CHAIN_ID),
41-
"mainnet_aurora_plus_rpc_url" => Some(MAINNET_AURORA_CHAIN_ID),
42-
"new_mainnet_aurora_plus" => Some(MAINNET_AURORA_CHAIN_ID),
43-
"mainnet_aurora" => Some(MAINNET_AURORA_CHAIN_ID),
44+
"testnet_aurora_plus" | "testnet_aurora" => Some(TESTNET_AURORA_CHAIN_ID),
45+
"mainnet_aurora_plus"
46+
| "wss_mainnet_aurora_plus"
47+
| "mainnet_aurora_plus_rpc_url"
48+
| "new_mainnet_aurora_plus"
49+
| "mainnet_aurora" => Some(MAINNET_AURORA_CHAIN_ID),
4450
_ => Some(0),
4551
}
4652
}
4753

54+
#[must_use]
4855
pub fn get_client_version(network_name: &str) -> Option<String> {
4956
static AURORA_WEB3_CLIENT_VERSION: &str = "Aurora";
5057
match network_name {
51-
"sepolia" => Some(AURORA_WEB3_CLIENT_VERSION.to_string()),
5258
"ropsten" => Some("erigon/2022.99.99/linux-amd64/go1.18.3".to_string()), // https://rpc.ankr.com/eth_ropsten
5359
"goerli" => Some("Geth/v1.10.23-omnibus-b38477ec/linux-amd64/go1.18.5".to_string()), // infura
54-
"testnet_aurora_plus" => Some(AURORA_WEB3_CLIENT_VERSION.to_string()),
55-
"testnet_aurora" => Some(AURORA_WEB3_CLIENT_VERSION.to_string()),
56-
"mainnet_aurora_plus" => Some(AURORA_WEB3_CLIENT_VERSION.to_string()),
57-
"wss_mainnet_aurora_plus" => Some(AURORA_WEB3_CLIENT_VERSION.to_string()),
58-
"mainnet_aurora_plus_rpc_url" => Some(AURORA_WEB3_CLIENT_VERSION.to_string()),
59-
"new_mainnet_aurora_plus" => Some(AURORA_WEB3_CLIENT_VERSION.to_string()),
60-
"mainnet_aurora" => Some(AURORA_WEB3_CLIENT_VERSION.to_string()),
61-
_ => Some("".to_string()),
60+
"sepolia"
61+
| "testnet_aurora_plus"
62+
| "testnet_aurora"
63+
| "mainnet_aurora_plus"
64+
| "wss_mainnet_aurora_plus"
65+
| "mainnet_aurora_plus_rpc_url"
66+
| "new_mainnet_aurora_plus"
67+
| "mainnet_aurora" => Some(AURORA_WEB3_CLIENT_VERSION.to_string()),
68+
_ => Some(String::new()),
6269
}
6370
}
6471

72+
#[must_use]
6573
pub fn get_protocol_version(network: &str) -> Option<i32> {
6674
match network {
67-
"sepolia" => Some(65),
6875
"ropsten" => Some(0), // this one is unknown!
69-
"goerli" => Some(65),
70-
"testnet_aurora_plus" => Some(65), // 0x41
71-
"testnet_aurora" => Some(65), // 0x41
72-
"mainnet_aurora_plus" => Some(65), // 0x41
73-
"wss_mainnet_aurora_plus" => Some(65), // 0x41
74-
"mainnet_aurora_plus_rpc_url" => Some(65), // 0x41
75-
"new_mainnet_aurora_plus" => Some(65), // 0x41
76-
"mainnet_aurora" => Some(65), // 0x41
76+
"goerli"
77+
| "sepolia"
78+
| "testnet_aurora_plus"
79+
| "testnet_aurora"
80+
| "mainnet_aurora_plus"
81+
| "wss_mainnet_aurora_plus"
82+
| "mainnet_aurora_plus_rpc_url"
83+
| "new_mainnet_aurora_plus"
84+
| "mainnet_aurora" => Some(65), // 0x41
7785
_ => None,
7886
}
7987
}

‎dynamic_apis_tests/tests/it/configs/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,19 @@ pub struct Configs {
1313
pub protocol_version: String,
1414
}
1515

16+
#[allow(clippy::manual_let_else)]
1617
impl Configs {
1718
pub fn load() -> Result<Configs, rusqlite::Error> {
1819
let rpc_url = match get_env_var("RPC_URL") {
1920
Some(value) => value,
2021
None => panic!("Environment variable RPC_URL is not set"),
2122
};
22-
let api_key = match get_env_var("AURORA_PLUS_API_KEY") {
23-
Some(value) => value,
24-
None => "".to_owned(),
25-
};
23+
let api_key = get_env_var("AURORA_PLUS_API_KEY").unwrap_or_default();
2624
let network = match get_env_var("NETWORK_NAME") {
2725
Some(value) => value,
2826
None => panic!("Environment variable NETWORK_NAME is not set"),
2927
};
30-
let url = format!("{}{}", rpc_url, api_key);
28+
let url = format!("{rpc_url}{api_key}");
3129
let full_db_path = get_full_db_path().unwrap();
3230
let chain_id = get_chain_id(&network).unwrap().to_string();
3331
let client_version = get_client_version(&network).unwrap();

‎dynamic_apis_tests/tests/it/eth_block_number.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use tracing::info;
99
use crate::common::init;
1010
use crate::configs::Configs;
1111

12+
#[allow(clippy::needless_range_loop)]
1213
#[tokio::test]
1314
async fn test_eth_block_number() -> anyhow::Result<()> {
1415
let _guard = init();

‎dynamic_apis_tests/tests/it/eth_get_block_by_hash.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use tracing::info;
88
use crate::common::init;
99
use crate::configs::Configs;
1010

11+
#[allow(clippy::needless_range_loop)]
1112
#[tokio::test]
1213
async fn test_eth_get_block_by_hash() -> anyhow::Result<()> {
1314
let _guard = init();

‎dynamic_apis_tests/tests/it/eth_get_block_by_number.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use tracing::info;
88
use crate::common::init;
99
use crate::configs::Configs;
1010

11+
#[allow(clippy::needless_range_loop)]
1112
#[tokio::test]
1213
async fn test_eth_get_block_by_number() -> anyhow::Result<()> {
1314
let _guard = init();

‎dynamic_apis_tests/tests/it/eth_get_block_transaction_count_by_hash.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use tracing::info;
1010
use crate::common::init;
1111
use crate::configs::Configs;
1212

13+
#[allow(clippy::needless_range_loop)]
1314
#[tokio::test]
1415
async fn test_eth_get_block_transaction_count_by_hash() -> anyhow::Result<()> {
1516
let _guard = init();
@@ -57,8 +58,7 @@ async fn test_eth_get_block_transaction_count_by_hash() -> anyhow::Result<()> {
5758
.await;
5859
assert!(
5960
response.is_err(),
60-
"Expected an error response, but got {:?}",
61-
response
61+
"Expected an error response, but got {response:?}"
6262
);
6363
}
6464
Ok(())

‎dynamic_apis_tests/tests/it/eth_get_block_transaction_count_by_number.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use tracing::info;
99
use crate::common::init;
1010
use crate::configs::Configs;
1111

12+
#[allow(clippy::needless_range_loop)]
1213
#[tokio::test]
1314
async fn test_eth_get_block_transaction_count_by_number() -> anyhow::Result<()> {
1415
let _guard = init();

‎dynamic_apis_tests/tests/it/eth_get_logs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async fn test_eth_get_logs() -> anyhow::Result<()> {
4949
.unwrap();
5050
let transactions = TransactionReceipt::load(vec![receipt]).unwrap();
5151
for log in &transactions[0].logs {
52-
let topics: Vec<String> = log.topics.to_vec();
52+
let topics: Vec<String> = log.topics.clone();
5353
let log_filter = LogFilter {
5454
topics: vec![topics[0].clone()],
5555
address: log.address.to_string(),

‎dynamic_apis_tests/tests/it/eth_get_storage_at.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async fn test_eth_get_storage_at() -> anyhow::Result<()> {
3434
let response: Result<String, _> = client.request("eth_getStorageAt", params).await;
3535
let res = response.unwrap();
3636
let total_supply = i32::from_str_radix(&res[2..res.len()], 16).unwrap();
37-
let expected_total_supply = 1000000;
37+
let expected_total_supply = 1_000_000;
3838
info!("Asserting total_supply is {}", total_supply);
3939
assert_eq!(total_supply, expected_total_supply);
4040
let expected_token_name = String::from("Watermelon");
@@ -50,7 +50,7 @@ async fn test_eth_get_storage_at() -> anyhow::Result<()> {
5050
hex::decode(&token_name[2..token_name.len()]).expect("Decoding failed");
5151
let token_name_str = match std::str::from_utf8(&decoded_token_name) {
5252
Ok(v) => v,
53-
Err(e) => panic!("Invalid UTF-8 sequence: {}", e),
53+
Err(e) => panic!("Invalid UTF-8 sequence: {e}"),
5454
};
5555
info!("Asserting token name is: {:?}", token_name_str);
5656
assert!(token_name_str.contains(&expected_token_name));
@@ -67,7 +67,7 @@ async fn test_eth_get_storage_at() -> anyhow::Result<()> {
6767
hex::decode(&token_symbol[2..token_symbol.len()]).expect("Decoding failed");
6868
let token_symbol_str = match std::str::from_utf8(&decoded_token_symbol) {
6969
Ok(v) => v,
70-
Err(e) => panic!("Invalid UTF-8 sequence: {}", e),
70+
Err(e) => panic!("Invalid UTF-8 sequence: {e}"),
7171
};
7272
info!("Asserting token symbol is: {:?}", token_symbol_str);
7373
assert!(token_symbol_str.contains(&expected_token_symbol));

‎dynamic_apis_tests/tests/it/eth_get_transaction_by_block_hash_and_index.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ async fn test_eth_get_transaction_by_block_hash_and_index() -> anyhow::Result<()
5050
.await;
5151
assert!(
5252
response.is_err(),
53-
"Expected an error response, but got {:?}",
54-
response
53+
"Expected an error response, but got {response:?}"
5554
);
5655
info!("assert no transaction @ invalid transaction index");
5756
let invalid_transaction_index = 50;

‎dynamic_apis_tests/tests/it/eth_get_transaction_by_block_number_and_index.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ async fn test_eth_get_transaction_by_block_number_and_index() -> anyhow::Result<
5151
.await;
5252
assert!(
5353
response.is_err(),
54-
"Expected an error response, but got {:?}",
55-
response
54+
"Expected an error response, but got {response:?}"
5655
);
5756
info!("assert no transaction @ invalid transaction index");
5857
let invalid_transaction_index = 50;

‎dynamic_apis_tests/tests/it/eth_get_transaction_receipt.rs

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ async fn test_eth_get_transaction_receipt() -> anyhow::Result<()> {
100100
Ok(())
101101
}
102102

103+
#[allow(clippy::struct_field_names)]
103104
#[derive(Serialize, Deserialize, Debug)]
104105
#[serde(rename_all(serialize = "snake_case", deserialize = "camelCase"))]
105106
pub struct Log {

‎dynamic_apis_tests/tests/it/eth_get_uncle_by_block_hash_and_index.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use tracing::info;
88
use crate::common::init;
99
use crate::configs::Configs;
1010

11+
#[allow(clippy::needless_range_loop)]
1112
#[tokio::test]
1213
async fn test_eth_get_uncle_by_block_hash_and_index() -> anyhow::Result<()> {
1314
let _guard = init();

‎dynamic_apis_tests/tests/it/eth_get_uncle_by_block_number_and_index.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use tracing::info;
88
use crate::common::init;
99
use crate::configs::Configs;
1010

11+
#[allow(clippy::needless_range_loop)]
1112
#[tokio::test]
1213
async fn test_eth_get_uncle_by_block_number_and_index() -> anyhow::Result<()> {
1314
let _guard = init();

‎dynamic_apis_tests/tests/it/eth_get_uncle_count_by_block_hash.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::configs::Configs;
1010

1111
use crate::utils::hex_string_to_i32;
1212

13+
#[allow(clippy::needless_range_loop)]
1314
#[tokio::test]
1415
async fn test_eth_get_uncle_count_by_block_hash() -> anyhow::Result<()> {
1516
let _guard = init();

‎dynamic_apis_tests/tests/it/eth_get_uncle_count_by_block_number.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::configs::Configs;
1010

1111
use crate::utils::hex_string_to_i32;
1212

13+
#[allow(clippy::needless_range_loop)]
1314
#[tokio::test]
1415
async fn test_eth_get_uncle_count_by_block_number() -> anyhow::Result<()> {
1516
let _guard = init();

‎dynamic_apis_tests/tests/it/eth_get_work.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async fn test_eth_get_work() -> anyhow::Result<()> {
3434
// info!("{}", result);
3535
let does_exist: Vec<bool> = goerli_responses
3636
.iter()
37-
.map(|v| result.contains(&v.to_string()))
37+
.map(|v| result.contains(&(*v).to_string()))
3838
.collect();
3939
info!("Unsupported method ? {:?}", does_exist.contains(&true));
4040
}

‎dynamic_apis_tests/tests/it/eth_new_filter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async fn test_eth_new_filter() -> anyhow::Result<()> {
3333
.unwrap();
3434
let transactions = TransactionReceipt::load(vec![receipt]).unwrap();
3535
for log in &transactions[0].logs {
36-
let topics: Vec<String> = log.topics.to_vec();
36+
let topics: Vec<String> = log.topics.clone();
3737
let log_filter = LogFilter {
3838
topics: vec![topics[0].clone()],
3939
address: log.address.to_string(),

‎dynamic_apis_tests/tests/it/eth_send_raw_transaction.rs

+2
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,15 @@ async fn test_eth_send_raw_transaction_wtm() -> anyhow::Result<()> {
237237
Ok(())
238238
}
239239

240+
#[allow(clippy::unnecessary_wraps)]
240241
pub fn get_absolute_path(relative_path: &str) -> Option<PathBuf> {
241242
Some(Path::join(
242243
env::current_dir().unwrap().as_path(),
243244
Path::new(relative_path).to_str().unwrap(),
244245
))
245246
}
246247

248+
#[allow(clippy::unnecessary_wraps)]
247249
pub fn read_bytes_from_file(file: &str) -> Result<Bytes, AbiError> {
248250
let bytecode_path = get_absolute_path(file).unwrap();
249251
let bytecode_text = std::fs::read_to_string(&bytecode_path).unwrap();

‎dynamic_apis_tests/tests/it/eth_submit_hash_rate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async fn test_eth_submit_hash_rate() -> anyhow::Result<()> {
3838
// info!("{}", result);
3939
let does_exist: Vec<bool> = goerli_responses
4040
.iter()
41-
.map(|v| result.contains(&v.to_string()))
41+
.map(|v| result.contains(&(*v).to_string()))
4242
.collect();
4343
info!("Unsupported method ? {:?}", does_exist.contains(&true));
4444
}

‎dynamic_apis_tests/tests/it/utils/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ extern crate serde;
22
extern crate serde_derive;
33
extern crate serde_json;
44

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.