Skip to content

Commit

Permalink
Merge #55: Add setup_device function
Browse files Browse the repository at this point in the history
9cc3d50 Add setup_device function (Yuki Kishimoto)

Pull request description:

ACKs for top commit:
  danielabrozzoni:
    ACK 9cc3d50

Tree-SHA512: f301333c47b60a3497251e4e6db2b59fad9a4b89e2f3bae831621360a97a59a95ba67d2aa6e5b5d6cf35c10fb06382eedd3053cced20e4e8c3d3aa0339edf771
  • Loading branch information
danielabrozzoni committed Nov 18, 2022
2 parents e67d884 + 9cc3d50 commit 13fbe0a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,25 @@ impl HWIClient {
})
}

/// Setup a device
pub fn setup_device(&self, label: Option<&str>, passphrase: Option<&str>) -> Result<(), Error> {
Python::with_gil(|py| {
let func_args = (
&self.hw_client,
label.unwrap_or(""),
passphrase.unwrap_or(""),
);
let output = self
.hwilib
.commands
.getattr(py, "setup_device")?
.call1(py, func_args)?;
let output = self.hwilib.json_dumps.call1(py, (output,))?;
let status: HWIStatus = deserialize_obj!(&output.to_string())?;
status.into()
})
}

/// Wipe a device
pub fn wipe_device(&self) -> Result<(), Error> {
Python::with_gil(|py| {
Expand Down
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,24 @@ mod tests {
break;
}
}

#[test]
#[serial]
fn test_get_version() {
HWIClient::get_version().unwrap();
}

#[test]
#[serial]
#[ignore]
// At the moment (hwi v2.1.1 and trezor-firmware core v2.5.2) work only with physical devices and NOT emulators!
fn test_setup_trezor_device() {
let client =
HWIClient::find_device(None, Some("trezor"), None, false, types::HWIChain::Test)
.unwrap();
client.setup_device(Some("My Label"), None).unwrap();
}

#[test]
#[serial]
#[ignore]
Expand All @@ -340,6 +352,7 @@ mod tests {
client.wipe_device().unwrap();
}
}

#[test]
#[serial]
#[ignore]
Expand Down

0 comments on commit 13fbe0a

Please sign in to comment.