Skip to content

Commit 24c7f47

Browse files
authored
Merge pull request #51 from Quantus-Network/fix/clippy-error
Fix clippy error and add to CI
2 parents 4576d90 + d178e95 commit 24c7f47

23 files changed

Lines changed: 77 additions & 87 deletions

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ jobs:
6161
- name: Check Formatting
6262
run: cargo fmt --all -- --check
6363

64+
- name: Run Clippy
65+
run: cargo clippy --all-targets --all-features -- -D warnings
66+
6467
# Run tests (Non-chain only, as requested)
6568
- name: Run Tests
6669
run: cargo test -- --skip chain_ --test-threads=1 --nocapture

src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fn map_db_error(err: DbError) -> (StatusCode, String) {
150150
if msg.contains("duplicate key value violates unique constraint") {
151151
(
152152
StatusCode::CONFLICT,
153-
format!("The given value is conflicting with existing record"),
153+
"The given value is conflicting with existing record".to_string(),
154154
)
155155
} else {
156156
(

src/handlers/auth.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,28 +85,28 @@ pub async fn verify_login(
8585
warn!(error = %e, "verify_login: verify_address error");
8686
}
8787
let addr_ok = addr_res.map_err(|_| {
88-
AppError::Handler(HandlerError::Auth(AuthHandlerError::Unauthorized(format!(
89-
"address verification failed"
90-
))))
88+
AppError::Handler(HandlerError::Auth(AuthHandlerError::Unauthorized(
89+
"address verification failed".to_string(),
90+
)))
9191
})?;
9292
if !addr_ok {
9393
return Err(AppError::Handler(HandlerError::Auth(AuthHandlerError::Unauthorized(
94-
format!("address verification failed"),
94+
"address verification failed".to_string(),
9595
))));
9696
}
9797
let sig_res = SignatureService::verify_message(message.as_bytes(), &body.signature, &body.public_key);
9898
if let Err(e) = &sig_res {
9999
warn!(error = %e, "verify_login: verify_message error");
100100
}
101101
let sig_ok = sig_res.map_err(|_| {
102-
AppError::Handler(HandlerError::Auth(AuthHandlerError::Unauthorized(format!(
103-
"message verification failed"
104-
))))
102+
AppError::Handler(HandlerError::Auth(AuthHandlerError::Unauthorized(
103+
"message verification failed".to_string(),
104+
)))
105105
})?;
106106
debug!(addr_ok = addr_ok, sig_ok = sig_ok, "verify_login: verification results");
107107
if !sig_ok {
108108
return Err(AppError::Handler(HandlerError::Auth(AuthHandlerError::Unauthorized(
109-
format!("message verification failed"),
109+
"message verification failed".to_string(),
110110
))));
111111
}
112112

@@ -168,7 +168,7 @@ pub async fn handle_x_oauth(
168168
tracing::info!("Quan address from token: {}", quan_address);
169169

170170
let (auth_url, verifier) = state.twitter_gateway.generate_auth_url();
171-
let session_id = format!("{}|{}", quan_address, uuid::Uuid::new_v4().to_string());
171+
let session_id = format!("{}|{}", quan_address, uuid::Uuid::new_v4());
172172

173173
tracing::info!("Session id in cookies: {}", session_id);
174174

@@ -254,9 +254,9 @@ pub async fn handle_x_oauth_callback(
254254
tracing::debug!("Do X association...");
255255
let quan_address = {
256256
let Some(address) = session_id.split_once('|').map(|(left, _)| left) else {
257-
return Err(AppError::Handler(HandlerError::Auth(AuthHandlerError::OAuth(format!(
258-
"Session id malformed",
259-
)))));
257+
return Err(AppError::Handler(HandlerError::Auth(AuthHandlerError::OAuth(
258+
"Session id malformed".to_string(),
259+
))));
260260
};
261261

262262
address.to_string()

src/handlers/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,5 @@ pub fn validate_pagination_query(page: u32, page_size: u32) -> Result<(), AppErr
130130
}
131131

132132
fn calculate_total_pages(page_size: u32, total_items: u32) -> u32 {
133-
let total_pages = ((total_items as f64) / (page_size as f64)).ceil() as u32;
134-
135-
total_pages
133+
((total_items as f64) / (page_size as f64)).ceil() as u32
136134
}

src/handlers/raid_quest.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pub async fn handle_get_raid_leaderboard(
137137
meta: PaginationMetadata {
138138
page: params.page,
139139
page_size: params.page_size,
140-
total_items: total_items as u32,
140+
total_items,
141141
total_pages,
142142
},
143143
};
@@ -151,9 +151,9 @@ pub async fn handle_get_specific_raider_raid_leaderboard(
151151
Path((raider_id, raid_id)): Path<(String, i32)>,
152152
) -> Result<Json<SuccessResponse<RaidLeaderboard>>, AppError> {
153153
let Some(raider_leaderboard) = state.db.raid_leaderboards.get_raider_entry(raid_id, &raider_id).await? else {
154-
return Err(AppError::Database(DbError::RecordNotFound(format!(
155-
"No raider leaderboard is found"
156-
))));
154+
return Err(AppError::Database(DbError::RecordNotFound(
155+
"No raider leaderboard is found".to_string(),
156+
)));
157157
};
158158

159159
Ok(SuccessResponse::new(raider_leaderboard))
@@ -189,13 +189,13 @@ pub async fn handle_create_raid_submission(
189189
let (current_active_raid, user_x) = get_active_raid_and_x_association(&state, &user).await?;
190190

191191
let Some((reply_username, reply_id)) = parse_x_status_url(&payload.tweet_reply_link) else {
192-
return Err(AppError::Handler(HandlerError::InvalidBody(format!(
193-
"Couldn't parse tweet reply link"
194-
))));
192+
return Err(AppError::Handler(HandlerError::InvalidBody(
193+
"Couldn't parse tweet reply link".to_string(),
194+
)));
195195
};
196196
if user_x.username != reply_username {
197197
return Err(AppError::Handler(HandlerError::Auth(AuthHandlerError::Unauthorized(
198-
format!("Only tweet reply author is eligible to submit"),
198+
"Only tweet reply author is eligible to submit".to_string(),
199199
))));
200200
}
201201

@@ -224,7 +224,7 @@ pub async fn handle_delete_raid_submission(
224224

225225
if raid_submission.raider_id != user.quan_address.0 {
226226
return Err(AppError::Handler(HandlerError::Auth(AuthHandlerError::Unauthorized(
227-
format!("Only raid submission owner can delete"),
227+
"Only raid submission owner can delete".to_string(),
228228
))));
229229
}
230230

@@ -238,14 +238,14 @@ async fn get_active_raid_and_x_association(
238238
user: &Address,
239239
) -> Result<(RaidQuest, XAssociation), AppError> {
240240
let Some(current_active_raid) = state.db.raid_quests.find_active().await? else {
241-
return Err(AppError::Database(DbError::RecordNotFound(format!(
242-
"No active raid is found"
243-
))));
241+
return Err(AppError::Database(DbError::RecordNotFound(
242+
"No active raid is found".to_string(),
243+
)));
244244
};
245245
let Some(user_x) = state.db.x_associations.find_by_address(&user.quan_address).await? else {
246-
return Err(AppError::Database(DbError::RecordNotFound(format!(
247-
"User doesn't have X association"
248-
))));
246+
return Err(AppError::Database(DbError::RecordNotFound(
247+
"User doesn't have X association".to_string(),
248+
)));
249249
};
250250
Ok((current_active_raid, user_x))
251251
}
@@ -369,7 +369,7 @@ mod tests {
369369
.oneshot(
370370
Request::builder()
371371
.method("PUT")
372-
.uri(&format!("/raids/{}/finish", raid_id))
372+
.uri(format!("/raids/{}/finish", raid_id))
373373
.body(Body::empty())
374374
.unwrap(),
375375
)
@@ -405,7 +405,7 @@ mod tests {
405405
.oneshot(
406406
Request::builder()
407407
.method("PUT")
408-
.uri(&format!("/raids/{}/activate", raid_id))
408+
.uri(format!("/raids/{}/activate", raid_id))
409409
.body(Body::empty())
410410
.unwrap(),
411411
)
@@ -514,7 +514,7 @@ mod tests {
514514
.oneshot(
515515
Request::builder()
516516
.method("GET")
517-
.uri(&format!("/raiders/{}/leaderboard/{}", user.quan_address.0, raid_id,))
517+
.uri(format!("/raiders/{}/leaderboard/{}", user.quan_address.0, raid_id,))
518518
.body(Body::empty())
519519
.unwrap(),
520520
)
@@ -707,7 +707,7 @@ mod tests {
707707
.oneshot(
708708
Request::builder()
709709
.method("DELETE")
710-
.uri(&format!("/submissions/{}", submission_id))
710+
.uri(format!("/submissions/{}", submission_id))
711711
.body(Body::empty())
712712
.unwrap(),
713713
)
@@ -756,7 +756,7 @@ mod tests {
756756
.oneshot(
757757
Request::builder()
758758
.method("DELETE")
759-
.uri(&format!("/submissions/{}", submission_id))
759+
.uri(format!("/submissions/{}", submission_id))
760760
.body(Body::empty())
761761
.unwrap(),
762762
)

src/handlers/referral.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ pub async fn handle_add_referral(
6868

6969
Ok(SuccessResponse::new(referrer.referral_code))
7070
} else {
71-
return Err(AppError::Handler(HandlerError::Referral(
71+
Err(AppError::Handler(HandlerError::Referral(
7272
ReferralHandlerError::ReferralNotFound(format!("Referrer not found for code '{}'", submitted_code)),
73-
)));
73+
)))
7474
}
7575
}
7676

src/handlers/tweet_author.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ mod tests {
423423

424424
let author = state.db.tweet_authors.find_by_id("hello").await.unwrap().unwrap();
425425

426-
assert_eq!(author.is_ignored, true);
426+
assert!(author.is_ignored);
427427
}
428428

429429
#[tokio::test]

src/metrics.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ pub struct Metrics {
5454
pub registry: Arc<Registry>,
5555
}
5656

57+
impl Default for Metrics {
58+
fn default() -> Self {
59+
Self::new()
60+
}
61+
}
62+
5763
impl Metrics {
5864
pub fn new() -> Self {
5965
let registry = Registry::new();

src/models/raid_submission.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,13 @@ impl From<&TwitterTweet> for UpdateRaidSubmissionStats {
7676
let default_metrics = TweetPublicMetrics::default();
7777
let public_metrics = tweet.public_metrics.as_ref().unwrap_or(&default_metrics);
7878

79-
let update_payload = UpdateRaidSubmissionStats {
79+
UpdateRaidSubmissionStats {
8080
id: tweet.id.clone(),
8181
impression_count: public_metrics.impression_count as i32,
8282
like_count: public_metrics.like_count as i32,
8383
retweet_count: public_metrics.retweet_count as i32,
8484
reply_count: public_metrics.reply_count as i32,
85-
};
86-
87-
update_payload
85+
}
8886
}
8987
}
9088

src/models/relevant_tweet.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl NewTweetPayload {
9797
.unwrap();
9898
let created_at = tweet.created_at.ok_or_else(|| chrono::Utc::now().to_rfc3339()).unwrap();
9999

100-
let new_tweet = NewTweetPayload {
100+
NewTweetPayload {
101101
id: tweet.id,
102102
author_id: tweet.author_id.unwrap(),
103103
text: tweet.text,
@@ -106,8 +106,6 @@ impl NewTweetPayload {
106106
retweet_count: public_metrics.retweet_count as i32,
107107
reply_count: public_metrics.reply_count as i32,
108108
created_at: DateTime::parse_from_rfc3339(&created_at).unwrap().with_timezone(&Utc),
109-
};
110-
111-
new_tweet
109+
}
112110
}
113111
}

0 commit comments

Comments
 (0)