Skip to content

Commit a2bf88a

Browse files
authored
Merge pull request #155 from semiotic-ai/ci_clippy_fail
ci: fix clippy
2 parents 08bc8dc + d052ac1 commit a2bf88a

File tree

8 files changed

+43
-46
lines changed

8 files changed

+43
-46
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
key: ${{ runner.os }}-cargo-clippy
3636
- run: |
3737
rustup component add clippy
38-
cargo clippy --all-features -- -D clippy::all
38+
cargo clippy --all-targets --all-features -- -D warnings
3939
4040
test-and-coverage:
4141
name: cargo test and coverage

tap_aggregator/src/aggregator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ mod tests {
149149
.await
150150
.unwrap();
151151
receipts.push(receipt.clone());
152-
receipts.push(receipt.clone());
152+
receipts.push(receipt);
153153

154154
let res = aggregator::check_signatures_unique(&receipts);
155155
assert!(res.is_err());

tap_aggregator/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use clap::Parser;
88
use ethers_signers::{coins_bip39::English, MnemonicBuilder};
99
use tokio::signal::unix::{signal, SignalKind};
1010

11-
use log::{debug, info, warn};
11+
use log::{debug, info};
1212
use tap_aggregator::metrics;
1313
use tap_aggregator::server;
1414

tap_core/src/adapters/test/receipt_checks_adapter_test.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ mod receipt_checks_adapter_unit_test {
6868
.await;
6969
let receipt_storage = Arc::new(RwLock::new(receipts));
7070

71-
let query_appraisals = (0..11)
72-
.into_iter()
73-
.map(|id| (id, 100u128))
74-
.collect::<HashMap<_, _>>();
71+
let query_appraisals = (0..11).map(|id| (id, 100u128)).collect::<HashMap<_, _>>();
7572

7673
let query_appraisals_storage = Arc::new(RwLock::new(query_appraisals));
7774

tap_core/src/tap_manager/test/manager_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright 2023-, Semiotic AI, Inc.
22
// SPDX-License-Identifier: Apache-2.0
3-
#[cfg(test)]
43

5-
mod manager_test {
4+
#[cfg(test)]
5+
mod manager_unit_test {
66
use std::{
77
collections::{HashMap, HashSet},
88
str::FromStr,

tap_integration_tests/clippy.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Since this whole crate is only for testing, we relax some of the clippy rules
2+
too-many-arguments-threshold = 15

tap_integration_tests/tests/indexer_mock/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<
9696
receipt_count: Arc::new(AtomicU64::new(0)),
9797
threshold,
9898
aggregator_client: (
99-
HttpClientBuilder::default().build(format!("{}", aggregate_server_address))?,
99+
HttpClientBuilder::default().build(aggregate_server_address)?,
100100
aggregate_server_api_version,
101101
),
102102
})
@@ -234,8 +234,7 @@ async fn request_rav<
234234
.await?;
235235
{
236236
let mut manager_guard = manager.lock().await;
237-
let _result =
238-
manager_guard.verify_and_store_rav(rav_request.expected_rav, remote_rav_result.data)?;
237+
manager_guard.verify_and_store_rav(rav_request.expected_rav, remote_rav_result.data)?;
239238
}
240239

241240
// For these tests, we expect every receipt to be valid, i.e. there should be no invalid receipts, nor any missing receipts (less than the expected threshold).
@@ -259,5 +258,5 @@ fn get_current_timestamp_u64_ns() -> Result<u64> {
259258
}
260259

261260
fn to_rpc_error(e: Box<dyn std::error::Error>, msg: &str) -> jsonrpsee::types::ErrorObjectOwned {
262-
jsonrpsee::types::ErrorObject::owned(-32000, format!("{} - {}", e.to_string(), msg), None::<()>)
261+
jsonrpsee::types::ErrorObject::owned(-32000, format!("{} - {}", e, msg), None::<()>)
263262
}

tap_integration_tests/tests/showcase.rs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -639,22 +639,24 @@ async fn test_manager_wrong_aggregator_keys(
639639

640640
let mut counter = 1;
641641
for (receipt_1, id) in requests {
642-
let result = client_1.request("request", (id, receipt_1)).await;
642+
let result: Result<(), jsonrpsee::core::Error> =
643+
client_1.request("request", (id, receipt_1)).await;
643644
// The rav request is being made with messages that have been signed with a key that differs from the gateway aggregator's.
644645
// So the Gateway Aggregator should send an error to the requesting Indexer.
645646
// And so the Indexer should then return an error to the clinet when a rav request is made.
646647
// A rav request is made when the number of receipts sent = receipt_threshold_1.
647648
// result should be an error when counter = multiple of receipt_threshold_1 and Ok otherwise.
648649
if (counter % receipt_threshold_1) == 0 {
649-
match result {
650-
Ok(()) => panic!("Gateway Aggregator should have sent an error to the Indexer."),
651-
Err(_) => {}
652-
}
650+
assert!(
651+
result.is_err(),
652+
"Gateway Aggregator should have sent an error to the Indexer."
653+
);
653654
} else {
654-
match result {
655-
Ok(()) => {}
656-
Err(e) => panic!("Error making receipt request: {:?}", e),
657-
}
655+
assert!(
656+
result.is_ok(),
657+
"Error making receipt request: {:?}",
658+
result.unwrap_err()
659+
);
658660
}
659661
counter += 1;
660662
}
@@ -680,21 +682,20 @@ async fn test_manager_wrong_requestor_keys(
680682

681683
let mut counter = 1;
682684
for (receipt_1, id) in requests {
683-
let result = client_1.request("request", (id, receipt_1)).await;
685+
let result: Result<(), jsonrpsee::core::Error> =
686+
client_1.request("request", (id, receipt_1)).await;
684687
// The receipts have been signed with a key that the Indexer is not expecting.
685688
// So the Indexer should return an error when a rav request is made, because they will not have any valid receipts for the request.
686689
// A rav request is made when the number of receipts sent = receipt_threshold_1.
687690
// result should be an error when counter = multiple of receipt_threshold_1 and Ok otherwise.
688691
if (counter % receipt_threshold_1) == 0 {
689-
match result {
690-
Ok(()) => panic!("Should have failed signature verification"),
691-
Err(_) => {}
692-
}
692+
assert!(result.is_err(), "Should have failed signature verification");
693693
} else {
694-
match result {
695-
Ok(()) => {}
696-
Err(e) => panic!("Error making receipt request: {:?}", e),
697-
}
694+
assert!(
695+
result.is_ok(),
696+
"Error making receipt request: {:?}",
697+
result.unwrap_err()
698+
);
698699
}
699700
counter += 1;
700701
}
@@ -740,22 +741,21 @@ async fn test_tap_manager_rav_timestamp_cuttoff(
740741

741742
let mut counter = 1;
742743
for (receipt_1, id) in requests {
743-
let result = client_1.request("request", (id, receipt_1)).await;
744+
let result: Result<(), jsonrpsee::core::Error> =
745+
client_1.request("request", (id, receipt_1)).await;
744746

745747
// The first receipt in the second batch has the same timestamp as the last receipt in the first batch.
746748
// TAP manager should ignore this receipt when creating the second RAV request.
747749
// The indexer_mock will throw an error if the number of receipts in RAV request is less than the expected number.
748750
// An error is expected when requesting the second RAV.
749751
if counter == 2 * receipt_threshold_1 {
750-
match result {
751-
Ok(()) => panic!("Should have failed RAV request"),
752-
Err(_) => {}
753-
}
752+
assert!(result.is_err(), "Should have failed RAV request");
754753
} else {
755-
match result {
756-
Ok(()) => {}
757-
Err(e) => panic!("Error making receipt request: {:?}", e),
758-
}
754+
assert!(
755+
result.is_ok(),
756+
"Error making receipt request: {:?}",
757+
result.unwrap_err()
758+
);
759759
}
760760
counter += 1;
761761
}
@@ -796,8 +796,7 @@ async fn test_tap_aggregator_rav_timestamp_cuttoff(
796796
http_max_concurrent_connections,
797797
)
798798
.await?;
799-
let client =
800-
HttpClientBuilder::default().build(format!("http://{}", gateway_addr.to_string()))?;
799+
let client = HttpClientBuilder::default().build(format!("http://{}", gateway_addr))?;
801800

802801
// This is the first part of the test, two batches of receipts are sent to the aggregator.
803802
// The second batch has one receipt with the same timestamp as the latest receipt in the first batch.
@@ -828,10 +827,10 @@ async fn test_tap_aggregator_rav_timestamp_cuttoff(
828827
jsonrpsee_helpers::JsonRpcResponse<SignedRAV>,
829828
jsonrpsee::core::Error,
830829
> = client.request("aggregate_receipts", params).await;
831-
match second_rav_response {
832-
Ok(_) => panic!("Should have failed RAV request"),
833-
Err(_) => {}
834-
}
830+
assert!(
831+
second_rav_response.is_err(),
832+
"Should have failed RAV request"
833+
);
835834

836835
// This is the second part of the test, two batches of receipts are sent to the aggregator.
837836
// The second batch has one receipt with the timestamp = timestamp+1 of the latest receipt in the first batch.

0 commit comments

Comments
 (0)