From ac7df092006ab9e4497f0f3284d76fd2b90c36df Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Thu, 8 Apr 2021 11:39:38 -0700 Subject: [PATCH 1/9] Remove needlessly taken reference of both operands, clippy warning https://rust-lang.github.io/rust-clippy/master/index.html#op_ref --- src/descriptor/policy.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/descriptor/policy.rs b/src/descriptor/policy.rs index 14e76e7f..e05134f9 100644 --- a/src/descriptor/policy.rs +++ b/src/descriptor/policy.rs @@ -1023,8 +1023,8 @@ mod test { assert!( matches!(&policy.item, Multisig { keys, threshold } if threshold == &2usize - && &keys[0].fingerprint.unwrap() == &fingerprint0 - && &keys[1].fingerprint.unwrap() == &fingerprint1) + && keys[0].fingerprint.unwrap() == fingerprint0 + && keys[1].fingerprint.unwrap() == fingerprint1) ); // TODO should this be "Satisfaction::None" since we have no prv keys? // TODO should items and conditions not be empty? @@ -1054,8 +1054,8 @@ mod test { .unwrap(); assert!( matches!(&policy.item, Multisig { keys, threshold } if threshold == &2usize - && &keys[0].fingerprint.unwrap() == &fingerprint0 - && &keys[1].fingerprint.unwrap() == &fingerprint1) + && keys[0].fingerprint.unwrap() == fingerprint0 + && keys[1].fingerprint.unwrap() == fingerprint1) ); assert!( From b68ec050e20f28810ee4622082021a166276bbe2 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Thu, 8 Apr 2021 11:41:58 -0700 Subject: [PATCH 2/9] Remove redundant clone, clippy warning https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone --- src/descriptor/policy.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/descriptor/policy.rs b/src/descriptor/policy.rs index e05134f9..c8df81f5 100644 --- a/src/descriptor/policy.rs +++ b/src/descriptor/policy.rs @@ -1429,7 +1429,7 @@ mod test { ) ); - let mut policy_clone = original_policy.clone(); + let mut policy_clone = original_policy; let psbt: PSBT = deserialize(&base64::decode(ALICE_BOB_SIGNED_PSBT).unwrap()).unwrap(); policy_clone .fill_satisfactions(&psbt, &wallet_desc, &secp) From af98b8da063b72d20f26ae210ad18108ffbe0471 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Thu, 8 Apr 2021 12:12:51 -0700 Subject: [PATCH 3/9] Compare float equality using error margin EPSILON, clippy warning https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp --- src/wallet/coin_selection.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/wallet/coin_selection.rs b/src/wallet/coin_selection.rs index 47ef2d99..5653662d 100644 --- a/src/wallet/coin_selection.rs +++ b/src/wallet/coin_selection.rs @@ -654,7 +654,7 @@ mod test { assert_eq!(result.selected.len(), 3); assert_eq!(result.selected_amount(), 300_010); - assert_eq!(result.fee_amount, 254.0); + assert!((result.fee_amount - 254.0).abs() < f32::EPSILON); } #[test] @@ -675,7 +675,7 @@ mod test { assert_eq!(result.selected.len(), 3); assert_eq!(result.selected_amount(), 300_010); - assert_eq!(result.fee_amount, 254.0); + assert!((result.fee_amount - 254.0).abs() < f32::EPSILON); } #[test] @@ -696,7 +696,7 @@ mod test { assert_eq!(result.selected.len(), 1); assert_eq!(result.selected_amount(), 200_000); - assert_eq!(result.fee_amount, 118.0); + assert!((result.fee_amount - 118.0).abs() < f32::EPSILON); } #[test] @@ -756,7 +756,7 @@ mod test { assert_eq!(result.selected.len(), 3); assert_eq!(result.selected_amount(), 300_000); - assert_eq!(result.fee_amount, 254.0); + assert!((result.fee_amount - 254.0).abs() < f32::EPSILON); } #[test] @@ -777,7 +777,7 @@ mod test { assert_eq!(result.selected.len(), 3); assert_eq!(result.selected_amount(), 300_010); - assert_eq!(result.fee_amount, 254.0); + assert!((result.fee_amount - 254.0).abs() < f32::EPSILON); } #[test] @@ -798,7 +798,7 @@ mod test { assert_eq!(result.selected.len(), 3); assert_eq!(result.selected_amount(), 300010); - assert_eq!(result.fee_amount, 254.0); + assert!((result.fee_amount - 254.0).abs() < f32::EPSILON); } #[test] @@ -968,7 +968,7 @@ mod test { cost_of_change, ) .unwrap(); - assert_eq!(result.fee_amount, 186.0); + assert!((result.fee_amount - 186.0).abs() < f32::EPSILON); assert_eq!(result.selected_amount(), 100_000); } @@ -1031,9 +1031,8 @@ mod test { ); assert!(result.selected_amount() > target_amount); - assert_eq!( - result.fee_amount, - 50.0 + result.selected.len() as f32 * 68.0 + assert!( + (result.fee_amount - (50.0 + result.selected.len() as f32 * 68.0)).abs() < f32::EPSILON ); } } From 2380634496139507a2ad0e44f453ebf9926ef351 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Thu, 8 Apr 2021 12:16:58 -0700 Subject: [PATCH 4/9] Use .get(0) instead of .iter().next(), clippy warning https://rust-lang.github.io/rust-clippy/master/index.html#iter_next_slice --- src/wallet/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs index 644854d5..73169a02 100644 --- a/src/wallet/mod.rs +++ b/src/wallet/mod.rs @@ -190,7 +190,7 @@ pub enum AddressIndex { /// then the returned address and subsequent addresses returned by calls to `AddressIndex::New` /// and `AddressIndex::LastUsed` may have already been used. Also if the index is reset to a /// value earlier than the [`crate::blockchain::Blockchain`] stop_gap (default is 20) then a - /// larger stop_gap should be used to monitor for all possibly used addresses. + /// larger stop_gap should be used to monitor for all possibly used addresses. Reset(u32), } @@ -1633,7 +1633,7 @@ mod test { .database .borrow_mut() .set_script_pubkey( - &bitcoin::Address::from_str(&tx_meta.output.iter().next().unwrap().to_address) + &bitcoin::Address::from_str(&tx_meta.output.get(0).unwrap().to_address) .unwrap() .script_pubkey(), KeychainKind::External, @@ -3615,7 +3615,7 @@ mod test { #[test] fn test_unused_address() { let db = MemoryDatabase::new(); - let wallet = Wallet::new_offline("wpkh(tpubEBr4i6yk5nf5DAaJpsi9N2pPYBeJ7fZ5Z9rmN4977iYLCGco1VyjB9tvvuvYtfZzjD5A8igzgw3HeWeeKFmanHYqksqZXYXGsw5zjnj7KM9/*)", + let wallet = Wallet::new_offline("wpkh(tpubEBr4i6yk5nf5DAaJpsi9N2pPYBeJ7fZ5Z9rmN4977iYLCGco1VyjB9tvvuvYtfZzjD5A8igzgw3HeWeeKFmanHYqksqZXYXGsw5zjnj7KM9/*)", None, Network::Testnet, db).unwrap(); assert_eq!( From 5f873ae500b4268bb263c0344d5acc4b19cac65b Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Thu, 8 Apr 2021 12:19:40 -0700 Subject: [PATCH 5/9] Use .any() instead of .find().is_some(), clippy warning https://rust-lang.github.io/rust-clippy/master/index.html#search_is_some --- src/wallet/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs index 73169a02..b0db0ec3 100644 --- a/src/wallet/mod.rs +++ b/src/wallet/mod.rs @@ -2431,8 +2431,7 @@ mod test { .unsigned_tx .input .iter() - .find(|input| input.previous_output == utxo.outpoint) - .is_some(), + .any(|input| input.previous_output == utxo.outpoint), "foreign_utxo should be in there" ); From e37680af96f20d4995e918d84789f5f7d9aa4054 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Thu, 8 Apr 2021 13:37:59 -0700 Subject: [PATCH 6/9] Use .flatten() instead of .filter_map(|x| x), clippy warning https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_identity --- src/descriptor/policy.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/descriptor/policy.rs b/src/descriptor/policy.rs index c8df81f5..f387fea8 100644 --- a/src/descriptor/policy.rs +++ b/src/descriptor/policy.rs @@ -870,7 +870,7 @@ impl ExtractPolicy for Miniscript .map(|n| n.extract_policy(signers, secp)) .collect::, _>>()? .into_iter() - .filter_map(|x| x) + .flatten() .collect(); if mapped.len() < nodes.len() { From 4da7488dc481f441a6ad3f7c2e013407fcb92f8b Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Thu, 8 Apr 2021 14:36:07 -0700 Subject: [PATCH 7/9] Update 'cargo-check.sh' to not check +nightly --- scripts/cargo-check.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/cargo-check.sh b/scripts/cargo-check.sh index 86508866..a014f621 100755 --- a/scripts/cargo-check.sh +++ b/scripts/cargo-check.sh @@ -3,7 +3,7 @@ # Run various invocations of cargo check features=( "default" "compiler" "electrum" "esplora" "compact_filters" "key-value-db" "async-interface" "all-keys" "keys-bip39" ) -toolchains=( "+stable" "+1.46" "+nightly" ) +toolchains=( "+stable" "+1.46" ) main() { check_src @@ -17,6 +17,7 @@ check_src() { for feature in "${features[@]}"; do touch_files + echo $cmd --features "$feature" $cmd --features "$feature" done done From 8e7d8312a943516e9110214ce18ccd9420602a04 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Thu, 8 Apr 2021 14:44:35 -0700 Subject: [PATCH 8/9] [ci] Update 'build-test' job to clippy check all-targets --- .github/workflows/cont_integration.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index b0080925..3a92f052 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -46,7 +46,7 @@ jobs: - name: Build run: cargo build --features ${{ matrix.features }} --no-default-features - name: Clippy - run: cargo clippy --features ${{ matrix.features }} --no-default-features -- -D warnings + run: cargo clippy --all-targets --features ${{ matrix.features }} --no-default-features -- -D warnings - name: Test run: cargo test --features ${{ matrix.features }} --no-default-features @@ -151,7 +151,7 @@ jobs: run: rustup default 1.51.0 # STABLE - name: Set profile run: rustup set profile minimal - - name: Add clippy + - name: Add rustfmt run: rustup component add rustfmt - name: Update toolchain run: rustup update From 3ed44ce8cfe0b7539bb7aa98bbb32411a11d2481 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Fri, 9 Apr 2021 09:19:19 -0700 Subject: [PATCH 9/9] Remove unneeded script --- scripts/cargo-check.sh | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100755 scripts/cargo-check.sh diff --git a/scripts/cargo-check.sh b/scripts/cargo-check.sh deleted file mode 100755 index a014f621..00000000 --- a/scripts/cargo-check.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -# -# Run various invocations of cargo check - -features=( "default" "compiler" "electrum" "esplora" "compact_filters" "key-value-db" "async-interface" "all-keys" "keys-bip39" ) -toolchains=( "+stable" "+1.46" ) - -main() { - check_src - check_all_targets -} - -# Check with all features, with various toolchains. -check_src() { - for toolchain in "${toolchains[@]}"; do - cmd="cargo $toolchain clippy --all-targets --no-default-features" - - for feature in "${features[@]}"; do - touch_files - echo $cmd --features "$feature" - $cmd --features "$feature" - done - done -} - -# Touch files to prevent cached warnings from not showing up. -touch_files() { - touch $(find . -name *.rs) -} - -main -exit 0