Fix clippy test issues (#850)

* Fix clippy test issues

* Address review feedback
This commit is contained in:
Ross Savage
2025-04-03 12:21:27 +02:00
committed by GitHub
parent 7a9aa02cf7
commit 3f94fd970a
8 changed files with 552 additions and 572 deletions

View File

@@ -5,5 +5,5 @@ set -e
# Cargo syntax checks
dirs=("lib" "cli")
for dir in ${dirs[@]}; do
(cd $dir; exec cargo fmt; exec cargo clippy -- -D warnings)
(cd $dir; exec cargo fmt; exec cargo clippy --all-targets -- -D warnings)
done

View File

@@ -48,11 +48,11 @@ jobs:
- name: Clippy bindings
working-directory: lib/bindings
run: cargo clippy -- -D warnings
run: cargo clippy --all-targets -- -D warnings
- name: Clippy core
working-directory: lib/core
run: cargo clippy -- -D warnings
run: cargo clippy --all-targets -- -D warnings
- name: Clippy cli
working-directory: cli

View File

@@ -12,10 +12,8 @@ fmt:
clippy: cargo-clippy wasm-clippy
cargo-clippy:
cd lib/bindings && cargo clippy -- -D warnings
cd lib/bindings && cargo clippy --tests -- -D warnings
cd lib/core && cargo clippy -- -D warnings
cd lib/core && cargo clippy --tests -- -D warnings
cd lib/bindings && cargo clippy --all-targets -- -D warnings
cd lib/core && cargo clippy --all-targets -- -D warnings
cd cli && cargo clippy -- -D warnings
wasm-clippy:

View File

@@ -18,7 +18,7 @@ test: cargo-test wasm-test
regtest-test: cargo-regtest-test wasm-regtest-test
cargo-clippy:
cargo clippy -- -D warnings
cargo clippy --all-targets -- -D warnings
cargo-test:
cargo test
@@ -40,7 +40,7 @@ cargo-regtest-test: check-regtest
$(REGTEST_PREFIX) cargo test $(REGTEST_TESTS) --features "regtest"
wasm-clippy:
$(CLANG_PREFIX) cargo clippy --target=wasm32-unknown-unknown -- -D warnings
$(CLANG_PREFIX) cargo clippy --all-targets --target=wasm32-unknown-unknown -- -D warnings
BROWSER ?= firefox

View File

@@ -1,12 +1,9 @@
#[cfg(test)]
mod tests {
#![cfg(test)]
use anyhow::Result;
use bip39::rand::{self, RngCore};
use lwk_wollet::bitcoin;
use lwk_wollet::elements::address::AddressParams;
use lwk_wollet::elements::confidential::{
Asset, AssetBlindingFactor, Value, ValueBlindingFactor,
};
use lwk_wollet::elements::confidential::{Asset, AssetBlindingFactor, Value, ValueBlindingFactor};
use lwk_wollet::elements::secp256k1_zkp::SecretKey;
use lwk_wollet::elements::{secp256k1_zkp, Address, AssetId, Script, TxOutSecrets, Txid};
use std::str::FromStr;
@@ -26,8 +23,7 @@ mod tests {
fn create_test_input(asset_id: AssetId, sk: &SecretKey) -> PsetInput {
// Create a dummy txid
let txid =
Txid::from_str("0000000000000000000000000000000000000000000000000000000000000001")
.unwrap();
Txid::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap();
// Create a dummy script pubkey
let script_pub_key =
@@ -37,11 +33,8 @@ mod tests {
let secp = secp256k1_zkp::Secp256k1::new();
let asset_bf = AssetBlindingFactor::from_slice(&sk.secret_bytes()).unwrap();
let asset_gen = secp256k1_zkp::Generator::new_blinded(
&secp,
asset_id.into_tag(),
asset_bf.into_inner(),
);
let asset_gen =
secp256k1_zkp::Generator::new_blinded(&secp, asset_id.into_tag(), asset_bf.into_inner());
let asset_commitment = Asset::Confidential(asset_gen);
// Create a Pedersen commitment for the value
@@ -73,8 +66,7 @@ mod tests {
let secp = secp256k1_zkp::Secp256k1::new();
let blinding_key =
bitcoin::PublicKey::new(secp256k1_zkp::PublicKey::from_secret_key(&secp, sk));
let address_pk =
bitcoin::PublicKey::new(secp256k1_zkp::PublicKey::from_secret_key(&secp, sk));
let address_pk = bitcoin::PublicKey::new(secp256k1_zkp::PublicKey::from_secret_key(&secp, sk));
let address = Address::p2pkh(
&address_pk,
@@ -197,4 +189,3 @@ mod tests {
let result = construct_pset(request);
assert!(result.is_err());
}
}

View File

@@ -1,5 +1,4 @@
#[cfg(test)]
mod tests {
#![cfg(test)]
use std::collections::BTreeMap;
use lwk_wollet::elements::AssetId;
@@ -7,8 +6,8 @@ mod tests {
use crate::payjoin::{
model::InOut,
utxo_select::{
utxo_select, utxo_select_basic, utxo_select_best, utxo_select_fixed,
utxo_select_in_range, UtxoSelectRequest,
utxo_select, utxo_select_basic, utxo_select_best, utxo_select_fixed, utxo_select_in_range,
UtxoSelectRequest,
},
};
@@ -385,4 +384,3 @@ mod tests {
// Check that we're not wasting fees unnecessarily
assert!(selection.cost <= selection.server_fee.value);
}
}

View File

@@ -68,7 +68,7 @@ impl LiquidChainService for MockLiquidChainService {
_script: &ElementsScript,
_retries: u64,
) -> Result<Vec<LBtcHistory>> {
Ok(self.get_history().into_iter().map(Into::into).collect())
Ok(self.get_history().into_iter().collect())
}
async fn get_script_history(&self, _script: &ElementsScript) -> Result<Vec<LBtcHistory>> {
@@ -156,14 +156,7 @@ impl BitcoinChainService for MockBitcoinChainService {
_script: &Script,
_retries: u64,
) -> Result<Vec<BtcHistory>> {
Ok(self
.history
.lock()
.unwrap()
.clone()
.into_iter()
.map(Into::into)
.collect())
Ok(self.history.lock().unwrap().clone().into_iter().collect())
}
async fn get_script_history(&self, _scripts: &Script) -> Result<Vec<BtcHistory>> {

View File

@@ -9,7 +9,7 @@ init:
rustup target add wasm32-unknown-unknown
clippy:
$(CLANG_PREFIX) cargo clippy --target=wasm32-unknown-unknown -- -D warnings
$(CLANG_PREFIX) cargo clippy --all-targets --target=wasm32-unknown-unknown -- -D warnings
build: build-bundle build-deno build-node build-web