Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix clippy warnings for rust 1.49 #1803

Merged
merged 1 commit into from
Dec 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
-D clippy::cast-precision-loss
-D clippy::cast-sign-loss
-D clippy::checked-conversions
-A clippy::field-reassign-with-default

steps:
- uses: actions/checkout@v1
Expand Down
1 change: 1 addition & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export CLIPPY_LINTS := '-D warnings
-D clippy::cast-precision-loss
-D clippy::cast-sign-loss
-D clippy::checked-conversions
-A clippy::field-reassign-with-default
'

# run clippy
Expand Down
18 changes: 2 additions & 16 deletions bridges/ethereum/src/eth.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::config::Config;
use crate::multibimap::MultiBiMap;
use ethabi::{Bytes, Token};
use crate::{config::Config, multibimap::MultiBiMap};
use ethabi::Bytes;
use futures::Future;
use futures_locks::RwLock;
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -427,19 +426,6 @@ impl EthState {
}
}

/// Assume the first return value of an event log is a U256 and return it
pub fn read_u256_from_event_log(value: &web3::types::Log) -> Result<U256, ()> {
let event_types = vec![ethabi::ParamType::Uint(0)];
let event_data = ethabi::decode(&event_types, &value.data.0);
log::debug!("Event data: {:?}", event_data);

// Errors are handled by the caller, if this fails there is nothing we can do
match event_data.map_err(|_| ())?.get(0).ok_or(())? {
Token::Uint(x) => Ok(*x),
_ => Err(()),
}
}

/// Possible ethereum events emited by the WRB ethereum contract
pub enum WrbEvent {
/// A new data request has been posted to ethereum
Expand Down
5 changes: 3 additions & 2 deletions crypto/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ where
let seed_bytes = self.seed.as_ref();
let seed_len = seed_bytes.len();

if seed_len < 16 || seed_len > 64 {
// Seed length must be between 16 and 64 bytes (128 and 512 bits)
if !(16..=64).contains(&seed_len) {
return Err(MasterKeyGenError::InvalidSeedLength);
}

Expand Down Expand Up @@ -148,7 +149,7 @@ pub enum KeyDerivationError {
#[fail(display = "The length of the hmac key is invalid")]
InvalidKeyLength,
/// Invalid seed length
#[fail(display = "The length of the seed is invalid, must be between 128/256 bits")]
#[fail(display = "The length of the seed is invalid, must be between 128/512 bits")]
InvalidSeedLength,
/// Secp256k1 internal error
#[fail(display = "Error in secp256k1 crate")]
Expand Down
46 changes: 27 additions & 19 deletions data_structures/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5404,14 +5404,22 @@ mod tests {

#[test]
fn test_sort_own_utxos() {
let mut vto1 = ValueTransferOutput::default();
vto1.value = 100;
let mut vto2 = ValueTransferOutput::default();
vto2.value = 500;
let mut vto3 = ValueTransferOutput::default();
vto3.value = 200;
let mut vto4 = ValueTransferOutput::default();
vto4.value = 300;
let vto1 = ValueTransferOutput {
value: 100,
..ValueTransferOutput::default()
};
let vto2 = ValueTransferOutput {
value: 500,
..ValueTransferOutput::default()
};
let vto3 = ValueTransferOutput {
value: 200,
..ValueTransferOutput::default()
};
let vto4 = ValueTransferOutput {
value: 300,
..ValueTransferOutput::default()
};

let vt = Transaction::ValueTransfer(VTTransaction::new(
VTTransactionBody::new(vec![], vec![vto1, vto2, vto3, vto4]),
Expand Down Expand Up @@ -5461,9 +5469,9 @@ mod tests {
fn test_ordered_alts_no_tie() {
let mut alt_keys = AltKeys::default();

let p1 = PublicKeyHash::from_bytes(&[0x01 as u8; 20]).unwrap();
let p2 = PublicKeyHash::from_bytes(&[0x02 as u8; 20]).unwrap();
let p3 = PublicKeyHash::from_bytes(&[0x03 as u8; 20]).unwrap();
let p1 = PublicKeyHash::from_bytes(&[0x01; 20]).unwrap();
let p2 = PublicKeyHash::from_bytes(&[0x02; 20]).unwrap();
let p3 = PublicKeyHash::from_bytes(&[0x03; 20]).unwrap();

let p1_bls =
Bn256PublicKey::from_secret_key(&Bn256SecretKey::from_slice(&[1; 32]).unwrap())
Expand Down Expand Up @@ -5505,9 +5513,9 @@ mod tests {
fn test_ordered_alts_with_tie() {
let mut alt_keys = AltKeys::default();

let p1 = PublicKeyHash::from_bytes(&[0x01 as u8; 20]).unwrap();
let p2 = PublicKeyHash::from_bytes(&[0x02 as u8; 20]).unwrap();
let p3 = PublicKeyHash::from_bytes(&[0x03 as u8; 20]).unwrap();
let p1 = PublicKeyHash::from_bytes(&[0x01; 20]).unwrap();
let p2 = PublicKeyHash::from_bytes(&[0x02; 20]).unwrap();
let p3 = PublicKeyHash::from_bytes(&[0x03; 20]).unwrap();

let p1_bls =
Bn256PublicKey::from_secret_key(&Bn256SecretKey::from_slice(&[1; 32]).unwrap())
Expand Down Expand Up @@ -5547,11 +5555,11 @@ mod tests {
fn test_ordered_alts_with_tie_2() {
let mut alt_keys = AltKeys::default();

let p1 = PublicKeyHash::from_bytes(&[0x01 as u8; 20]).unwrap();
let p2 = PublicKeyHash::from_bytes(&[0x02 as u8; 20]).unwrap();
let p3 = PublicKeyHash::from_bytes(&[0x03 as u8; 20]).unwrap();
let p4 = PublicKeyHash::from_bytes(&[0x04 as u8; 20]).unwrap();
let p5 = PublicKeyHash::from_bytes(&[0x05 as u8; 20]).unwrap();
let p1 = PublicKeyHash::from_bytes(&[0x01; 20]).unwrap();
let p2 = PublicKeyHash::from_bytes(&[0x02; 20]).unwrap();
let p3 = PublicKeyHash::from_bytes(&[0x03; 20]).unwrap();
let p4 = PublicKeyHash::from_bytes(&[0x04; 20]).unwrap();
let p5 = PublicKeyHash::from_bytes(&[0x05; 20]).unwrap();

let p1_bls =
Bn256PublicKey::from_secret_key(&Bn256SecretKey::from_slice(&[1; 32]).unwrap())
Expand Down
8 changes: 3 additions & 5 deletions net/src/client/tcp/actors/jsonrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,9 @@ impl StreamHandler<NotifySubscriptionId, Error> for JsonRpcClient {

fn is_connection_error(err: &Error) -> bool {
match err {
Error::RequestFailed { error_kind, .. } => match error_kind {
TransportErrorKind::Transport(_) => true,
TransportErrorKind::Unreachable => true,
_ => false,
},
Error::RequestFailed { error_kind, .. } => {
matches!(error_kind, TransportErrorKind::Transport(_) | TransportErrorKind::Unreachable)
}
Error::RequestTimedOut(_) => true,
Error::Mailbox(_) => true,
_ => false,
Expand Down
8 changes: 5 additions & 3 deletions node/src/actors/chain_manager/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,9 @@ impl Handler<AddSuperBlockVote> for ChainManager {
AddSuperBlockVote { superblock_vote }: AddSuperBlockVote,
ctx: &mut Context<Self>,
) -> Self::Result {
self.add_superblock_vote(superblock_vote, ctx)
self.add_superblock_vote(superblock_vote, ctx);

Ok(())
}
}

Expand All @@ -670,7 +672,7 @@ impl Handler<GetBlocksEpochRange> for ChainManager {
type Result = Result<Vec<(Epoch, Hash)>, ChainManagerError>;

fn handle(&mut self, msg: GetBlocksEpochRange, _ctx: &mut Context<Self>) -> Self::Result {
self.get_blocks_epoch_range(msg)
Ok(self.get_blocks_epoch_range(msg))
}
}

Expand Down Expand Up @@ -1040,7 +1042,7 @@ impl Handler<PeersBeacons> for ChainManager {
// This is the only point in the whole base code for the state
// machine to move into `Synced` state.
self.update_state_machine(StateMachine::Synced);
self.add_temp_superblock_votes(ctx).unwrap();
self.add_temp_superblock_votes(ctx);
}
Ok(peers_to_unregister)
}
Expand Down
42 changes: 22 additions & 20 deletions node/src/actors/chain_manager/mining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,8 +1070,10 @@ mod tests {
// Fields required to mine a block
let block_beacon = CheckpointBeacon::default();

let mut vrf_input = CheckpointVRF::default();
vrf_input.hash_prev_vrf = LAST_VRF_INPUT.parse().unwrap();
let vrf_input = CheckpointVRF {
hash_prev_vrf: LAST_VRF_INPUT.parse().unwrap(),
checkpoint: 0,
};

// Add valid vrf proof
let vrf = &mut VrfCtx::secp256k1().unwrap();
Expand Down Expand Up @@ -1573,7 +1575,7 @@ mod tests {
probs.push(calculate_mining_probability(&rep_engine, id, rf, bf))
}

let new_pkh = PublicKeyHash::from_bytes(&[0xFF as u8; 20]).unwrap();
let new_pkh = PublicKeyHash::from_bytes(&[0xFF; 20]).unwrap();
let new_prob = calculate_mining_probability(&rep_engine, new_pkh, rf, bf);

(probs, new_prob)
Expand All @@ -1589,20 +1591,20 @@ mod tests {
for &prob in &probs[0..8] {
assert_eq!(
(prob * 10_000.0).round() as u32,
(7.12 as f64 * 100.0).round() as u32
(7.12_f64 * 100.0).round() as u32
);
}

for &prob in &probs[8..10] {
assert_eq!(
(prob * 10_000.0).round() as u32,
(4.09 as f64 * 100.0).round() as u32
(4.09_f64 * 100.0).round() as u32
);
}

assert_eq!(
(new_prob * 10_000.0).round() as u32,
(3.89 as f64 * 100.0).round() as u32
(3.89_f64 * 100.0).round() as u32
);
}

Expand All @@ -1616,13 +1618,13 @@ mod tests {
for prob in probs {
assert_eq!(
(prob * 10_000.0).round() as u32,
(9.04 as f64 * 100.0).round() as u32
(9.04_f64 * 100.0).round() as u32
);
}

assert_eq!(
(new_prob * 10_000.0).round() as u32,
(4.56 as f64 * 100.0).round() as u32
(4.56_f64 * 100.0).round() as u32
);
}

Expand All @@ -1636,13 +1638,13 @@ mod tests {
for prob in probs {
assert_eq!(
(prob * 10_000.0).round() as u32,
(8.93 as f64 * 100.0).round() as u32
(8.93_f64 * 100.0).round() as u32
);
}

assert_eq!(
(new_prob * 10_000.0).round() as u32,
(2.15 as f64 * 100.0).round() as u32
(2.15_f64 * 100.0).round() as u32
);
}

Expand All @@ -1656,13 +1658,13 @@ mod tests {
for prob in probs {
assert_eq!(
(prob * 10_000.0).round() as u32,
(10.02 as f64 * 100.0).round() as u32
(10.02_f64 * 100.0).round() as u32
);
}

assert_eq!(
(new_prob * 10_000.0).round() as u32,
(0.25 as f64 * 100.0).round() as u32
(0.25_f64 * 100.0).round() as u32
);
}

Expand All @@ -1675,12 +1677,12 @@ mod tests {

assert_eq!(
(probs[0] * 10_000.0).round() as u32,
(6.51 as f64 * 100.0).round() as u32
(6.51_f64 * 100.0).round() as u32
);

assert_eq!(
(new_prob * 10_000.0).round() as u32,
(3.49 as f64 * 100.0).round() as u32
(3.49_f64 * 100.0).round() as u32
);
}

Expand All @@ -1693,12 +1695,12 @@ mod tests {

assert_eq!(
(probs[0] * 10_000.0).round() as u32,
(0.63 as f64 * 100.0).round() as u32
(0.63_f64 * 100.0).round() as u32
);

assert_eq!(
(new_prob * 10_000.0).round() as u32,
(0.37 as f64 * 100.0).round() as u32
(0.37_f64 * 100.0).round() as u32
);
}

Expand All @@ -1711,12 +1713,12 @@ mod tests {

assert_eq!(
(probs[0] * 10_000.0).round() as u32,
(1.0 as f64 * 100.0).round() as u32
(1.0_f64 * 100.0).round() as u32
);

assert_eq!(
(new_prob * 10_000.0).round() as u32,
(0.08 as f64 * 100.0).round() as u32
(0.08_f64 * 100.0).round() as u32
);
}

Expand Down Expand Up @@ -1749,7 +1751,7 @@ mod tests {

assert_eq!(
(new_prob * 10_000.0).round() as u32,
(0.08 as f64 * 100.0).round() as u32
(0.08_f64 * 100.0).round() as u32
);
}

Expand All @@ -1769,7 +1771,7 @@ mod tests {

assert_eq!(
(new_prob * 10_000.0).round() as u32,
(0.0 as f64 * 100.0).round() as u32
(0_f64 * 100.0).round() as u32
);
}
}
Loading