Skip to content

Commit 388e9d2

Browse files
committed
chore: make clippy fail tests on warnings
1 parent 0b69ae2 commit 388e9d2

File tree

29 files changed

+132
-158
lines changed

29 files changed

+132
-158
lines changed

.github/workflows/run-tests-on-push-to-main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
run: cargo fmt --all -- --check
2525

2626
- name: Run Clippy
27-
run: cargo clippy --all-targets --all-features
27+
run: cargo clippy --all-targets --all-features -- -D warnings
2828

2929
- name: Run Build
3030
run: cargo build --verbose

codec/src/map_parameters.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub fn map_nullable_gov_action_id(
198198
fn map_constitution(constitution: &conway::Constitution) -> Constitution {
199199
Constitution {
200200
anchor: map_anchor(&constitution.anchor),
201-
guardrail_script: map_nullable(|x| to_hash(x), &constitution.guardrail_script),
201+
guardrail_script: map_nullable(to_hash, &constitution.guardrail_script),
202202
}
203203
}
204204

common/src/address.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,8 @@ impl StakeAddress {
398398

399399
pub fn get_credential(&self) -> Credential {
400400
match &self.credential {
401-
StakeCredential::AddrKeyHash(hash) => Credential::AddrKeyHash(hash.clone()),
402-
StakeCredential::ScriptHash(hash) => Credential::ScriptHash(hash.clone()),
401+
StakeCredential::AddrKeyHash(hash) => Credential::AddrKeyHash(*hash),
402+
StakeCredential::ScriptHash(hash) => Credential::ScriptHash(*hash),
403403
}
404404
}
405405

@@ -411,7 +411,7 @@ impl StakeAddress {
411411
};
412412

413413
let data = self.to_binary();
414-
Ok(bech32::encode::<bech32::Bech32>(hrp, &data.as_slice())?)
414+
Ok(bech32::encode::<bech32::Bech32>(hrp, data.as_slice())?)
415415
}
416416

417417
/// Read from a string format ("stake1xxx...")
@@ -520,7 +520,7 @@ impl<C> minicbor::Encode<C> for StakeAddress {
520520
_ctx: &mut C,
521521
) -> Result<(), minicbor::encode::Error<W::Error>> {
522522
let data = self.to_binary();
523-
e.bytes(&data.as_slice())?;
523+
e.bytes(data.as_slice())?;
524524
Ok(())
525525
}
526526
}
@@ -902,7 +902,7 @@ mod tests {
902902
assert_eq!(sa.network, NetworkId::Mainnet);
903903
assert_eq!(
904904
match sa.credential {
905-
StakeCredential::AddrKeyHash(key) => hex::encode(&key),
905+
StakeCredential::AddrKeyHash(key) => hex::encode(key),
906906
_ => "SCRIPT".to_string(),
907907
},
908908
"558f3ee09b26d88fac2eddc772a9eda94cce6dbadbe9fee439bd6001"
@@ -918,7 +918,7 @@ mod tests {
918918
assert_eq!(sa.network, NetworkId::Mainnet);
919919
assert_eq!(
920920
match sa.credential {
921-
StakeCredential::ScriptHash(key) => hex::encode(&key),
921+
StakeCredential::ScriptHash(key) => hex::encode(key),
922922
_ => "STAKE".to_string(),
923923
},
924924
"558f3ee09b26d88fac2eddc772a9eda94cce6dbadbe9fee439bd6001"
@@ -934,7 +934,7 @@ mod tests {
934934
assert_eq!(sa.network, NetworkId::Testnet);
935935
assert_eq!(
936936
match sa.credential {
937-
StakeCredential::AddrKeyHash(key) => hex::encode(&key),
937+
StakeCredential::AddrKeyHash(key) => hex::encode(key),
938938
_ => "SCRIPT".to_string(),
939939
},
940940
"558f3ee09b26d88fac2eddc772a9eda94cce6dbadbe9fee439bd6001"
@@ -963,7 +963,7 @@ mod tests {
963963
// - 0x1d: Length of 29 bytes (the stake address data)
964964
// - [29 bytes]: The actual stake address (network header + 28-byte hash)
965965
// Total: 31 bytes (2-byte CBOR framing + 29-byte payload)
966-
let expected = [[0x58, 0x1d].as_slice(), &binary.as_slice()].concat();
966+
let expected = [[0x58, 0x1d].as_slice(), binary.as_slice()].concat();
967967

968968
let mut actual = Vec::new();
969969
let mut encoder = minicbor::Encoder::new(&mut actual);
@@ -977,7 +977,7 @@ mod tests {
977977
fn stake_addresses_decode_mainnet_stake() {
978978
let binary = {
979979
let mut v = vec![0x58, 0x1d];
980-
v.extend_from_slice(&mainnet_stake_address().to_binary().as_slice());
980+
v.extend_from_slice(mainnet_stake_address().to_binary().as_slice());
981981
v
982982
};
983983

@@ -987,7 +987,7 @@ mod tests {
987987
assert_eq!(decoded.network, NetworkId::Mainnet);
988988
assert_eq!(
989989
match decoded.credential {
990-
StakeCredential::AddrKeyHash(key) => hex::encode(&key),
990+
StakeCredential::AddrKeyHash(key) => hex::encode(key),
991991
_ => "STAKE".to_string(),
992992
},
993993
"558f3ee09b26d88fac2eddc772a9eda94cce6dbadbe9fee439bd6001"
@@ -1010,7 +1010,7 @@ mod tests {
10101010
assert_eq!(decoded.network, NetworkId::Mainnet);
10111011
assert_eq!(
10121012
match decoded.credential {
1013-
StakeCredential::ScriptHash(key) => hex::encode(&key),
1013+
StakeCredential::ScriptHash(key) => hex::encode(key),
10141014
_ => "STAKE".to_string(),
10151015
},
10161016
"558f3ee09b26d88fac2eddc772a9eda94cce6dbadbe9fee439bd6001"
@@ -1031,7 +1031,7 @@ mod tests {
10311031
assert_eq!(decoded.network, NetworkId::Testnet);
10321032
assert_eq!(
10331033
match decoded.credential {
1034-
StakeCredential::ScriptHash(key) => hex::encode(&key),
1034+
StakeCredential::ScriptHash(key) => hex::encode(key),
10351035
_ => "SCRIPT".to_string(),
10361036
},
10371037
"558f3ee09b26d88fac2eddc772a9eda94cce6dbadbe9fee439bd6001"

common/src/crypto.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use cryptoxide::hashing::blake2b::Blake2b;
99
pub fn keyhash_256(key: &[u8]) -> Hash<32> {
1010
let mut context = Blake2b::<256>::new();
1111
context.update_mut(key);
12-
Hash::new(context.finalize().into())
12+
Hash::new(context.finalize())
1313
}
1414

1515
/// Get a Blake2b-224 hash of a key
@@ -18,5 +18,5 @@ pub fn keyhash_256(key: &[u8]) -> Hash<32> {
1818
pub fn keyhash_224(key: &[u8]) -> Hash<28> {
1919
let mut context = Blake2b::<224>::new();
2020
context.update_mut(key);
21-
Hash::new(context.finalize().into())
21+
Hash::new(context.finalize())
2222
}

common/src/hash.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,10 @@ macro_rules! declare_hash_type_with_bech32 {
312312
}
313313
}
314314

315-
impl crate::serialization::Bech32Conversion for $name {
315+
impl $crate::serialization::Bech32Conversion for $name {
316316
fn to_bech32(&self) -> Result<String, anyhow::Error> {
317-
use crate::serialization::Bech32WithHrp;
318317
use anyhow::Context;
318+
use $crate::serialization::Bech32WithHrp;
319319

320320
self.as_ref().to_bech32_with_hrp($hrp).with_context(|| {
321321
format!(
@@ -327,8 +327,8 @@ macro_rules! declare_hash_type_with_bech32 {
327327
}
328328

329329
fn from_bech32(s: &str) -> Result<Self, anyhow::Error> {
330-
use crate::serialization::Bech32WithHrp;
331330
use anyhow::Context;
331+
use $crate::serialization::Bech32WithHrp;
332332

333333
let v = Vec::<u8>::from_bech32_with_hrp(s, $hrp).with_context(|| {
334334
format!("Failed to decode {} from bech32", stringify!($name))

common/src/queries/blocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl Serialize for BlockInfo {
157157
"block_vrf",
158158
&self.block_vrf.and_then(|vkey| vkey.to_bech32().ok()),
159159
)?;
160-
state.serialize_field("op_cert", &self.op_cert.clone().map(hex::encode))?;
160+
state.serialize_field("op_cert", &self.op_cert.map(hex::encode))?;
161161
state.serialize_field("op_cert_counter", &self.op_cert_counter)?;
162162
state.serialize_field("previous_block", &self.previous_block)?;
163163
state.serialize_field("next_block", &self.next_block)?;

common/src/stake_addresses.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,11 @@ impl StakeAddressMap {
150150
let sas_data: Vec<(PoolId, u64)> = self
151151
.inner
152152
.values()
153-
.filter_map(|sas| sas.delegated_spo.as_ref().map(|spo| (spo.clone(), sas.utxo_value)))
153+
.filter_map(|sas| sas.delegated_spo.as_ref().map(|spo| (*spo, sas.utxo_value)))
154154
.collect();
155155

156156
sas_data.iter().for_each(|(spo, utxo_value)| {
157-
live_stakes_map
158-
.entry(spo.clone())
159-
.and_modify(|v| *v += utxo_value)
160-
.or_insert(*utxo_value);
157+
live_stakes_map.entry(*spo).and_modify(|v| *v += utxo_value).or_insert(*utxo_value);
161158
});
162159

163160
spos.iter()
@@ -298,7 +295,7 @@ impl StakeAddressMap {
298295
.inner
299296
.values()
300297
.filter_map(|sas| {
301-
sas.delegated_spo.as_ref().map(|spo| (spo.clone(), (sas.utxo_value, sas.rewards)))
298+
sas.delegated_spo.as_ref().map(|spo| (*spo, (sas.utxo_value, sas.rewards)))
302299
})
303300
.collect();
304301

@@ -307,7 +304,7 @@ impl StakeAddressMap {
307304
.par_iter() // Rayon multi-threaded iterator
308305
.for_each(|(spo, (utxo_value, rewards))| {
309306
spo_stakes
310-
.entry(spo.clone())
307+
.entry(*spo)
311308
.and_modify(|v| {
312309
v.active += *utxo_value;
313310
v.active_delegators_count += 1;
@@ -321,7 +318,7 @@ impl StakeAddressMap {
321318
});
322319

323320
// Collect into a plain BTreeMap, so that it is ordered on output
324-
spo_stakes.iter().map(|entry| (entry.key().clone(), *entry.value())).collect()
321+
spo_stakes.iter().map(|entry| (*entry.key(), *entry.value())).collect()
325322
}
326323

327324
/// Dump current Stake Pool Delegation Distribution State
@@ -331,7 +328,7 @@ impl StakeAddressMap {
331328
.inner
332329
.par_iter()
333330
.filter_map(|(key, sas)| {
334-
sas.delegated_spo.as_ref().map(|spo| (spo.clone(), (key.clone(), sas.utxo_value)))
331+
sas.delegated_spo.as_ref().map(|spo| (*spo, (key.clone(), sas.utxo_value)))
335332
})
336333
.collect();
337334

@@ -436,7 +433,7 @@ impl StakeAddressMap {
436433
pub fn record_stake_delegation(&mut self, stake_address: &StakeAddress, spo: &PoolId) -> bool {
437434
if let Some(sas) = self.get_mut(stake_address) {
438435
if sas.registered {
439-
sas.delegated_spo = Some(spo.clone());
436+
sas.delegated_spo = Some(*spo);
440437
true
441438
} else {
442439
error!(
@@ -1251,8 +1248,8 @@ mod tests {
12511248
let map = stake_addresses.get_accounts_utxo_values_map(&keys).unwrap();
12521249

12531250
assert_eq!(map.len(), 2);
1254-
assert_eq!(map.get(&addr1.get_hash()).copied().unwrap(), 1000);
1255-
assert_eq!(map.get(&addr2.get_hash()).copied().unwrap(), 2000);
1251+
assert_eq!(map.get(addr1.get_hash()).copied().unwrap(), 1000);
1252+
assert_eq!(map.get(addr2.get_hash()).copied().unwrap(), 2000);
12561253
}
12571254

12581255
#[test]
@@ -1365,8 +1362,8 @@ mod tests {
13651362
let map = stake_addresses.get_accounts_balances_map(&addresses).unwrap();
13661363

13671364
assert_eq!(map.len(), 2);
1368-
assert_eq!(map.get(&addr1.get_hash()).copied().unwrap(), 1100);
1369-
assert_eq!(map.get(&addr2.get_hash()).copied().unwrap(), 2000);
1365+
assert_eq!(map.get(addr1.get_hash()).copied().unwrap(), 1100);
1366+
assert_eq!(map.get(addr2.get_hash()).copied().unwrap(), 2000);
13701367
}
13711368

13721369
#[test]
@@ -1474,14 +1471,14 @@ mod tests {
14741471

14751472
assert_eq!(map.len(), 3);
14761473
assert_eq!(
1477-
map.get(&addr1.get_hash()).unwrap(),
1474+
map.get(addr1.get_hash()).unwrap(),
14781475
&Some(DRepChoice::Abstain)
14791476
);
14801477
assert_eq!(
1481-
map.get(&addr2.get_hash()).unwrap(),
1478+
map.get(addr2.get_hash()).unwrap(),
14821479
&Some(DRepChoice::Key(DREP_HASH))
14831480
);
1484-
assert_eq!(map.get(&addr3.get_hash()).unwrap(), &None);
1481+
assert_eq!(map.get(addr3.get_hash()).unwrap(), &None);
14851482
}
14861483

14871484
#[test]

common/src/types.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,11 +723,10 @@ impl Credential {
723723
}
724724

725725
pub fn get_hash(&self) -> KeyHash {
726-
match self {
726+
*match self {
727727
Self::AddrKeyHash(hash) => hash,
728728
Self::ScriptHash(hash) => hash,
729729
}
730-
.clone()
731730
}
732731

733732
pub fn from_drep_bech32(bech32_str: &str) -> Result<Self, Error> {

modules/accounts_state/src/accounts_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ impl AccountsState {
510510
AccountsStateQueryResponse::AccountInfo(AccountInfo {
511511
utxo_value: account.utxo_value,
512512
rewards: account.rewards,
513-
delegated_spo: account.delegated_spo.clone(),
513+
delegated_spo: account.delegated_spo,
514514
delegated_drep: account.delegated_drep.clone(),
515515
})
516516
} else {

modules/accounts_state/src/rewards.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ pub fn calculate_rewards(
213213
result.total_paid += reward.amount;
214214
}
215215

216-
result.rewards.insert(operator_id.clone(), rewards);
217-
result.spo_rewards.push((operator_id.clone(), spo_rewards));
216+
result.rewards.insert(*operator_id, rewards);
217+
result.spo_rewards.push((*operator_id, spo_rewards));
218218
}
219219
}
220220

0 commit comments

Comments
 (0)