From dd3e6d93dd9f655ac2fa36d49f48e53c9cc1eed5 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Tue, 28 May 2024 20:48:26 -0500 Subject: [PATCH] ci(speculos): set version to 0.8.3, fix clippy --- .github/workflows/main.yml | 13 ++----------- ci/Dockerfile.ledger | 2 +- clippy.toml | 2 +- src/lib.rs | 17 +++++++++-------- src/types.rs | 11 +++++++---- 5 files changed, 20 insertions(+), 25 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 61bbf4a..9a0f4d7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -59,17 +59,8 @@ jobs: ~/.cargo/git target key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }} - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Build and push - uses: docker/build-push-action@v3 - with: - context: ci/ - file: ci/Dockerfile.${{ matrix.emulator.name }} - tags: hwi/${{ matrix.emulator.name }}_emulator:latest - load: true - cache-from: type=gha - cache-to: type=gha + - name: Build simulator image + run: docker build -t hwi/${{ matrix.emulator.name }}_emulator:latest ./ci -f ci/Dockerfile.${{ matrix.emulator.name }} - name: Run simulator image run: docker run --name simulator --network=host hwi/${{ matrix.emulator.name }}_emulator & - name: Install Python diff --git a/ci/Dockerfile.ledger b/ci/Dockerfile.ledger index b593664..c73008f 100644 --- a/ci/Dockerfile.ledger +++ b/ci/Dockerfile.ledger @@ -1,4 +1,4 @@ -FROM ghcr.io/ledgerhq/speculos +FROM ghcr.io/ledgerhq/speculos:0.8.3 RUN apt-get update RUN apt-get install wget -y diff --git a/clippy.toml b/clippy.toml index 516ad1f..69478ce 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1 @@ -msrv="1.48.0" +msrv="1.63.0" diff --git a/src/lib.rs b/src/lib.rs index d986b1c..69c00cc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,6 +29,7 @@ #[cfg(test)] #[macro_use] extern crate serial_test; +extern crate core; pub use interface::HWIClient; @@ -58,7 +59,7 @@ mod tests { #[serial] fn test_enumerate() { let devices = HWIClient::enumerate().unwrap(); - assert!(devices.len() > 0); + assert!(!devices.is_empty()); } #[test] @@ -82,7 +83,7 @@ mod tests { .expect("No devices found. Either plug in a hardware wallet, or start a simulator.") .as_ref() .expect("Error when opening the first device"); - HWIClient::get_client(&device, true, TESTNET).unwrap() + HWIClient::get_client(device, true, TESTNET).unwrap() } #[test] @@ -118,8 +119,8 @@ mod tests { let client = get_first_device(); let account = Some(10); let descriptor = client.get_descriptors::(account).unwrap(); - assert!(descriptor.internal.len() > 0); - assert!(descriptor.receive.len() > 0); + assert!(!descriptor.internal.is_empty()); + assert!(!descriptor.receive.is_empty()); } #[test] @@ -140,8 +141,8 @@ mod tests { let descriptor = client .get_descriptors::>(account) .unwrap(); - assert!(descriptor.internal.len() > 0); - assert!(descriptor.receive.len() > 0); + assert!(!descriptor.internal.is_empty()); + assert!(!descriptor.receive.is_empty()); } #[test] @@ -198,7 +199,7 @@ mod tests { fn test_sign_tx() { let devices = HWIClient::enumerate().unwrap(); let device = devices.first().unwrap().as_ref().unwrap(); - let client = HWIClient::get_client(&device, true, TESTNET).unwrap(); + let client = HWIClient::get_client(device, true, TESTNET).unwrap(); let derivation_path = DerivationPath::from_str("m/44'/1'/0'/0/0").unwrap(); let address = client @@ -236,7 +237,7 @@ mod tests { input: vec![previous_txin], output: vec![TxOut { value: Amount::from_sat(50), - script_pubkey: script_pubkey, + script_pubkey, }], }, xpub: Default::default(), diff --git a/src/types.rs b/src/types.rs index 4f368ef..db8ef8e 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,4 +1,6 @@ +use core::fmt; use std::convert::TryFrom; +use std::fmt::{Display, Formatter}; use std::ops::Deref; use std::str::FromStr; @@ -260,9 +262,9 @@ where } } -impl ToString for HWIDeviceType { - fn to_string(&self) -> String { - match self { +impl Display for HWIDeviceType { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let name = match self { Self::Ledger => String::from("ledger"), Self::Trezor => String::from("trezor"), Self::BitBox01 => String::from("digitalbitbox"), @@ -271,7 +273,8 @@ impl ToString for HWIDeviceType { Self::Coldcard => String::from("coldcard"), Self::Jade => String::from("jade"), Self::Other(name) => name.to_string(), - } + }; + fmt::Display::fmt(&name, f) } }