Skip to content

Commit

Permalink
cargo fmt fix and check_commit
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjiao committed Sep 5, 2023
1 parent ac76f3e commit 7a81f87
Show file tree
Hide file tree
Showing 23 changed files with 41 additions and 82 deletions.
4 changes: 1 addition & 3 deletions account/api/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ use starcoin_types::account_config::token_code::TokenCode;
use starcoin_types::sign_message::{SignedMessage, SigningMessage};
use starcoin_types::transaction::{RawUserTransaction, SignedUserTransaction};

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[derive(Default)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum AccountProviderStrategy {
#[default]
RPC,
Local,
PrivateKey,
}


pub trait AccountProvider {
fn create_account(&self, password: String) -> Result<AccountInfo>;

Expand Down
12 changes: 6 additions & 6 deletions commons/forkable-jellyfish-merkle/src/jellyfish_merkle_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,8 @@ proptest! {
}
}

fn test_existent_keys_impl<'a>(
tree: &JellyfishMerkleTree<'a, HashValueKey, MockTreeStore>,
fn test_existent_keys_impl(
tree: &JellyfishMerkleTree<'_, HashValueKey, MockTreeStore>,
root_hash: HashValue,
existent_kvs: &HashMap<HashValueKey, Blob>,
) {
Expand All @@ -778,8 +778,8 @@ fn test_existent_keys_impl<'a>(
}
}

fn test_nonexistent_keys_impl<'a>(
tree: &JellyfishMerkleTree<'a, HashValueKey, MockTreeStore>,
fn test_nonexistent_keys_impl(
tree: &JellyfishMerkleTree<'_, HashValueKey, MockTreeStore>,
root_hash: HashValue,
nonexistent_keys: &[HashValueKey],
) {
Expand All @@ -792,8 +792,8 @@ fn test_nonexistent_keys_impl<'a>(
}
}

fn test_nonexistent_key_value_update_impl<'a>(
tree: &JellyfishMerkleTree<'a, HashValueKey, MockTreeStore>,
fn test_nonexistent_key_value_update_impl(
tree: &JellyfishMerkleTree<'_, HashValueKey, MockTreeStore>,
db: &MockTreeStore,
root_hash: HashValue,
noneexistent_kv: (HashValue, Blob),
Expand Down
2 changes: 1 addition & 1 deletion commons/service-registry/src/bus/sys_bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ mod tests {
let mut bus = SysBus::new();
let receiver = bus.oneshot::<Message>();
assert_eq!(1, bus.len_by_type::<Message>());
let job = task::spawn(async { receiver.await });
let job = task::spawn(receiver);
Delay::new(Duration::from_millis(10)).await;
bus.broadcast(Message {});
let result = job.await;
Expand Down
5 changes: 1 addition & 4 deletions config/src/api_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ impl FromStr for Api {
}
}

#[derive(Debug, Clone)]
#[derive(Default)]
#[derive(Debug, Clone, Default)]
pub enum ApiSet {
// Unsafe context (like jsonrpc over http)
#[default]
Expand All @@ -98,8 +97,6 @@ pub enum ApiSet {
List(HashSet<Api>),
}



impl PartialEq for ApiSet {
fn eq(&self, other: &Self) -> bool {
self.list_apis() == other.list_apis()
Expand Down
2 changes: 0 additions & 2 deletions config/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,6 @@ impl BuiltinNetworkID {
}
}



impl From<BuiltinNetworkID> for ChainNetwork {
fn from(network: BuiltinNetworkID) -> Self {
ChainNetwork::new(
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/consensus_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) The Starcoin Core Contributors
// SPDX-License-Identifier: Apache-2.0

#![allow(clippy::integer_arithmetic)]
#![allow(clippy::arithmetic_side_effects)]

use crate::consensus::Consensus;
use crate::difficulty::{get_next_target_helper, BlockDiffInfo};
Expand Down
5 changes: 1 addition & 4 deletions network-p2p/peerset/tests/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ fn test_once() {
for _ in 0..2500 {
// Each of these weights corresponds to an action that we may perform.
let action_weights = [150, 90, 90, 30, 30, 1, 1, 4, 4];
match WeightedIndex::new(&action_weights)
.unwrap()
.sample(&mut rng)
{
match WeightedIndex::new(action_weights).unwrap().sample(&mut rng) {
// If we generate 0, poll the peerset.
0 => match Stream::poll_next(Pin::new(&mut peerset), cx) {
Poll::Ready(Some(Message::Connect { peer_id, .. })) => {
Expand Down
8 changes: 4 additions & 4 deletions network-p2p/src/service_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ async fn test_handshake_fail() {
.unwrap();
let service1 = worker1.service().clone();

let _ = tokio::task::spawn(worker1);
let _ = tokio::task::spawn(worker1).await;

let seed = config::MultiaddrWithPeerId {
multiaddr: config1.listen_addresses[0].clone(),
Expand All @@ -540,7 +540,7 @@ async fn test_handshake_fail() {
.unwrap();
let service2 = worker2.service().clone();

let _ = tokio::task::spawn(worker2);
let _ = tokio::task::spawn(worker2).await;
tokio::time::sleep(Duration::from_secs(1)).await;

debug!(
Expand Down Expand Up @@ -619,7 +619,7 @@ async fn test_support_protocol() {
.unwrap();
let service1 = worker1.service().clone();
let stream1 = service1.event_stream("test1");
let _ = tokio::task::spawn(worker1);
let _ = tokio::task::spawn(worker1).await;

let seed = MultiaddrWithPeerId {
multiaddr: config1.listen_addresses[0].clone(),
Expand All @@ -637,7 +637,7 @@ async fn test_support_protocol() {
.unwrap();
let service2 = worker2.service().clone();
let stream2 = service2.event_stream("test1");
let _ = tokio::task::spawn(worker2);
let _ = tokio::task::spawn(worker2).await;

tokio::time::sleep(Duration::from_secs(1)).await;

Expand Down
5 changes: 1 addition & 4 deletions network/api/src/peer_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ impl From<(PeerInfo, u64)> for PeerDetail {
}
}

#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Serialize, JsonSchema)]
#[derive(Default)]
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Serialize, JsonSchema, Default)]
pub enum PeerStrategy {
Random,
#[default]
Expand All @@ -95,8 +94,6 @@ pub enum PeerStrategy {
Avg,
}



impl std::fmt::Display for PeerStrategy {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let display = match self {
Expand Down
20 changes: 8 additions & 12 deletions network/src/network_p2p_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,10 @@ impl BusinessLayerHandle for Networkp2pHandle {
self.status.info = other_chain_info;
Ok(())
}
Err(error) => {
Err(anyhow!(
"failed to decode the generic data for the reason: {}",
error
))
}
Err(error) => Err(anyhow!(
"failed to decode the generic data for the reason: {}",
error
)),
}
}

Expand All @@ -128,12 +126,10 @@ impl BusinessLayerHandle for Networkp2pHandle {
self.status.info.update_status(status);
Ok(())
}
Err(error) => {
Err(anyhow!(
"failed to decode the generic data for the reason: {}",
error
))
}
Err(error) => Err(anyhow!(
"failed to decode the generic data for the reason: {}",
error
)),
}
}

Expand Down
5 changes: 1 addition & 4 deletions rpc/api/src/types/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ impl Serialize for Result {
}

/// Subscription kind.
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize)]
#[derive(Default)]
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Default)]
pub enum Params {
/// No parameters passed.
#[default]
Expand All @@ -68,8 +67,6 @@ pub enum Params {
Events(EventParams),
}



impl<'a> Deserialize<'a> for Params {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Params, D::Error>
where
Expand Down
5 changes: 1 addition & 4 deletions rpc/client/src/remote_state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@ use starcoin_vm_types::state_store::state_key::StateKey;
use starcoin_vm_types::state_store::table::{TableHandle, TableInfo};
use std::str::FromStr;

#[derive(Debug, Clone, Copy)]
#[derive(Default)]
#[derive(Debug, Clone, Copy, Default)]
pub enum StateRootOption {
#[default]
Latest,
BlockHash(HashValue),
BlockNumber(BlockNumber),
}



impl FromStr for StateRootOption {
type Err = anyhow::Error;

Expand Down
4 changes: 2 additions & 2 deletions rpc/client/tests/client_server_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ fn test_client_reconnect_subscribe() -> Result<()> {
std::thread::sleep(Duration::from_millis(300));
let _e = node_handle.stop();

let events1 = futures::executor::block_on(async move { handle1.await });
let events2 = futures::executor::block_on(async move { handle2.await });
let events1 = futures::executor::block_on(handle1);
let events2 = futures::executor::block_on(handle2);
assert_ne!(events1.len(), 0);
assert_ne!(events2.len(), 0);
Ok(())
Expand Down
1 change: 0 additions & 1 deletion state/statedb/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ fn state_keys_to_write_set(state_keys: Vec<StateKey>, values: Vec<Vec<u8>>) -> W
state_keys
.into_iter()
.zip(values)
.into_iter()
.map(|(key, val)| (key, WriteOp::Value(val)))
.collect::<Vec<_>>(),
)
Expand Down
2 changes: 1 addition & 1 deletion sync/src/block_connector/test_illegal_block.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) The Starcoin Core Contributors
// SPDX-License-Identifier: Apache-2.0
#![allow(clippy::integer_arithmetic)]
#![allow(clippy::arithmetic_side_effects)]
use crate::block_connector::{
create_writeable_block_chain, gen_blocks, new_block, WriteBlockChainService,
};
Expand Down
2 changes: 1 addition & 1 deletion sync/src/block_connector/test_write_block_chain.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) The Starcoin Core Contributors
// SPDX-License-Identifier: Apache-2.0
#![allow(clippy::integer_arithmetic)]
#![allow(clippy::arithmetic_side_effects)]
use crate::block_connector::WriteBlockChainService;
use starcoin_account_api::AccountInfo;
use starcoin_chain::{BlockChain, ChainReader};
Expand Down
8 changes: 2 additions & 6 deletions sync/src/tasks/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,15 @@ use starcoin_types::block::{Block, BlockIdAndNumber, BlockInfo, BlockNumber};
use std::sync::Arc;
use std::time::Duration;

#[derive(Default)]
pub enum ErrorStrategy {
_RateLimitErr,
Timeout(u64),
#[default]
RandomErr,
MethodNotFound,
}

impl Default for ErrorStrategy {
fn default() -> Self {
ErrorStrategy::RandomErr
}
}

pub struct ErrorMocker {
strategy: ErrorStrategy,
pub random_error_percent: u32,
Expand Down
2 changes: 1 addition & 1 deletion sync/src/tasks/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) The Starcoin Core Contributors
// SPDX-License-Identifier: Apache-2.0

#![allow(clippy::integer_arithmetic)]
#![allow(clippy::arithmetic_side_effects)]
use crate::tasks::block_sync_task::SyncBlockData;
use crate::tasks::mock::{ErrorStrategy, MockBlockIdFetcher, SyncNodeMocker};
use crate::tasks::{
Expand Down
2 changes: 0 additions & 2 deletions txpool/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ async fn test_pool_pending() -> Result<()> {
let metrics_config: &MetricsConfig = &node_config.metrics;

let txn_vec = (0..pool_size + expect_reject)
.into_iter()
.map(|index| generate_txn(node_config.clone(), index))
.collect::<Vec<_>>();

Expand Down Expand Up @@ -152,7 +151,6 @@ async fn test_pool_pending() -> Result<()> {
);

let txn_vec = (pool_size..(pool_size + expect_reject))
.into_iter()
.map(|index| generate_txn(node_config.clone(), index))
.collect::<Vec<_>>();

Expand Down
14 changes: 6 additions & 8 deletions vm/gas-algebra-ext/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,12 @@ mod tests {

#[test]
fn optional_should_be_honored() {
assert!(
matches!(
GasParameters::from_on_chain_gas_schedule(
&[("test.foo".to_string(), 0)].into_iter().collect(),
),
Some(_)
)
);
assert!(matches!(
GasParameters::from_on_chain_gas_schedule(
&[("test.foo".to_string(), 0)].into_iter().collect(),
),
Some(_)
));

assert!(matches!(
GasParameters::from_on_chain_gas_schedule(&[].into_iter().collect()),
Expand Down
5 changes: 1 addition & 4 deletions vm/move-package-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ pub struct TestOpts {
format: Format,
}

#[derive(Debug, Eq, PartialEq)]
#[derive(Default)]
#[derive(Debug, Eq, PartialEq, Default)]
enum Format {
#[default]
Pretty,
Expand Down Expand Up @@ -98,8 +97,6 @@ impl FromStr for Format {
}
}



#[derive(Args, Debug)]
pub struct IntegrationTestCommand {
#[clap(flatten)]
Expand Down
7 changes: 1 addition & 6 deletions vm/types/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use std::cmp::Ordering;
use std::fmt::{self, Formatter};
use std::fmt::{Debug, Display};
use std::str::FromStr;
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Default)]
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Default)]
pub enum StdlibVersion {
#[default]
Latest,
Expand Down Expand Up @@ -73,8 +72,6 @@ impl Ord for StdlibVersion {
}
}



impl FromStr for StdlibVersion {
type Err = anyhow::Error;

Expand Down Expand Up @@ -127,8 +124,6 @@ impl ConsensusStrategy {
}
}



impl fmt::Display for ConsensusStrategy {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down
1 change: 0 additions & 1 deletion vm/types/src/transaction/authenticator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,6 @@ mod tests {
let mut key_gen = KeyGen::from_os_rng();
let threshold = 2;
let pubkeys = (0..2)
.into_iter()
.map(|_| key_gen.generate_keypair().1)
.collect::<Vec<_>>();
let account_public_key = AccountPublicKey::multi(pubkeys.clone(), threshold).unwrap();
Expand Down

0 comments on commit 7a81f87

Please sign in to comment.