From eaef9779575cd3abb0516c0fc62908dd30790c9f Mon Sep 17 00:00:00 2001 From: Lorenzo Delgado Date: Wed, 15 Jan 2025 22:39:40 +0100 Subject: [PATCH] refactor: format imports using cargo fmt (#258) Signed-off-by: Lorenzo Delgado --- .github/workflows/tests.yml | 14 +++++---- rustfmt.toml | 6 ++++ tap_aggregator/src/aggregator.rs | 2 +- tap_aggregator/src/main.rs | 3 +- tap_aggregator/src/server.rs | 10 +++--- tap_aggregator/tests/aggregate_test.rs | 1 - .../timeline_aggretion_protocol_benchmark.rs | 6 ++-- tap_core/src/error.rs | 6 ++-- tap_core/src/manager/context/memory.rs | 26 ++++++++++------ tap_core/src/rav.rs | 6 ++-- tap_core/src/rav/request.rs | 8 +++-- tap_core/src/receipt/checks.rs | 31 +++++++++---------- tap_core/src/receipt/receipt_sol.rs | 10 ++++-- tap_core/src/receipt/received_receipt.rs | 10 +++--- tap_core/tests/escrow_test.rs | 1 - tap_core/tests/rav_test.rs | 21 ++++++++----- tap_core/tests/receipt_test.rs | 21 ++++++------- tap_integration_tests/tests/indexer_mock.rs | 1 - tap_integration_tests/tests/showcase.rs | 1 - 19 files changed, 100 insertions(+), 84 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 44d9ff9e..71a98d0b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,13 +11,15 @@ jobs: fmt: name: cargo fmt runs-on: ubuntu-latest - container: - image: rust:1.83-bookworm steps: - - uses: actions/checkout@v3 - - run: | - rustup component add rustfmt - cargo fmt --all -- --check + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + - uses: actions-rust-lang/setup-rust-toolchain@11df97af8e8102fd60b60a77dfbf58d40cd843b8 # v1 + with: + # Imports formatting is an unstable feature, so we need to use nightly + toolchain: nightly + components: rustfmt + cache: false + - run: cargo +nightly fmt --all -- --check clippy: name: cargo clippy diff --git a/rustfmt.toml b/rustfmt.toml index 3a26366d..58770b41 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1,7 @@ edition = "2021" + +# Enable nightly features required for formatting imports +unstable_features = true +imports_granularity = "Crate" +group_imports = "StdExternalCrate" +reorder_modules = true diff --git a/tap_aggregator/src/aggregator.rs b/tap_aggregator/src/aggregator.rs index 1fe15262..9cd788ff 100644 --- a/tap_aggregator/src/aggregator.rs +++ b/tap_aggregator/src/aggregator.rs @@ -137,9 +137,9 @@ mod tests { use alloy::{dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner}; use rstest::*; + use tap_core::{receipt::Receipt, signed_message::EIP712SignedMessage, tap_eip712_domain}; use crate::aggregator; - use tap_core::{receipt::Receipt, signed_message::EIP712SignedMessage, tap_eip712_domain}; #[fixture] fn keys() -> (PrivateKeySigner, Address) { diff --git a/tap_aggregator/src/main.rs b/tap_aggregator/src/main.rs index 556caba4..72f8e11d 100644 --- a/tap_aggregator/src/main.rs +++ b/tap_aggregator/src/main.rs @@ -9,9 +9,8 @@ use alloy::{dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateK use anyhow::Result; use clap::Parser; use log::{debug, info}; -use tap_core::tap_eip712_domain; - use tap_aggregator::{metrics, server}; +use tap_core::tap_eip712_domain; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] diff --git a/tap_aggregator/src/server.rs b/tap_aggregator/src/server.rs index 8e82fd57..ab84ce8b 100644 --- a/tap_aggregator/src/server.rs +++ b/tap_aggregator/src/server.rs @@ -388,21 +388,19 @@ fn create_json_rpc_service( #[cfg(test)] #[allow(clippy::too_many_arguments)] mod tests { - use std::collections::HashSet; - use std::str::FromStr; + use std::{collections::HashSet, str::FromStr}; use alloy::{dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner}; use jsonrpsee::{core::client::ClientT, http_client::HttpClientBuilder, rpc_params}; - use rand::prelude::*; - use rand::seq::SliceRandom; + use rand::{prelude::*, seq::SliceRandom}; use rstest::*; - - use crate::server; use tap_core::{ rav::ReceiptAggregateVoucher, receipt::Receipt, signed_message::EIP712SignedMessage, tap_eip712_domain, }; + use crate::server; + #[derive(Clone)] struct Keys { wallet: PrivateKeySigner, diff --git a/tap_aggregator/tests/aggregate_test.rs b/tap_aggregator/tests/aggregate_test.rs index e7521979..8c16436c 100644 --- a/tap_aggregator/tests/aggregate_test.rs +++ b/tap_aggregator/tests/aggregate_test.rs @@ -4,7 +4,6 @@ use std::{collections::HashSet, str::FromStr}; use alloy::{primitives::Address, signers::local::PrivateKeySigner}; - use jsonrpsee::{core::client::ClientT, http_client::HttpClientBuilder, rpc_params}; use tap_aggregator::{ grpc::{tap_aggregator_client::TapAggregatorClient, RavRequest}, diff --git a/tap_core/benches/timeline_aggretion_protocol_benchmark.rs b/tap_core/benches/timeline_aggretion_protocol_benchmark.rs index e76e1d29..69052919 100644 --- a/tap_core/benches/timeline_aggretion_protocol_benchmark.rs +++ b/tap_core/benches/timeline_aggretion_protocol_benchmark.rs @@ -10,13 +10,11 @@ use std::str::FromStr; -use alloy::dyn_abi::Eip712Domain; -use alloy::primitives::Address; -use alloy::signers::local::PrivateKeySigner; +use alloy::{dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner}; use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use tap_core::tap_eip712_domain; use tap_core::{ rav::ReceiptAggregateVoucher, receipt::Receipt, signed_message::EIP712SignedMessage, + tap_eip712_domain, }; pub fn create_and_sign_receipt( diff --git a/tap_core/src/error.rs b/tap_core/src/error.rs index b5d1c562..9a4a31f8 100644 --- a/tap_core/src/error.rs +++ b/tap_core/src/error.rs @@ -4,11 +4,13 @@ //! Module containing Error type and Result typedef //! -use crate::{rav::ReceiptAggregateVoucher, receipt::ReceiptError}; -use alloy::primitives::{Address, SignatureError}; use std::result::Result as StdResult; + +use alloy::primitives::{Address, SignatureError}; use thiserror::Error as ThisError; +use crate::{rav::ReceiptAggregateVoucher, receipt::ReceiptError}; + /// Error type for the TAP protocol #[derive(ThisError, Debug)] pub enum Error { diff --git a/tap_core/src/manager/context/memory.rs b/tap_core/src/manager/context/memory.rs index 21eff1b7..455b123d 100644 --- a/tap_core/src/manager/context/memory.rs +++ b/tap_core/src/manager/context/memory.rs @@ -6,17 +6,21 @@ //! This module provides an in-memory implementation of the TAP manager context. //! It is useful for testing and development purposes. +use std::{ + collections::HashMap, + ops::RangeBounds, + sync::{Arc, RwLock}, +}; + +use alloy::primitives::Address; +use async_trait::async_trait; + use crate::{ manager::adapters::*, rav::SignedRAV, receipt::{checks::StatefulTimestampCheck, state::Checking, ReceiptWithState}, signed_message::MessageId, }; -use alloy::primitives::Address; -use async_trait::async_trait; -use std::ops::RangeBounds; -use std::sync::RwLock; -use std::{collections::HashMap, sync::Arc}; pub type EscrowStorage = Arc>>; pub type QueryAppraisals = Arc>>; @@ -259,6 +263,13 @@ impl EscrowHandler for InMemoryContext { } pub mod checks { + use std::{ + collections::{HashMap, HashSet}, + sync::{Arc, RwLock}, + }; + + use alloy::{dyn_abi::Eip712Domain, primitives::Address}; + use crate::{ receipt::{ checks::{Check, CheckError, CheckResult, ReceiptCheck}, @@ -267,11 +278,6 @@ pub mod checks { }, signed_message::MessageId, }; - use alloy::{dyn_abi::Eip712Domain, primitives::Address}; - use std::{ - collections::{HashMap, HashSet}, - sync::{Arc, RwLock}, - }; pub fn get_full_list_of_checks( domain_separator: Eip712Domain, diff --git a/tap_core/src/rav.rs b/tap_core/src/rav.rs index 78ea2c80..bf55f862 100644 --- a/tap_core/src/rav.rs +++ b/tap_core/src/rav.rs @@ -41,12 +41,10 @@ mod request; use std::cmp; -use alloy::primitives::Address; -use alloy::sol; +use alloy::{primitives::Address, sol}; use serde::{Deserialize, Serialize}; -use crate::Error; -use crate::{receipt::Receipt, signed_message::EIP712SignedMessage}; +use crate::{receipt::Receipt, signed_message::EIP712SignedMessage, Error}; /// EIP712 signed message for ReceiptAggregateVoucher pub type SignedRAV = EIP712SignedMessage; diff --git a/tap_core/src/rav/request.rs b/tap_core/src/rav/request.rs index 991d8626..3854d7f2 100644 --- a/tap_core/src/rav/request.rs +++ b/tap_core/src/rav/request.rs @@ -1,11 +1,13 @@ // Copyright 2023-, Semiotic AI, Inc. // SPDX-License-Identifier: Apache-2.0 -use crate::receipt::state::Reserved; -use crate::Error; use crate::{ rav::{ReceiptAggregateVoucher, SignedRAV}, - receipt::{state::Failed, ReceiptWithState}, + receipt::{ + state::{Failed, Reserved}, + ReceiptWithState, + }, + Error, }; /// Request to `tap_aggregator` to aggregate receipts into a Signed RAV. diff --git a/tap_core/src/receipt/checks.rs b/tap_core/src/receipt/checks.rs index 4820cf8d..86889f0d 100644 --- a/tap_core/src/receipt/checks.rs +++ b/tap_core/src/receipt/checks.rs @@ -29,18 +29,18 @@ //! let my_check: ReceiptCheck = Arc::new(MyCheck); //! ``` -use crate::signed_message::{SignatureBytes, SignatureBytesExt}; - -use super::{ - state::{Checking, Failed}, - Context, ReceiptError, ReceiptWithState, -}; use std::{ collections::HashSet, ops::Deref, sync::{Arc, RwLock}, }; +use super::{ + state::{Checking, Failed}, + Context, ReceiptError, ReceiptWithState, +}; +use crate::signed_message::{SignatureBytes, SignatureBytesExt}; + /// ReceiptCheck is a type alias for an Arc of a struct that implements the `Check` trait. pub type ReceiptCheck = Arc; @@ -200,19 +200,18 @@ impl CheckBatch for UniqueCheck { #[cfg(test)] mod tests { - use std::str::FromStr; - use std::time::Duration; - use std::time::SystemTime; - - use alloy::dyn_abi::Eip712Domain; - use alloy::primitives::Address; - use alloy::signers::local::PrivateKeySigner; - use alloy::sol_types::eip712_domain; + use std::{ + str::FromStr, + time::{Duration, SystemTime}, + }; - use crate::receipt::Receipt; - use crate::signed_message::EIP712SignedMessage; + use alloy::{ + dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner, + sol_types::eip712_domain, + }; use super::*; + use crate::{receipt::Receipt, signed_message::EIP712SignedMessage}; fn create_signed_receipt_with_custom_value(value: u128) -> ReceiptWithState { let wallet: PrivateKeySigner = PrivateKeySigner::random(); diff --git a/tap_core/src/receipt/receipt_sol.rs b/tap_core/src/receipt/receipt_sol.rs index c7670eba..f855fb2b 100644 --- a/tap_core/src/receipt/receipt_sol.rs +++ b/tap_core/src/receipt/receipt_sol.rs @@ -43,10 +43,14 @@ impl Receipt { #[cfg(test)] mod receipt_unit_test { - use super::*; + use std::{ + str::FromStr, + time::{SystemTime, UNIX_EPOCH}, + }; + use rstest::*; - use std::str::FromStr; - use std::time::{SystemTime, UNIX_EPOCH}; + + use super::*; #[fixture] fn allocation_ids() -> Vec
{ diff --git a/tap_core/src/receipt/received_receipt.rs b/tap_core/src/receipt/received_receipt.rs index 3b94f014..708d6dab 100644 --- a/tap_core/src/receipt/received_receipt.rs +++ b/tap_core/src/receipt/received_receipt.rs @@ -15,11 +15,13 @@ use alloy::dyn_abi::Eip712Domain; -use super::checks::CheckError; -use super::{Context, Receipt, ReceiptError, ReceiptResult, SignedReceipt}; -use crate::receipt::state::{AwaitingReserve, Checking, Failed, ReceiptState, Reserved}; +use super::{checks::CheckError, Context, Receipt, ReceiptError, ReceiptResult, SignedReceipt}; use crate::{ - manager::adapters::EscrowHandler, receipt::checks::ReceiptCheck, + manager::adapters::EscrowHandler, + receipt::{ + checks::ReceiptCheck, + state::{AwaitingReserve, Checking, Failed, ReceiptState, Reserved}, + }, signed_message::EIP712SignedMessage, }; diff --git a/tap_core/tests/escrow_test.rs b/tap_core/tests/escrow_test.rs index 5bd0853b..1b4b5bfb 100644 --- a/tap_core/tests/escrow_test.rs +++ b/tap_core/tests/escrow_test.rs @@ -8,7 +8,6 @@ use std::{ use alloy::signers::local::PrivateKeySigner; use rstest::*; - use tap_core::{ manager::{adapters::EscrowHandler, context::memory::InMemoryContext}, receipt::checks::StatefulTimestampCheck, diff --git a/tap_core/tests/rav_test.rs b/tap_core/tests/rav_test.rs index 17149e46..1b96edca 100644 --- a/tap_core/tests/rav_test.rs +++ b/tap_core/tests/rav_test.rs @@ -1,19 +1,24 @@ // Copyright 2023-, Semiotic AI, Inc. // SPDX-License-Identifier: Apache-2.0 -use std::collections::HashMap; -use std::sync::RwLock; -use std::{str::FromStr, sync::Arc}; +use std::{ + collections::HashMap, + str::FromStr, + sync::{Arc, RwLock}, +}; -use alloy::dyn_abi::Eip712Domain; #[allow(deprecated)] use alloy::primitives::{Address, PrimitiveSignature, Signature}; -use alloy::signers::local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner}; +use alloy::{ + dyn_abi::Eip712Domain, + signers::local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner}, +}; use rstest::*; - -use tap_core::manager::context::memory::InMemoryContext; use tap_core::{ - manager::adapters::{RAVRead, RAVStore}, + manager::{ + adapters::{RAVRead, RAVStore}, + context::memory::InMemoryContext, + }, rav::ReceiptAggregateVoucher, receipt::{checks::StatefulTimestampCheck, Receipt}, signed_message::EIP712SignedMessage, diff --git a/tap_core/tests/receipt_test.rs b/tap_core/tests/receipt_test.rs index a507bc7e..6416d0d8 100644 --- a/tap_core/tests/receipt_test.rs +++ b/tap_core/tests/receipt_test.rs @@ -1,20 +1,19 @@ -use alloy::dyn_abi::Eip712Domain; -use alloy::primitives::Address; -use alloy::signers::local::PrivateKeySigner; +use std::{ + collections::HashMap, + str::FromStr, + sync::{Arc, RwLock}, +}; + +use alloy::{dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner}; // Copyright 2023-, Semiotic AI, Inc. // SPDX-License-Identifier: Apache-2.0 use rand::seq::SliceRandom; use rand::thread_rng; -use std::collections::HashMap; -use std::str::FromStr; -use std::sync::{Arc, RwLock}; -use tap_core::manager::context::memory::InMemoryContext; -use tap_core::receipt::{state::Checking, ReceiptWithState}; - use rstest::*; -use tap_core::receipt::checks::StatefulTimestampCheck; use tap_core::{ - manager::adapters::ReceiptStore, receipt::Receipt, signed_message::EIP712SignedMessage, + manager::{adapters::ReceiptStore, context::memory::InMemoryContext}, + receipt::{checks::StatefulTimestampCheck, state::Checking, Receipt, ReceiptWithState}, + signed_message::EIP712SignedMessage, tap_eip712_domain, }; diff --git a/tap_integration_tests/tests/indexer_mock.rs b/tap_integration_tests/tests/indexer_mock.rs index f7ad1b12..7877ffba 100644 --- a/tap_integration_tests/tests/indexer_mock.rs +++ b/tap_integration_tests/tests/indexer_mock.rs @@ -14,7 +14,6 @@ use jsonrpsee::{ rpc_params, server::{ServerBuilder, ServerHandle}, }; - use tap_aggregator::jsonrpsee_helpers; use tap_core::{ manager::{ diff --git a/tap_integration_tests/tests/showcase.rs b/tap_integration_tests/tests/showcase.rs index 6c89f05b..794b2e9d 100644 --- a/tap_integration_tests/tests/showcase.rs +++ b/tap_integration_tests/tests/showcase.rs @@ -23,7 +23,6 @@ use jsonrpsee::{ }; use rand::{rngs::StdRng, Rng, SeedableRng}; use rstest::*; - use tap_aggregator::{jsonrpsee_helpers, server as agg_server}; use tap_core::{ manager::context::memory::{checks::get_full_list_of_checks, *},