Skip to content

Commit

Permalink
chore: fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Oct 9, 2023
1 parent f3fd080 commit 48d79c9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
name: Clippy
with:
command: clippy
args: --workspace --all-features --all-targets -D warnings
args: --workspace --all-features --all-targets -- -D warnings
doc:
runs-on: ubuntu-latest
steps:
Expand Down
44 changes: 22 additions & 22 deletions consensus/src/coding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,10 +715,10 @@ mod tests {
d: impl AsRef<[u8]>,
) -> Result<T, ConsensusDataError> {
let mut cursor = Cursor::new(d.as_ref());
Ok(T::consensus_decode(&mut cursor).map_err(|err| match err {
T::consensus_decode(&mut cursor).map_err(|err| match err {
ConsensusDecodeError::Data(e) => e,
ConsensusDecodeError::Io(_) => unreachable!(),
})?)
})
}

#[test]
Expand Down Expand Up @@ -860,44 +860,44 @@ mod tests {
#[test]
fn deserialize_int_test() {
// u8
assert_eq!(deserialize(&[58u8]).ok(), Some(58u8));
assert_eq!(deserialize([58u8]).ok(), Some(58u8));

// u16
assert_eq!(deserialize(&[0x01u8, 0x02]).ok(), Some(0x0201u16));
assert_eq!(deserialize(&[0xABu8, 0xCD]).ok(), Some(0xCDABu16));
assert_eq!(deserialize(&[0xA0u8, 0x0D]).ok(), Some(0xDA0u16));
let failure16: Result<u16, _> = deserialize(&[1u8]);
assert_eq!(deserialize([0x01u8, 0x02]).ok(), Some(0x0201u16));
assert_eq!(deserialize([0xABu8, 0xCD]).ok(), Some(0xCDABu16));
assert_eq!(deserialize([0xA0u8, 0x0D]).ok(), Some(0xDA0u16));
let failure16: Result<u16, _> = deserialize([1u8]);
assert!(failure16.is_err());

// u32
assert_eq!(deserialize(&[0xABu8, 0xCD, 0, 0]).ok(), Some(0xCDABu32));
assert_eq!(deserialize(&[0xA0u8, 0x0D, 0xAB, 0xCD]).ok(), Some(0xCDAB0DA0u32));
assert_eq!(deserialize([0xABu8, 0xCD, 0, 0]).ok(), Some(0xCDABu32));
assert_eq!(deserialize([0xA0u8, 0x0D, 0xAB, 0xCD]).ok(), Some(0xCDAB0DA0u32));

let failure32: Result<u32, _> = deserialize(&[1u8, 2, 3]);
let failure32: Result<u32, _> = deserialize([1u8, 2, 3]);
assert!(failure32.is_err());

// i32
assert_eq!(deserialize(&[0xABu8, 0xCD, 0, 0]).ok(), Some(0xCDABi32));
assert_eq!(deserialize(&[0xA0u8, 0x0D, 0xAB, 0x2D]).ok(), Some(0x2DAB0DA0i32));
assert_eq!(deserialize([0xABu8, 0xCD, 0, 0]).ok(), Some(0xCDABi32));
assert_eq!(deserialize([0xA0u8, 0x0D, 0xAB, 0x2D]).ok(), Some(0x2DAB0DA0i32));

assert_eq!(deserialize(&[0, 0, 0, 0]).ok(), Some(-0_i32));
assert_eq!(deserialize(&[0, 0, 0, 0]).ok(), Some(0_i32));
assert_eq!(deserialize([0, 0, 0, 0]).ok(), Some(-0_i32));
assert_eq!(deserialize([0, 0, 0, 0]).ok(), Some(0_i32));

assert_eq!(deserialize(&[0xFF, 0xFF, 0xFF, 0xFF]).ok(), Some(-1_i32));
assert_eq!(deserialize(&[0xFE, 0xFF, 0xFF, 0xFF]).ok(), Some(-2_i32));
assert_eq!(deserialize(&[0x01, 0xFF, 0xFF, 0xFF]).ok(), Some(-255_i32));
assert_eq!(deserialize(&[0x02, 0xFF, 0xFF, 0xFF]).ok(), Some(-254_i32));
assert_eq!(deserialize([0xFF, 0xFF, 0xFF, 0xFF]).ok(), Some(-1_i32));
assert_eq!(deserialize([0xFE, 0xFF, 0xFF, 0xFF]).ok(), Some(-2_i32));
assert_eq!(deserialize([0x01, 0xFF, 0xFF, 0xFF]).ok(), Some(-255_i32));
assert_eq!(deserialize([0x02, 0xFF, 0xFF, 0xFF]).ok(), Some(-254_i32));

let failurei32: Result<i32, _> = deserialize(&[1u8, 2, 3]);
let failurei32: Result<i32, _> = deserialize([1u8, 2, 3]);
assert!(failurei32.is_err());

// u64
assert_eq!(deserialize(&[0xABu8, 0xCD, 0, 0, 0, 0, 0, 0]).ok(), Some(0xCDABu64));
assert_eq!(deserialize([0xABu8, 0xCD, 0, 0, 0, 0, 0, 0]).ok(), Some(0xCDABu64));
assert_eq!(
deserialize(&[0xA0u8, 0x0D, 0xAB, 0xCD, 0x99, 0, 0, 0x99]).ok(),
deserialize([0xA0u8, 0x0D, 0xAB, 0xCD, 0x99, 0, 0, 0x99]).ok(),
Some(0x99000099CDAB0DA0u64)
);
let failure64: Result<u64, _> = deserialize(&[1u8, 2, 3, 4, 5, 6, 7]);
let failure64: Result<u64, _> = deserialize([1u8, 2, 3, 4, 5, 6, 7]);
assert!(failure64.is_err());
}
}
3 changes: 1 addition & 2 deletions consensus/src/segwit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ impl ScriptPubkey {
};
let push_opbyte = self[1]; // Second byte push opcode 2-40 bytes
WitnessVer::from_op_code(ver_opcode).is_ok()
&& push_opbyte >= OP_PUSHBYTES_2
&& push_opbyte <= OP_PUSHBYTES_40
&& (OP_PUSHBYTES_2..=OP_PUSHBYTES_40).contains(&push_opbyte)

Check warning on line 300 in consensus/src/segwit.rs

View check run for this annotation

Codecov / codecov/patch

consensus/src/segwit.rs#L300

Added line #L300 was not covered by tests
// Check that the rest of the script has the correct size
&& script_len - 2 == push_opbyte as usize
}
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ pub struct Sats(

impl Sats {
pub const ZERO: Self = Sats(0);
#[allow(clippy::inconsistent_digit_grouping)]
pub const BTC: Self = Sats(1_000_000_00);

pub const fn from_btc(btc: u32) -> Self { Self(btc as u64 * Self::BTC.0) }
Expand Down Expand Up @@ -443,7 +444,7 @@ impl FromStr for Tx {

fn from_str(s: &str) -> Result<Self, Self::Err> {
let data = Vec::<u8>::from_hex(s)?;
Tx::consensus_deserialize(&data).map_err(TxParseError::from)
Tx::consensus_deserialize(data).map_err(TxParseError::from)
}
}

Expand Down

0 comments on commit 48d79c9

Please sign in to comment.