Skip to content

Commit 3733731

Browse files
committed
Add wipe_device function
Also adds test for wipe_device
1 parent 3b9a10d commit 3733731

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,5 @@ jobs:
5353
run: rustup update
5454
- name: Test
5555
run: cargo test
56+
- name: Wipe
57+
run: cargo test test_wipe_device -- --ignored

src/interface.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,19 @@ impl HWIClient {
345345
status.into()
346346
})
347347
}
348+
349+
/// Wipe a device
350+
pub fn wipe_device(&self) -> Result<(), Error> {
351+
Python::with_gil(|py| {
352+
let func_args = (&self.hw_client,);
353+
let output = self
354+
.hwilib
355+
.commands
356+
.getattr(py, "toggle_passphrase")?
357+
.call1(py, func_args)?;
358+
let output = self.hwilib.json_dumps.call1(py, (output,))?;
359+
let status: HWIStatus = deserialize_obj!(&output.to_string())?;
360+
status.into()
361+
})
362+
}
348363
}

src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ mod tests {
212212
)
213213
.unwrap();
214214
}
215+
215216
#[test]
216217
#[serial]
217218
#[ignore]
@@ -243,4 +244,20 @@ mod tests {
243244
break;
244245
}
245246
}
247+
248+
#[test]
249+
#[serial]
250+
#[ignore]
251+
fn test_wipe_device() {
252+
let devices = HWIClient::enumerate().unwrap();
253+
let unsupported = ["ledger", "coldcard", "jade"];
254+
for device in devices {
255+
if unsupported.contains(&device.device_type.as_str()) {
256+
// These devices don't support wipe
257+
continue;
258+
}
259+
let client = HWIClient::get_client(&device, true, types::HWIChain::Test).unwrap();
260+
client.wipe_device().unwrap();
261+
}
262+
}
246263
}

0 commit comments

Comments
 (0)