Skip to content

Commit

Permalink
Rustfmt rules (#151)
Browse files Browse the repository at this point in the history
- [x] Add rustfmt rules
- [x] Execute `cargo fmt` to format the files according to the set
rules.
  • Loading branch information
rakanalh authored Nov 27, 2023
1 parent f7fcdcc commit df7b36e
Show file tree
Hide file tree
Showing 46 changed files with 190 additions and 170 deletions.
30 changes: 30 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
edition = "2021"

# Basic
hard_tabs = true
max_width = 100
use_small_heuristics = "Max"

# Imports
imports_granularity = "Crate"
reorder_imports = true
group_imports = "StdExternalCrate"

# Consistency
newline_style = "Unix"

# Format comments
comment_width = 100
wrap_comments = true

# Misc
chain_width = 80
spaces_around_ranges = false
binop_separator = "Back"
reorder_impl_items = false
match_arm_leading_pipes = "Preserve"
match_arm_blocks = false
match_block_trailing_comma = true
trailing_comma = "Vertical"
trailing_semicolon = false
use_field_init_shorthand = true
4 changes: 2 additions & 2 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::cli::{Cli, Subcommand};

use cere_service::{self, IdentifyVariant};
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
use sc_cli::{Error, RuntimeVersion, SubstrateCli};
use sc_service::error::Error as ServiceError;

use crate::cli::{Cli, Subcommand};

impl SubstrateCli for Cli {
fn impl_name() -> String {
"Cere Node".into()
Expand Down
2 changes: 0 additions & 2 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ mod command;

#[cfg(feature = "cli")]
pub use cli::*;

#[cfg(feature = "cli")]
pub use command::*;

#[cfg(feature = "cli")]
pub use sc_cli::{Error, Result};
3 changes: 2 additions & 1 deletion node/client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::Arc;

pub use node_primitives::{AccountId, Balance, Block, BlockNumber, Hash, Header, Index, Signature};
use sc_client_api::{AuxStore, Backend as BackendT, BlockchainEvents, KeyIterator, UsageProvider};
pub use sc_executor::NativeElseWasmExecutor;
Expand All @@ -10,7 +12,6 @@ use sp_runtime::{
Justifications,
};
use sp_storage::{ChildInfo, StorageData, StorageKey};
use std::sync::Arc;

pub type FullBackend = sc_service::TFullBackend<Block>;
pub type FullClient<RuntimeApi, ExecutorDispatch> =
Expand Down
6 changes: 2 additions & 4 deletions node/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#[cfg(feature = "cere-native")]
use cere_runtime as cere;

#[cfg(feature = "cere-dev-native")]
use cere_dev_runtime as cere_dev;
#[cfg(feature = "cere-dev-native")]
use cere_dev_runtime_constants::currency::DOLLARS as TEST_UNITS;

#[cfg(feature = "cere-native")]
use cere_runtime as cere;
pub use node_primitives::{AccountId, Balance, Block, Signature};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use sc_chain_spec::ChainSpecExtension;
Expand Down
7 changes: 3 additions & 4 deletions node/service/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.

use std::sync::Arc;

#[cfg(feature = "cere-dev-native")]
pub use cere_dev_runtime;
#[cfg(feature = "cere-native")]
pub use cere_runtime;

use futures::prelude::*;
use sc_client_api::{Backend, BlockBackend};
use sc_consensus_babe::{self, SlotProportion};
pub use sc_executor::NativeExecutionDispatch;
use sc_network::Event;
use sc_service::{
error::Error as ServiceError, Configuration, KeystoreContainer, RpcHandlers, TaskManager,
};
use sc_telemetry::{Telemetry, TelemetryWorker};
use sp_runtime::traits::{BlakeTwo256, Block as BlockT};
use sp_trie::PrefixedMemoryDB;
use std::sync::Arc;

pub use sc_executor::NativeExecutionDispatch;
pub mod chain_spec;
pub use cere_client::{
AbstractClient, CereDevExecutorDispatch, CereExecutorDispatch, Client, ClientHandle,
Expand Down
5 changes: 2 additions & 3 deletions pallets/chainbridge/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#![cfg(test)]

use super::*;

use frame_support::{
assert_ok, ord_parameter_types, parameter_types, traits::Everything, weights::Weight,
};
use frame_system::{self as system};
pub use pallet_balances as balances;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{AccountIdConversion, BlakeTwo256, IdentityLookup},
Perbill,
};

use super::*;
use crate::{self as bridge, Config};
pub use pallet_balances as balances;

parameter_types! {
pub const BlockHashCount: u64 = 250;
Expand Down
31 changes: 6 additions & 25 deletions pallets/chainbridge/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![cfg(test)]

use frame_support::{assert_noop, assert_ok};

use super::{
mock::{
assert_events, new_test_ext, Balances, Bridge, ProposalLifetime, RuntimeCall, RuntimeEvent,
Expand All @@ -9,7 +11,6 @@ use super::{
*,
};
use crate::mock::new_test_ext_initialized;
use frame_support::{assert_noop, assert_ok};

#[test]
fn derive_ids() {
Expand Down Expand Up @@ -141,12 +142,7 @@ fn asset_transfer_success() {
assert_ok!(Bridge::set_threshold(RuntimeOrigin::root(), TEST_THRESHOLD,));

assert_ok!(Bridge::whitelist_chain(RuntimeOrigin::root(), dest_id));
assert_ok!(Bridge::transfer_fungible(
dest_id,
resource_id,
to.clone(),
amount.into()
));
assert_ok!(Bridge::transfer_fungible(dest_id, resource_id, to.clone(), amount.into()));
assert_events(vec![
RuntimeEvent::Bridge(RawEvent::ChainWhitelisted(dest_id)),
RuntimeEvent::Bridge(RawEvent::FungibleTransfer(
Expand Down Expand Up @@ -174,11 +170,7 @@ fn asset_transfer_success() {
metadata.clone(),
))]);

assert_ok!(Bridge::transfer_generic(
dest_id,
resource_id,
metadata.clone()
));
assert_ok!(Bridge::transfer_generic(dest_id, resource_id, metadata.clone()));
assert_events(vec![RuntimeEvent::Bridge(RawEvent::GenericTransfer(
dest_id,
3,
Expand All @@ -200,23 +192,12 @@ fn asset_transfer_invalid_resource_id() {
assert_ok!(Bridge::whitelist_chain(RuntimeOrigin::root(), dest_id));

assert_noop!(
Bridge::transfer_fungible(
dest_id,
resource_id,
to,
amount.into()
),
Bridge::transfer_fungible(dest_id, resource_id, to, amount.into()),
Error::<Test>::ResourceDoesNotExist
);

assert_noop!(
Bridge::transfer_nonfungible(
dest_id,
resource_id,
vec![],
vec![],
vec![]
),
Bridge::transfer_nonfungible(dest_id, resource_id, vec![], vec![], vec![]),
Error::<Test>::ResourceDoesNotExist
);

Expand Down
3 changes: 2 additions & 1 deletion pallets/ddc-clusters/src/cluster.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::pallet::Error;
use codec::{Decode, Encode};
use ddc_primitives::{ClusterId, ClusterParams};
use frame_support::{pallet_prelude::*, parameter_types};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};

use crate::pallet::Error;

parameter_types! {
pub MaxClusterParamsLen: u16 = 2048;
}
Expand Down
12 changes: 7 additions & 5 deletions pallets/ddc-clusters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ pub(crate) mod mock;
#[cfg(test)]
mod tests;

use crate::{
cluster::Cluster,
node_provider_auth::{NodeProviderAuthContract, NodeProviderAuthContractError},
};
use ddc_primitives::{
ClusterBondingParams, ClusterFeesParams, ClusterGovParams, ClusterId, ClusterParams,
ClusterPricingParams, NodePubKey, NodeType,
Expand All @@ -43,6 +39,11 @@ use pallet_ddc_nodes::{NodeRepository, NodeTrait};
use sp_runtime::SaturatedConversion;
use sp_std::prelude::*;

use crate::{
cluster::Cluster,
node_provider_auth::{NodeProviderAuthContract, NodeProviderAuthContractError},
};

pub mod cluster;
mod node_provider_auth;

Expand All @@ -52,10 +53,11 @@ pub type BalanceOf<T> =

#[frame_support::pallet]
pub mod pallet {
use super::*;
use ddc_traits::cluster::{ClusterManager, ClusterManagerError};
use pallet_contracts::chain_extension::UncheckedFrom;

use super::*;

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::without_storage_info]
Expand Down
3 changes: 2 additions & 1 deletion pallets/ddc-clusters/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#![allow(dead_code)]

use crate::{self as pallet_ddc_clusters, *};
use ddc_primitives::{ClusterId, NodePubKey};
use ddc_traits::staking::{StakingVisitor, StakingVisitorError};
use frame_support::{
Expand All @@ -22,6 +21,8 @@ use sp_runtime::{
MultiSignature,
};

use crate::{self as pallet_ddc_clusters, *};

/// The AccountId alias in this test module.
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
pub(crate) type AccountIndex = u64;
Expand Down
3 changes: 2 additions & 1 deletion pallets/ddc-clusters/src/node_provider_auth.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::Config;
use codec::Encode;
use ddc_primitives::{NodePubKey, NodeType};
use frame_support::weights::Weight;
use pallet_contracts::chain_extension::UncheckedFrom;
use sp_std::prelude::Vec;

use crate::Config;

/// ink! 4.x selector for the "is_authorized" message, equals to the first four bytes of the
/// blake2("is_authorized"). See also: https://use.ink/basics/selectors#selector-calculation/,
/// https://use.ink/macros-attributes/selector/.
Expand Down
3 changes: 2 additions & 1 deletion pallets/ddc-clusters/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//! Tests for the module.

use super::{mock::*, *};
use ddc_primitives::{CDNNodeParams, ClusterId, ClusterParams, NodeParams, NodePubKey};
use frame_support::{assert_noop, assert_ok, error::BadOrigin};
use frame_system::Config;
use hex_literal::hex;
use sp_runtime::{traits::Hash, AccountId32, Perbill};

use super::{mock::*, *};

#[test]
fn create_cluster_works() {
ExtBuilder.build_and_execute(|| {
Expand Down
5 changes: 3 additions & 2 deletions pallets/ddc-customers/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//! DdcStaking pallet benchmarking.
#![cfg(feature = "runtime-benchmarks")]

use super::*;
use crate::Pallet as DdcCustomers;
use ddc_primitives::{ClusterGovParams, ClusterId, ClusterParams};
use frame_benchmarking::{account, benchmarks, whitelist_account};
use frame_support::traits::Currency;
use sp_runtime::Perbill;
use sp_std::prelude::*;

use super::*;
use crate::Pallet as DdcCustomers;

pub type BalanceOf<T> =
<<T as pallet::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;

Expand Down
7 changes: 3 additions & 4 deletions pallets/ddc-customers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ mod tests;
use core::fmt::Debug;

use codec::{Decode, Encode, HasCompact};

use ddc_primitives::{BucketId, ClusterId};
use ddc_traits::{
cluster::{ClusterCreator, ClusterVisitor},
Expand All @@ -26,15 +25,14 @@ use frame_support::{
traits::{Currency, DefensiveSaturating, ExistenceRequirement},
BoundedVec, PalletId,
};
pub use pallet::*;
use scale_info::TypeInfo;
use sp_runtime::{
traits::{AccountIdConversion, AtLeast32BitUnsigned, CheckedAdd, CheckedSub, Saturating, Zero},
RuntimeDebug, SaturatedConversion,
};
use sp_std::prelude::*;

pub use pallet::*;

/// The balance type of this pallet.
pub type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
Expand Down Expand Up @@ -167,10 +165,11 @@ impl<

#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::{pallet_prelude::*, traits::LockableCurrency};
use frame_system::pallet_prelude::*;

use super::*;

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::without_storage_info]
Expand Down
3 changes: 2 additions & 1 deletion pallets/ddc-customers/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Test utilities

use crate::{self as pallet_ddc_customers, *};
use ddc_primitives::{
ClusterBondingParams, ClusterFeesParams, ClusterGovParams, ClusterId, ClusterParams,
ClusterPricingParams, NodePubKey, NodeType,
Expand All @@ -22,6 +21,8 @@ use sp_runtime::{
DispatchResult, Perbill,
};

use crate::{self as pallet_ddc_customers, *};

/// The AccountId alias in this test module.
pub(crate) type AccountId = u64;
pub(crate) type AccountIndex = u64;
Expand Down
4 changes: 2 additions & 2 deletions pallets/ddc-customers/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Tests for the module.

use super::{mock::*, *};
use ddc_primitives::ClusterId;

use frame_support::{assert_noop, assert_ok};
use frame_system::Config;
use pallet_balances::Error as BalancesError;

use super::{mock::*, *};

#[test]
fn create_bucket_works() {
ExtBuilder.build_and_execute(|| {
Expand Down
Loading

0 comments on commit df7b36e

Please sign in to comment.