Skip to content

Commit a042d4c

Browse files
authored
chore: Fix clippy lints in Rust beta (#10050)
* Fix max compact difficulty calculation in tests * Refactor duplicate tree checks to use if let instead of unwrap * Add clippy allow for `unwrap_in_result` in tests * Refactor error handling by replacing panics with Result propagation * Add `clippy::unwrap_in_result` to `zebra-utils` * fmt * Remove unnecessary clone call in get_block_1 test * Remove unused variable * Use Amount::zero instead of try_from for zero nonnegative amount Simplify amount initialization by replacing try_from(0) with Amount::zero() for clarity and consistency in joinsplit and sprout pool checks * Fix typo in comment from "Defence" to "Defense" * Add Default derive to CompactSizeMessage struct * Add From<SerializationError> for io::Error implementation * Simplify `zcash_serialize_{bytes, empty_list}` * Handle minimal height case safely in subtree validation * Move clippy allow for unwrap_in_result inside append method * Add From impl for Sprout NoteCommitmentTreeError in ValidateContextError * Simplify sprout anchor tree appends using error propagation * Improve error handling in height_from_signed_int conversions * Add error handling for conversion and overflow checks in ZIP-317 logic * Add explicit expect for mem_bytes length in truncate_zero_be_bytes
1 parent 7a7572f commit a042d4c

File tree

99 files changed

+279
-119
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+279
-119
lines changed

tower-batch-control/tests/ed25519.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Test batching using ed25519 verification.
22
3+
#![allow(clippy::unwrap_in_result)]
4+
35
use std::{
46
mem,
57
pin::Pin,

zebra-chain/src/amount/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//! Tests for amounts
22
3+
#![allow(clippy::unwrap_in_result)]
4+
35
mod prop;
46
mod vectors;

zebra-chain/src/block/arbitrary.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,9 +602,7 @@ where
602602
input.set_outpoint(selected_outpoint);
603603
new_inputs.push(input);
604604

605-
let spent_utxo = utxos
606-
.remove(&selected_outpoint)
607-
.expect("selected outpoint must have a UTXO");
605+
let spent_utxo = utxos.remove(&selected_outpoint)?;
608606
spent_outputs.insert(selected_outpoint, spent_utxo.utxo.output);
609607
}
610608
// otherwise, drop the invalid input, because it has no valid UTXOs to spend

zebra-chain/src/block/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Tests for Zebra blocks
22
3+
#![allow(clippy::unwrap_in_result)]
4+
35
// TODO: generate should be rewritten as strategies
46
#[cfg(any(test, feature = "bench", feature = "proptest-impl"))]
57
pub mod generate;

zebra-chain/src/chain_tip/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
#![allow(clippy::unwrap_in_result)]
2+
13
mod prop;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//! Tests for history trees
22
3+
#![allow(clippy::unwrap_in_result)]
4+
35
#[cfg(test)]
46
mod vectors;

zebra-chain/src/orchard/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::unwrap_in_result)]
2+
13
mod preallocate;
24
mod prop;
35
mod tree;

zebra-chain/src/parameters/checkpoint/list/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Tests for CheckpointList
22
3+
#![allow(clippy::unwrap_in_result)]
4+
35
use std::sync::Arc;
46

57
use num_integer::div_ceil;

zebra-chain/src/parameters/network/subsidy.rs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -712,34 +712,22 @@ pub fn height_for_halving(halving: u32, network: &Network) -> Option<Height> {
712712
}
713713

714714
let slow_start_shift = i64::from(network.slow_start_shift().0);
715-
let blossom_height = i64::from(
716-
NetworkUpgrade::Blossom
717-
.activation_height(network)
718-
.expect("blossom activation height should be available")
719-
.0,
720-
);
715+
let blossom_height = i64::from(NetworkUpgrade::Blossom.activation_height(network)?.0);
721716
let pre_blossom_halving_interval = network.pre_blossom_halving_interval();
722717
let halving_index = i64::from(halving);
723718

724-
let unscaled_height = halving_index
725-
.checked_mul(pre_blossom_halving_interval)
726-
.expect("Multiplication overflow: consider reducing the halving interval");
719+
let unscaled_height = halving_index.checked_mul(pre_blossom_halving_interval)?;
727720

728721
let pre_blossom_height = unscaled_height
729722
.min(blossom_height)
730-
.checked_add(slow_start_shift)
731-
.expect("Addition overflow: consider reducing the halving interval");
723+
.checked_add(slow_start_shift)?;
732724

733725
let post_blossom_height = 0
734726
.max(unscaled_height - blossom_height)
735-
.checked_mul(i64::from(BLOSSOM_POW_TARGET_SPACING_RATIO))
736-
.expect("Multiplication overflow: consider reducing the halving interval")
737-
.checked_add(slow_start_shift)
738-
.expect("Addition overflow: consider reducing the halving interval");
739-
740-
let height = pre_blossom_height
741-
.checked_add(post_blossom_height)
742-
.expect("Addition overflow: consider reducing the halving interval");
727+
.checked_mul(i64::from(BLOSSOM_POW_TARGET_SPACING_RATIO))?
728+
.checked_add(slow_start_shift)?;
729+
730+
let height = pre_blossom_height.checked_add(post_blossom_height)?;
743731

744732
let height = u32::try_from(height).ok()?;
745733
height.try_into().ok()

zebra-chain/src/parameters/network/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::unwrap_in_result)]
2+
13
mod prop;
24
mod vectors;
35

0 commit comments

Comments
 (0)