Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CI, update py03 to latest version #101

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:

env:
CARGO_TERM_COLOR: always
OPENSSL_CONF: ci/openssl.cnf

jobs:
fmt:
Expand Down Expand Up @@ -36,7 +37,7 @@ jobs:
- name: Clippy
run: cargo clippy --all-features -- -D warnings
test-emulators:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
matrix:
rust:
Expand All @@ -58,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 }}
notmandatory marked this conversation as resolved.
Show resolved Hide resolved
- name: Run simulator image
run: docker run --name simulator --network=host hwi/${{ matrix.emulator.name }}_emulator &
- name: Install Python
Expand All @@ -89,7 +81,7 @@ jobs:
- name: Wipe
run: cargo test test_wipe_device -- --ignored
test-readme-examples:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: checkout
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ readme = "README.md"
bitcoin = { version = "0.31.0", features = ["serde", "base64"] }
serde = { version = "^1.0", features = ["derive"] }
serde_json = { version = "^1.0" }
pyo3 = { version = "0.15.1", features = ["auto-initialize"] }
pyo3 = { version = "0.21.2", features = ["auto-initialize"] }

miniscript = { version = "11.0", features = ["serde"], optional = true }

Expand Down
2 changes: 1 addition & 1 deletion ci/Dockerfile.ledger
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 14 additions & 0 deletions ci/openssl.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
openssl_conf = openssl_init

[openssl_init]
providers = provider_sect

[provider_sect]
default = default_sect
legacy = legacy_sect

[default_sect]
activate = 1

[legacy_sect]
activate = 1
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv="1.48.0"
msrv="1.63.0"
7 changes: 4 additions & 3 deletions src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ struct HWILib {
impl HWILib {
pub fn initialize() -> Result<Self, Error> {
Python::with_gil(|py| {
let commands: Py<PyModule> = PyModule::import(py, "hwilib.commands")?.into();
let json_dumps: Py<PyAny> = PyModule::import(py, "json")?.getattr("dumps")?.into();
let commands: Py<PyModule> = PyModule::import_bound(py, "hwilib.commands")?.into();
let json_dumps: Py<PyAny> =
PyModule::import_bound(py, "json")?.getattr("dumps")?.into();
Ok(HWILib {
commands,
json_dumps,
Expand Down Expand Up @@ -497,7 +498,7 @@ impl HWIClient {
pub fn get_version() -> Option<String> {
Python::with_gil(|py| {
Some(
PyModule::import(py, "hwilib")
PyModule::import_bound(py, "hwilib")
.ok()?
.getattr("__version__")
.expect("Should have a __version__")
Expand Down
17 changes: 9 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#[cfg(test)]
#[macro_use]
extern crate serial_test;
extern crate core;

pub use interface::HWIClient;

Expand Down Expand Up @@ -58,7 +59,7 @@ mod tests {
#[serial]
fn test_enumerate() {
let devices = HWIClient::enumerate().unwrap();
assert!(devices.len() > 0);
assert!(!devices.is_empty());
}

#[test]
Expand All @@ -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]
Expand Down Expand Up @@ -118,8 +119,8 @@ mod tests {
let client = get_first_device();
let account = Some(10);
let descriptor = client.get_descriptors::<String>(account).unwrap();
assert!(descriptor.internal.len() > 0);
assert!(descriptor.receive.len() > 0);
assert!(!descriptor.internal.is_empty());
assert!(!descriptor.receive.is_empty());
}

#[test]
Expand All @@ -140,8 +141,8 @@ mod tests {
let descriptor = client
.get_descriptors::<Descriptor<DescriptorPublicKey>>(account)
.unwrap();
assert!(descriptor.internal.len() > 0);
assert!(descriptor.receive.len() > 0);
assert!(!descriptor.internal.is_empty());
assert!(!descriptor.receive.is_empty());
}

#[test]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down
16 changes: 10 additions & 6 deletions src/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use core::fmt;
use std::convert::TryFrom;
use std::fmt::{Display, Formatter};
use std::ops::Deref;
use std::str::FromStr;

Expand All @@ -13,6 +15,7 @@ use serde::{Deserialize, Deserializer};

#[cfg(feature = "miniscript")]
use miniscript::{Descriptor, DescriptorPublicKey};
use pyo3::prelude::PyAnyMethods;

use crate::error::{Error, ErrorCode};

Expand Down Expand Up @@ -111,7 +114,7 @@ pub enum HWIAddressType {

impl IntoPy<PyObject> for HWIAddressType {
fn into_py(self, py: pyo3::Python) -> PyObject {
let addrtype = PyModule::import(py, "hwilib.common")
let addrtype = PyModule::import_bound(py, "hwilib.common")
.unwrap()
.getattr("AddressType")
.unwrap();
Expand All @@ -131,7 +134,7 @@ impl IntoPy<PyObject> for HWIChain {
fn into_py(self, py: pyo3::Python) -> PyObject {
use bitcoin::Network::*;

let chain = PyModule::import(py, "hwilib.common")
let chain = PyModule::import_bound(py, "hwilib.common")
.unwrap()
.getattr("Chain")
.unwrap();
Expand Down Expand Up @@ -260,9 +263,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"),
Expand All @@ -271,7 +274,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)
}
}

Expand Down
Loading