rust: async unit tests instead of block_on
What changed, and why it matters
This commit is a code-quality refactor for unit tests only. It introduces a small Rust helper macro called async_test::test that lets developers write async test functions directly, instead of manually wrapping async code in a block_on() call. The change touches many test files but does not alter any production firmware behavior, user-facing functionality, or security logic.
No security action required. This is a test-only refactoring change. Normal code-review approval is sufficient.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit adds a new proc-macro crate async_test that transforms an async fn into a standard #[test] fn by wrapping the body in util::bb02_async::block_on(…). It then applies this macro across 41 Rust test modules, removing explicit block_on() calls and converting sync test functions to async. Cargo manifests are updated to add the dev-dependency. No production code paths are modified; all changes are under #[cfg(test)] / mod tests or in test-only dev-dependencies.
Changed components
src/rust/async_test (new test-only proc-macro crate)src/rust/bitbox-platform-host (dev-dependency only)src/rust/bitbox02-rust (test modules only)Inspect captured patch +1128 / −1024
diff --git a/src/rust/Cargo.lock b/src/rust/Cargo.lock
index 0f1dafc..d926ca1 100644
--- a/src/rust/Cargo.lock
+++ b/src/rust/Cargo.lock
@@ -36,6 +36,15 @@ version = "4.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de"
+[[package]]
+name = "async_test"
+version = "0.1.0"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
[[package]]
name = "autocfg"
version = "1.0.1"
@@ -169,6 +178,7 @@ dependencies = [
name = "bitbox-platform-host"
version = "0.1.0"
dependencies = [
+ "async_test",
"bitbox-hal",
"bitcoin",
"hex_lit",
@@ -233,6 +243,7 @@ dependencies = [
name = "bitbox02-rust"
version = "0.1.0"
dependencies = [
+ "async_test",
"binascii",
"bip32-ed25519",
"bip39",
diff --git a/src/rust/Cargo.toml b/src/rust/Cargo.toml
index dec8477..eae5aeb 100644
--- a/src/rust/Cargo.toml
+++ b/src/rust/Cargo.toml
@@ -3,6 +3,7 @@
[workspace]
members = [
+ "async_test",
"bitbox-u2fhid",
"bitbox02-rust-c",
"bitbox02-rust",
diff --git a/src/rust/async_test/Cargo.toml b/src/rust/async_test/Cargo.toml
new file mode 100644
index 0000000..7972158
--- /dev/null
+++ b/src/rust/async_test/Cargo.toml
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: Apache-2.0
+
+[package]
+name = "async_test"
+version = "0.1.0"
+edition = "2024"
+description = "Drop-in replacement for tokio::test"
+license = "Apache-2.0"
+
+[lib]
+proc-macro = true
+
+[dependencies]
+proc-macro2 = "1"
+quote = "1"
+syn = { version = "2", features = ["full"] }
diff --git a/src/rust/async_test/src/lib.rs b/src/rust/async_test/src/lib.rs
new file mode 100644
index 0000000..04d5400
--- /dev/null
+++ b/src/rust/async_test/src/lib.rs
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: Apache-2.0
+
+use proc_macro::TokenStream;
+use quote::quote;
+use syn::parse_macro_input;
+use syn::spanned::Spanned;
+use syn::{ItemFn, ReturnType};
+
+#[proc_macro_attribute]
+pub fn test(attr: TokenStream, item: TokenStream) -> TokenStream {
+ if !attr.is_empty() {
+ return syn::Error::new(
+ proc_macro2::TokenStream::from(attr).span(),
+ "async_test::test does not accept arguments",
+ )
+ .to_compile_error()
+ .into();
+ }
+
+ let input = parse_macro_input!(item as ItemFn);
+ match expand(input) {
+ Ok(output) => output,
+ Err(err) => err.to_compile_error().into(),
+ }
+}
+
+fn expand(input: ItemFn) -> Result<TokenStream, syn::Error> {
+ let attrs = input.attrs;
+ let vis = input.vis;
+ let block = input.block;
+ let sig = input.sig;
+
+ if sig.constness.is_some() {
+ return Err(syn::Error::new_spanned(
+ sig.constness,
+ "async_test::test only supports non-const async fn",
+ ));
+ }
+ if sig.unsafety.is_some() {
+ return Err(syn::Error::new_spanned(
+ sig.unsafety,
+ "async_test::test only supports safe async fn",
+ ));
+ }
+ if sig.abi.is_some() {
+ return Err(syn::Error::new_spanned(
+ &sig.abi,
+ "async_test::test does not support extern functions",
+ ));
+ }
+ if sig.asyncness.is_none() {
+ return Err(syn::Error::new_spanned(
+ sig.fn_token,
+ "async_test::test requires async fn",
+ ));
+ }
+ if !sig.generics.params.is_empty() || sig.generics.where_clause.is_some() {
+ return Err(syn::Error::new_spanned(
+ &sig.generics,
+ "async_test::test does not support generics",
+ ));
+ }
+ if !sig.inputs.is_empty() {
+ return Err(syn::Error::new_spanned(
+ &sig.inputs,
+ "async_test::test does not support function arguments",
+ ));
+ }
+ if !matches!(sig.output, ReturnType::Default) {
+ return Err(syn::Error::new_spanned(
+ &sig.output,
+ "async_test::test does not support explicit return types",
+ ));
+ }
+
+ let ident = sig.ident;
+
+ Ok(quote! {
+ #(#attrs)*
+ #[test]
+ #vis fn #ident() {
+ ::util::bb02_async::block_on(async #block)
+ }
+ }
+ .into())
+}
diff --git a/src/rust/bitbox-platform-host/Cargo.toml b/src/rust/bitbox-platform-host/Cargo.toml
index 0c59eae..324de33 100644
--- a/src/rust/bitbox-platform-host/Cargo.toml
+++ b/src/rust/bitbox-platform-host/Cargo.toml
@@ -17,4 +17,5 @@ zeroize = { workspace = true }
app-u2f = ["bitbox-hal/app-u2f"]
[dev-dependencies]
+async_test = { path = "../async_test" }
util = { path = "../util", features = ["testing"] }
diff --git a/src/rust/bitbox-platform-host/src/sd.rs b/src/rust/bitbox-platform-host/src/sd.rs
index 57c83b0..fc3def9 100644
--- a/src/rust/bitbox-platform-host/src/sd.rs
+++ b/src/rust/bitbox-platform-host/src/sd.rs
@@ -66,37 +66,40 @@ impl bitbox_hal::Sd for FakeSd {
mod tests {
use super::*;
use bitbox_hal::Sd;
- use util::bb02_async::block_on;
// Quick check if our mock FakeSd implementation makes sense.
- #[test]
- fn test_sd_list_write_read_erase() {
+ #[async_test::test]
+ async fn test_sd_list_write_read_erase() {
let mut sd = FakeSd::new();
- assert_eq!(block_on(sd.list_subdir(None)), Ok(vec![]));
- assert_eq!(block_on(sd.list_subdir(Some("dir1"))), Ok(vec![]));
+ assert_eq!(sd.list_subdir(None).await, Ok(vec![]));
+ assert_eq!(sd.list_subdir(Some("dir1")).await, Ok(vec![]));
- assert!(block_on(sd.load_bin("file1.txt", "dir1")).is_err());
- assert!(block_on(sd.write_bin("file1.txt", "dir1", b"data")).is_ok());
- assert_eq!(block_on(sd.list_subdir(None)), Ok(vec!["dir1".into()]));
+ assert!(sd.load_bin("file1.txt", "dir1").await.is_err());
+ assert!(sd.write_bin("file1.txt", "dir1", b"data").await.is_ok());
+ assert_eq!(sd.list_subdir(None).await, Ok(vec!["dir1".into()]));
assert_eq!(
- block_on(sd.list_subdir(Some("dir1"))),
+ sd.list_subdir(Some("dir1")).await,
Ok(vec!["file1.txt".into()])
);
assert_eq!(
- block_on(sd.load_bin("file1.txt", "dir1"))
- .unwrap()
- .as_slice(),
+ sd.load_bin("file1.txt", "dir1").await.unwrap().as_slice(),
b"data"
);
- assert!(block_on(sd.write_bin("file1.txt", "dir1", b"replaced data")).is_ok());
+ assert!(
+ sd.write_bin("file1.txt", "dir1", b"replaced data")
+ .await
+ .is_ok()
+ );
assert_eq!(
- block_on(sd.load_bin("file1.txt", "dir1"))
- .unwrap()
- .as_slice(),
+ sd.load_bin("file1.txt", "dir1").await.unwrap().as_slice(),
b"replaced data"
);
- assert!(block_on(sd.erase_file_in_subdir("doesnt-exist.txt", "dir1")).is_err());
- assert!(block_on(sd.erase_file_in_subdir("file1.txt", "dir1")).is_ok());
- assert_eq!(block_on(sd.list_subdir(Some("dir1"))), Ok(vec![]));
+ assert!(
+ sd.erase_file_in_subdir("doesnt-exist.txt", "dir1")
+ .await
+ .is_err()
+ );
+ assert!(sd.erase_file_in_subdir("file1.txt", "dir1").await.is_ok());
+ assert_eq!(sd.list_subdir(Some("dir1")).await, Ok(vec![]));
}
}
diff --git a/src/rust/bitbox02-rust/Cargo.toml b/src/rust/bitbox02-rust/Cargo.toml
index f7da181..56c48c4 100644
--- a/src/rust/bitbox02-rust/Cargo.toml
+++ b/src/rust/bitbox02-rust/Cargo.toml
@@ -118,8 +118,10 @@ simulator-graphical = [
firmware = []
[dev-dependencies]
+async_test = { path = "../async_test" }
serde = { workspace = true }
serde_json = { workspace = true }
+util = { path = "../util", features = ["testing"] }
[build-dependencies]
serde_json = { workspace = true }
diff --git a/src/rust/bitbox02-rust/src/backup.rs b/src/rust/bitbox02-rust/src/backup.rs
index ab1540b..28533e4 100644
--- a/src/rust/bitbox02-rust/src/backup.rs
+++ b/src/rust/bitbox02-rust/src/backup.rs
@@ -280,8 +280,6 @@ mod tests {
use crate::hal::testing::TestingHal;
use core::convert::TryInto;
- use util::bb02_async::block_on;
-
#[test]
fn test_id() {
// Seeds of different lengths (16, 24, 32 bytes)
@@ -300,27 +298,19 @@ mod tests {
assert_eq!(id(&seed_32), expected_output_32);
}
- fn _test_create_load(seed: &[u8]) {
+ async fn _test_create_load(seed: &[u8]) {
let mut mock_hal = TestingHal::new();
let timestamp = 1601281809;
let birthdate = timestamp - 32400;
assert!(
- block_on(create(
- &mut mock_hal,
- seed,
- "test name",
- timestamp,
- birthdate
- ))
- .is_ok()
+ create(&mut mock_hal, seed, "test name", timestamp, birthdate)
+ .await
+ .is_ok()
);
let dir = id(seed);
+ assert_eq!(mock_hal.sd.list_subdir(None).await, Ok(vec![dir.clone()]));
assert_eq!(
- block_on(mock_hal.sd.list_subdir(None)),
- Ok(vec![dir.clone()])
- );
- assert_eq!(
- block_on(mock_hal.sd.list_subdir(Some(&dir))),
+ mock_hal.sd.list_subdir(Some(&dir)).await,
Ok(vec![
"backup_Mon_2020-09-28T08-30-09Z_0.bin".into(),
"backup_Mon_2020-09-28T08-30-09Z_1.bin".into(),
@@ -330,17 +320,12 @@ mod tests {
// Recreating using same timestamp is not allowed and doesn't change the backups.
assert!(
- block_on(create(
- &mut mock_hal,
- seed,
- "new name",
- timestamp,
- birthdate
- ))
- .is_err()
+ create(&mut mock_hal, seed, "new name", timestamp, birthdate)
+ .await
+ .is_err()
);
assert_eq!(
- block_on(mock_hal.sd.list_subdir(Some(&dir))),
+ mock_hal.sd.list_subdir(Some(&dir)).await,
Ok(vec![
"backup_Mon_2020-09-28T08-30-09Z_0.bin".into(),
"backup_Mon_2020-09-28T08-30-09Z_1.bin".into(),
@@ -348,14 +333,12 @@ mod tests {
])
);
- let contents: [zeroize::Zeroizing<Vec<u8>>; 3] =
- block_on(mock_hal.sd.list_subdir(Some(&dir)))
- .unwrap()
- .iter()
- .map(|file| block_on(mock_hal.sd.load_bin(file, &dir)).unwrap())
- .collect::<Vec<_>>()
- .try_into()
- .unwrap();
+ let files = mock_hal.sd.list_subdir(Some(&dir)).await.unwrap();
+ let mut contents = alloc::vec::Vec::with_capacity(files.len());
+ for file in files.iter() {
+ contents.push(mock_hal.sd.load_bin(file, &dir).await.unwrap());
+ }
+ let contents: [zeroize::Zeroizing<Vec<u8>>; 3] = contents.try_into().unwrap();
assert!(
contents[0].as_slice() == contents[1].as_slice()
&& contents[0].as_slice() == contents[2].as_slice()
@@ -363,17 +346,12 @@ mod tests {
// Recreating the backup removes the previous files.
assert!(
- block_on(create(
- &mut mock_hal,
- seed,
- "new name",
- timestamp + 1,
- birthdate
- ))
- .is_ok()
+ create(&mut mock_hal, seed, "new name", timestamp + 1, birthdate)
+ .await
+ .is_ok()
);
assert_eq!(
- block_on(mock_hal.sd.list_subdir(Some(&dir))),
+ mock_hal.sd.list_subdir(Some(&dir)).await,
Ok(vec![
"backup_Mon_2020-09-28T08-30-10Z_0.bin".into(),
"backup_Mon_2020-09-28T08-30-10Z_1.bin".into(),
@@ -381,19 +359,19 @@ mod tests {
])
);
- let (backup_data, metadata) = block_on(load(&mut mock_hal, &dir)).unwrap();
+ let (backup_data, metadata) = load(&mut mock_hal, &dir).await.unwrap();
assert_eq!(backup_data.get_seed(), seed);
assert_eq!(backup_data.0.birthdate, birthdate);
assert_eq!(metadata.name.as_str(), "new name");
assert_eq!(metadata.timestamp, timestamp + 1);
}
- #[test]
- fn test_create_load() {
+ #[async_test::test]
+ async fn test_create_load() {
// Test for seeds of different size.
- _test_create_load(&b"\x52\x20\xa4\xe9\xce\xea\xc6\x80\x5d\xf2\x36\x09\xf6\xb4\x78\xbb\x28\xca\x69\xb5\x16\x95\xed\x7c\x03\xbf\x74\x3a\xa5\xde\xe3\x7e"[..]);
- _test_create_load(&b"\x52\x20\xa4\xe9\xce\xea\xc6\x80\x5d\xf2\x36\x09\xf6\xb4\x78\xbb\x28\xca\x69\xb5\x16\x95\xed\x7c"[..]);
- _test_create_load(&b"\x52\x20\xa4\xe9\xce\xea\xc6\x80\x5d\xf2\x36\x09"[..]);
+ _test_create_load(&b"\x52\x20\xa4\xe9\xce\xea\xc6\x80\x5d\xf2\x36\x09\xf6\xb4\x78\xbb\x28\xca\x69\xb5\x16\x95\xed\x7c\x03\xbf\x74\x3a\xa5\xde\xe3\x7e"[..]).await;
+ _test_create_load(&b"\x52\x20\xa4\xe9\xce\xea\xc6\x80\x5d\xf2\x36\x09\xf6\xb4\x78\xbb\x28\xca\x69\xb5\x16\x95\xed\x7c"[..]).await;
+ _test_create_load(&b"\x52\x20\xa4\xe9\xce\xea\xc6\x80\x5d\xf2\x36\x09"[..]).await;
}
#[test]
diff --git a/src/rust/bitbox02-rust/src/bip39.rs b/src/rust/bitbox02-rust/src/bip39.rs
index 59851bb..6998cc1 100644
--- a/src/rust/bitbox02-rust/src/bip39.rs
+++ b/src/rust/bitbox02-rust/src/bip39.rs
@@ -72,7 +72,6 @@ pub extern "C" fn rust_get_bip39_word(idx: u16, mut out: util::bytes::BytesMut)
#[cfg(test)]
mod tests {
use super::*;
- use util::bb02_async::block_on;
#[test]
fn test_rust_get_bip39_word() {
@@ -181,8 +180,8 @@ mod tests {
);
}
- #[test]
- fn test_derive_bip39_seed() {
+ #[async_test::test]
+ async fn test_derive_bip39_seed() {
struct Test {
seed: &'static str,
passphrase: &'static str,
@@ -235,7 +234,7 @@ mod tests {
for test in tests {
let seed = hex::decode(test.seed).unwrap();
let (bip39_seed, root_fingerprint) =
- block_on(derive_seed(&seed, test.passphrase, async || {}));
+ derive_seed(&seed, test.passphrase, async || {}).await;
assert_eq!(hex::encode(bip39_seed).as_str(), test.expected_bip39_seed);
assert_eq!(
hex::encode(root_fingerprint).as_str(),
diff --git a/src/rust/bitbox02-rust/src/hal/testing/ui.rs b/src/rust/bitbox02-rust/src/hal/testing/ui.rs
index 716bb92..7b4733c 100644
--- a/src/rust/bitbox02-rust/src/hal/testing/ui.rs
+++ b/src/rust/bitbox02-rust/src/hal/testing/ui.rs
@@ -423,24 +423,22 @@ mod tests {
use super::*;
use crate::hal::Ui;
- use util::bb02_async::block_on;
-
- #[test]
- fn test_quiz_choices_queue() {
+ #[async_test::test]
+ async fn test_quiz_choices_queue() {
let mut ui = TestingUi::new();
ui.push_quiz_choice(1);
assert!(matches!(
- block_on(ui.quiz_mnemonic_word(&["a", "b", "c"], "01")),
+ ui.quiz_mnemonic_word(&["a", "b", "c"], "01").await,
Ok(1)
));
}
- #[test]
- fn test_quiz_choice_records_screen() {
+ #[async_test::test]
+ async fn test_quiz_choice_records_screen() {
let mut ui = TestingUi::new();
ui.push_quiz_choice(2);
assert!(matches!(
- block_on(ui.quiz_mnemonic_word(&["x", "bar", "y"], "02")),
+ ui.quiz_mnemonic_word(&["x", "bar", "y"], "02").await,
Ok(2)
));
assert_eq!(
@@ -453,18 +451,18 @@ mod tests {
);
}
- #[test]
+ #[async_test::test]
#[should_panic(expected = "quiz choice 9 out of bounds for 1 choices")]
- fn test_quiz_choice_out_of_bounds_panics() {
+ async fn test_quiz_choice_out_of_bounds_panics() {
let mut ui = TestingUi::new();
ui.push_quiz_choice(9);
- let _ = block_on(ui.quiz_mnemonic_word(&["a"], "01"));
+ let _ = ui.quiz_mnemonic_word(&["a"], "01").await;
}
- #[test]
+ #[async_test::test]
#[should_panic(expected = "quiz_mnemonic_word called without queued choice")]
- fn test_quiz_choice_without_state_panics() {
+ async fn test_quiz_choice_without_state_panics() {
let mut ui = TestingUi::new();
- let _ = block_on(ui.quiz_mnemonic_word(&["a"], "01"));
+ let _ = ui.quiz_mnemonic_word(&["a"], "01").await;
}
}
diff --git a/src/rust/bitbox02-rust/src/hww.rs b/src/rust/bitbox02-rust/src/hww.rs
index f40f1e2..6f0009b 100644
--- a/src/rust/bitbox02-rust/src/hww.rs
+++ b/src/rust/bitbox02-rust/src/hww.rs
@@ -216,11 +216,11 @@ mod tests {
}
/// Can't unlock when the device is not initialized yet (not seeded).
- #[test]
- fn test_cant_unlock() {
+ #[async_test::test]
+ async fn test_cant_unlock() {
mock_memory();
assert_eq!(
- block_on(process_packet(&mut TestingHal::new(), vec![OP_UNLOCK])),
+ process_packet(&mut TestingHal::new(), vec![OP_UNLOCK]).await,
[OP_STATUS_FAILURE_UNINITIALIZED].to_vec()
);
}
@@ -352,8 +352,8 @@ mod tests {
}
/// Can initiate noise and send the Reboot protobuf request when the device is initialized.
- #[test]
- fn test_reboot_when_initialized() {
+ #[async_test::test]
+ async fn test_reboot_when_initialized() {
mock_memory();
let mut make_request = init_noise();
@@ -438,7 +438,7 @@ mod tests {
.ui
.set_enter_string(Box::new(|_params| Ok("password".into())));
assert_eq!(
- block_on(process_packet(&mut mock_hal, vec![OP_UNLOCK])),
+ process_packet(&mut mock_hal, vec![OP_UNLOCK]).await,
[OP_STATUS_SUCCESS].to_vec()
);
assert!(!crate::keystore::is_locked());
diff --git a/src/rust/bitbox02-rust/src/hww/api/backup.rs b/src/rust/bitbox02-rust/src/hww/api/backup.rs
index 66a5481..db4c43e 100644
--- a/src/rust/bitbox02-rust/src/hww/api/backup.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/backup.rs
@@ -156,11 +156,10 @@ mod tests {
use crate::keystore::testing::{mock_unlocked, mock_unlocked_using_mnemonic};
use alloc::boxed::Box;
use bitbox02::testing::mock_memory;
- use util::bb02_async::block_on;
/// Test backup creation on a uninitialized keystore.
- #[test]
- pub fn test_create_uninitialized() {
+ #[async_test::test]
+ pub async fn test_create_uninitialized() {
const EXPECTED_TIMESTMAP: u32 = 1601281809;
// All good.
@@ -171,13 +170,14 @@ mod tests {
mock_hal.sd.inserted = Some(true);
mock_hal.securechip.event_counter_reset();
assert_eq!(
- block_on(create(
+ create(
&mut mock_hal,
&pb::CreateBackupRequest {
timestamp: EXPECTED_TIMESTMAP,
timezone_offset: 18000,
}
- )),
+ )
+ .await,
Ok(Response::Success(pb::Success {}))
);
assert_eq!(mock_hal.securechip.get_event_counter(), 1);
@@ -198,10 +198,7 @@ mod tests {
);
assert_eq!(
- block_on(check(
- &mut mock_hal,
- &pb::CheckBackupRequest { silent: true }
- )),
+ check(&mut mock_hal, &pb::CheckBackupRequest { silent: true }).await,
Ok(Response::CheckBackup(pb::CheckBackupResponse {
id: "41233dfbad010723dbbb93514b7b81016b73f8aa35c5148e1b478f60d5750dce".into()
}))
@@ -209,19 +206,19 @@ mod tests {
}
/// Test backup creation on a initialized keystore. The sdcard does not contain the backup yet.
- #[test]
- pub fn test_create_initialized_new() {
+ #[async_test::test]
+ pub async fn test_create_initialized_new() {
const TIMESTMAP: u32 = 1601281809;
mock_memory();
+ let mut password_entered: bool = false;
let mut mock_hal = TestingHal::new();
let seed = hex::decode("cb33c20cea62a5c277527e2002da82e6e2b37450a755143a540a54cea8da9044")
.unwrap();
crate::keystore::encrypt_and_store_seed(&mut mock_hal, &seed, "password").unwrap();
mock_hal.memory.set_initialized().unwrap();
- let mut password_entered: bool = false;
mock_hal.sd.inserted = Some(true);
mock_hal.ui.set_enter_string(Box::new(|_params| {
password_entered = true;
@@ -229,13 +226,14 @@ mod tests {
}));
mock_hal.securechip.event_counter_reset();
assert_eq!(
- block_on(create(
+ create(
&mut mock_hal,
&pb::CreateBackupRequest {
timestamp: TIMESTMAP,
timezone_offset: 18000,
}
- )),
+ )
+ .await,
Ok(Response::Success(pb::Success {}))
);
assert_eq!(mock_hal.securechip.get_event_counter(), 4);
@@ -256,10 +254,7 @@ mod tests {
mock_hal.ui.remove_enter_string(); // no more password entry needed
assert_eq!(
- block_on(check(
- &mut mock_hal,
- &pb::CheckBackupRequest { silent: true }
- )),
+ check(&mut mock_hal, &pb::CheckBackupRequest { silent: true }).await,
Ok(Response::CheckBackup(pb::CheckBackupResponse {
id: backup::id(&seed),
}))
@@ -271,8 +266,8 @@ mod tests {
/// Use backup file fixtures generated using firmware v9.12.0 and perform tests on it. This
/// should catch regressions when changing backup loading/verification in the firmware code.
- #[test]
- fn test_fixture() {
+ #[async_test::test]
+ async fn test_fixture() {
const EXPECTED_ID: &str =
"577782fdfffbe314b23acaeefc39ad5e8641fba7e7dbe418a35956a879a67dd2";
mock_memory();
@@ -288,19 +283,19 @@ mod tests {
// above seed.
let backup_fixture_v9_12_0: Vec<u8> = hex::decode("0a6c0a6a0a2017834e53e17370800c0bc49b49ef3f1309df104d7239db5bbd093c90eefc995112110891bec6fb0512094d7920426974426f782233081012208af64d31126a39b98f59708a3a463e5b000000000000000000000000000000001891bec6fb05220776392e31332e30").unwrap();
for i in 0..3 {
- block_on(mock_hal.sd.write_bin(
- &format!("backup_Mon_2020-09-28T08-30-09Z_{}.bin", i),
- EXPECTED_ID,
- &backup_fixture_v9_12_0,
- ))
- .unwrap();
+ mock_hal
+ .sd
+ .write_bin(
+ &format!("backup_Mon_2020-09-28T08-30-09Z_{}.bin", i),
+ EXPECTED_ID,
+ &backup_fixture_v9_12_0,
+ )
+ .await
+ .unwrap();
}
// Check that the loaded seed matches the backup.
assert_eq!(
- block_on(check(
- &mut mock_hal,
- &pb::CheckBackupRequest { silent: false }
- )),
+ check(&mut mock_hal, &pb::CheckBackupRequest { silent: false }).await,
Ok(Response::CheckBackup(pb::CheckBackupResponse {
id: EXPECTED_ID.into()
}))
@@ -326,8 +321,8 @@ mod tests {
);
}
- #[test]
- pub fn test_list() {
+ #[async_test::test]
+ pub async fn test_list() {
const EXPECTED_TIMESTAMP: u32 = 1601281809;
const DEVICE_NAME_1: &str = "test device name";
@@ -338,7 +333,7 @@ mod tests {
// No backups yet.
assert_eq!(
- block_on(list(&mut mock_hal)),
+ list(&mut mock_hal).await,
Ok(Response::ListBackups(pb::ListBackupsResponse {
info: vec![]
}))
@@ -353,18 +348,19 @@ mod tests {
mock_hal.memory.set_device_name(DEVICE_NAME_1).unwrap();
assert!(
- block_on(create(
+ create(
&mut mock_hal,
&pb::CreateBackupRequest {
timestamp: EXPECTED_TIMESTAMP,
timezone_offset: 18000,
}
- ))
+ )
+ .await
.is_ok()
);
assert_eq!(
- block_on(list(&mut mock_hal)),
+ list(&mut mock_hal).await,
Ok(Response::ListBackups(pb::ListBackupsResponse {
info: vec![pb::BackupInfo {
id: "41233dfbad010723dbbb93514b7b81016b73f8aa35c5148e1b478f60d5750dce".into(),
@@ -388,18 +384,19 @@ mod tests {
mock_hal.memory.set_device_name(DEVICE_NAME_2).unwrap();
assert!(
- block_on(create(
+ create(
&mut mock_hal,
&pb::CreateBackupRequest {
timestamp: EXPECTED_TIMESTAMP,
timezone_offset: 18000,
}
- ))
+ )
+ .await
.is_ok()
);
assert_eq!(
- block_on(list(&mut mock_hal)),
+ list(&mut mock_hal).await,
Ok(Response::ListBackups(pb::ListBackupsResponse {
info: vec![
pb::BackupInfo {
diff --git a/src/rust/bitbox02-rust/src/hww/api/bitcoin.rs b/src/rust/bitbox02-rust/src/hww/api/bitcoin.rs
index 0722b3c..4da97e0 100644
--- a/src/rust/bitbox02-rust/src/hww/api/bitcoin.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/bitcoin.rs
@@ -329,10 +329,9 @@ mod tests {
use alloc::boxed::Box;
use alloc::vec::Vec;
use pb::btc_script_config::multisig::ScriptType as MultisigScriptType;
- use util::bb02_async::block_on;
use util::bip32::HARDENED;
- #[test]
- pub fn test_xpub() {
+ #[async_test::test]
+ pub async fn test_xpub() {
struct Test<'a> {
mnemonic: &'a str,
coin: BtcCoin,
@@ -477,7 +476,7 @@ mod tests {
};
assert_eq!(
- block_on(process_pub(&mut TestingHal::new(), &req)),
+ process_pub(&mut TestingHal::new(), &req).await,
Ok(Response::Pub(pb::PubResponse {
r#pub: test.expected_xpub.into(),
})),
@@ -489,7 +488,7 @@ mod tests {
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process_pub(&mut mock_hal, &req)),
+ process_pub(&mut mock_hal, &req).await,
Ok(Response::Pub(pb::PubResponse {
r#pub: test.expected_xpub.into(),
})),
@@ -510,12 +509,12 @@ mod tests {
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process_pub(&mut mock_hal, &pb::BtcPubRequest {
+ process_pub(&mut mock_hal, &pb::BtcPubRequest {
coin: BtcCoin::Btc as _,
keypath: [1 + HARDENED, 2 + HARDENED, 3 + HARDENED, 4].to_vec(),
display: false,
output: Some(Output::XpubType(XPubType::Xpub as _)),
- })),
+ }).await,
Ok(Response::Pub(pb::PubResponse {
r#pub: "xpub6DdW7n2P4Ht8m9DNumbzVKPU4yXoBMR9mm39q6tGp8PHGgNTJWL3fBdoUS4E8tP9XmyK4F85ApxLEBTB6f3fJf3Ujk5PaqssRuTLsRVTn6E".into(),
}))
@@ -538,12 +537,12 @@ mod tests {
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process_pub(&mut mock_hal, &pb::BtcPubRequest {
+ process_pub(&mut mock_hal, &pb::BtcPubRequest {
coin: BtcCoin::Btc as _,
keypath: [1 + HARDENED, 2 + HARDENED, 3 + HARDENED, 4].to_vec(),
display: true,
output: Some(Output::XpubType(XPubType::Xpub as _)),
- })),
+ }).await,
Ok(Response::Pub(pb::PubResponse {
r#pub: "xpub6DdW7n2P4Ht8m9DNumbzVKPU4yXoBMR9mm39q6tGp8PHGgNTJWL3fBdoUS4E8tP9XmyK4F85ApxLEBTB6f3fJf3Ujk5PaqssRuTLsRVTn6E".into(),
}))
@@ -574,15 +573,23 @@ mod tests {
// -- Wrong coin: MIN-1
let mut req_invalid = req.clone();
req_invalid.coin = BtcCoin::Btc as i32 - 1;
- assert!(block_on(process_pub(&mut TestingHal::new(), &req_invalid)).is_err());
+ assert!(
+ process_pub(&mut TestingHal::new(), &req_invalid)
+ .await
+ .is_err()
+ );
// -- Wrong coin: MAX + 1
let mut req_invalid = req.clone();
req_invalid.coin = BtcCoin::Rbtc as i32 + 1;
- assert!(block_on(process_pub(&mut TestingHal::new(), &req_invalid)).is_err());
+ assert!(
+ process_pub(&mut TestingHal::new(), &req_invalid)
+ .await
+ .is_err()
+ );
}
- #[test]
- pub fn test_address_simple() {
+ #[async_test::test]
+ pub async fn test_address_simple() {
struct Test<'a> {
mnemonic: &'a str,
coin: BtcCoin,
@@ -798,7 +805,7 @@ mod tests {
// Without display.
mock_unlocked_using_mnemonic(test.mnemonic, "");
assert_eq!(
- block_on(process_pub(&mut TestingHal::new(), &req)),
+ process_pub(&mut TestingHal::new(), &req).await,
Ok(Response::Pub(pb::PubResponse {
r#pub: test.expected_address.into(),
})),
@@ -809,7 +816,7 @@ mod tests {
mock_unlocked_using_mnemonic(test.mnemonic, "");
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process_pub(&mut mock_hal, &req)),
+ process_pub(&mut mock_hal, &req).await,
Ok(Response::Pub(pb::PubResponse {
r#pub: test.expected_address.into()
})),
@@ -835,22 +842,34 @@ mod tests {
config: Some(Config::SimpleType(SimpleType::P2wpkhP2sh as _)),
})),
};
- assert!(block_on(process_pub(&mut TestingHal::new(), &req)).is_ok());
+ assert!(process_pub(&mut TestingHal::new(), &req).await.is_ok());
// -- Wrong coin: MIN-1
let mut req_invalid = req.clone();
req_invalid.coin = BtcCoin::Btc as i32 - 1;
- assert!(block_on(process_pub(&mut TestingHal::new(), &req_invalid)).is_err());
+ assert!(
+ process_pub(&mut TestingHal::new(), &req_invalid)
+ .await
+ .is_err()
+ );
// -- Wrong coin: MAX + 1
let mut req_invalid = req.clone();
req_invalid.coin = BtcCoin::Tltc as i32 + 1;
- assert!(block_on(process_pub(&mut TestingHal::new(), &req_invalid)).is_err());
+ assert!(
+ process_pub(&mut TestingHal::new(), &req_invalid)
+ .await
+ .is_err()
+ );
// -- Wrong keypath
let mut req_invalid = req.clone();
req_invalid.keypath = [49 + HARDENED, 0 + HARDENED, 1 + HARDENED, 1, 10000].to_vec();
- assert!(block_on(process_pub(&mut TestingHal::new(), &req_invalid)).is_err());
+ assert!(
+ process_pub(&mut TestingHal::new(), &req_invalid)
+ .await
+ .is_err()
+ );
// -- No taproot in Litecoin
assert!(
- block_on(process_pub(
+ process_pub(
&mut TestingHal::new(),
&pb::BtcPubRequest {
coin: BtcCoin::Ltc as _,
@@ -860,13 +879,14 @@ mod tests {
config: Some(Config::SimpleType(SimpleType::P2tr as _)),
})),
}
- ))
+ )
+ .await
.is_err()
);
}
- #[test]
- pub fn test_address_multisig() {
+ #[async_test::test]
+ pub async fn test_address_multisig() {
static mut UI_COUNTER: u32 = 0;
struct Test<'a> {
coin: BtcCoin,
@@ -1042,7 +1062,7 @@ mod tests {
})),
};
assert_eq!(
- block_on(process_pub(&mut mock_hal, &req)),
+ process_pub(&mut mock_hal, &req).await,
Ok(Response::Pub(pb::PubResponse {
r#pub: test.expected_address.into(),
})),
@@ -1070,8 +1090,8 @@ mod tests {
}
}
- #[test]
- fn test_address_policy() {
+ #[async_test::test]
+ async fn test_address_policy() {
mock_unlocked_using_mnemonic(
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
"",
@@ -1212,7 +1232,7 @@ mod tests {
})),
};
assert_eq!(
- block_on(process_pub(&mut mock_hal, &req)),
+ process_pub(&mut mock_hal, &req).await,
Ok(Response::Pub(pb::PubResponse {
r#pub: test.expected_address.into(),
})),
diff --git a/src/rust/bitbox02-rust/src/hww/api/bitcoin/signmsg.rs b/src/rust/bitbox02-rust/src/hww/api/bitcoin/signmsg.rs
index 2b85a8c..c5d83c2 100644
--- a/src/rust/bitbox02-rust/src/hww/api/bitcoin/signmsg.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/bitcoin/signmsg.rs
@@ -132,13 +132,12 @@ mod tests {
use crate::hal::testing::ui::Screen;
use crate::keystore::testing::mock_unlocked;
use alloc::boxed::Box;
- use util::bb02_async::block_on;
use util::bip32::HARDENED;
const MESSAGE: &str = "message";
- #[test]
- pub fn test_p2wpkh() {
+ #[async_test::test]
+ pub async fn test_p2wpkh() {
let request = pb::BtcSignMessageRequest {
coin: BtcCoin::Btc as _,
script_config: Some(pb::BtcScriptConfigWithKeypath {
@@ -154,7 +153,7 @@ mod tests {
mock_unlocked();
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(&mut mock_hal, &request)),
+ process(&mut mock_hal, &request).await,
Ok(Response::SignMessage(pb::BtcSignMessageResponse {
signature: b"\x0f\x1d\x54\x2a\x9e\x2f\x37\x4e\xfe\xd4\x57\x8c\xaa\x84\x72\xd1\xc3\x12\x68\xfb\x89\x2d\x39\xa6\x15\x44\x59\x18\x5b\x2d\x35\x4d\x3b\x2b\xff\xf0\xe1\x61\x5c\x77\x25\x73\x4f\x43\x13\x4a\xb4\x51\x6b\x7e\x7c\xb3\x9d\x2d\xba\xaa\x5f\x4e\x8b\x8a\xff\x9f\x97\xd0\x00".to_vec(),
}))
@@ -181,8 +180,8 @@ mod tests {
);
}
- #[test]
- pub fn test_p2wpkh_testnet() {
+ #[async_test::test]
+ pub async fn test_p2wpkh_testnet() {
let request = pb::BtcSignMessageRequest {
coin: BtcCoin::Tbtc as _,
script_config: Some(pb::BtcScriptConfigWithKeypath {
@@ -197,7 +196,7 @@ mod tests {
mock_unlocked();
let mut mock_hal = TestingHal::new();
- assert!(block_on(process(&mut mock_hal, &request)).is_ok());
+ assert!(process(&mut mock_hal, &request).await.is_ok());
assert_eq!(
mock_hal.ui.screens,
vec![
@@ -220,8 +219,8 @@ mod tests {
);
}
- #[test]
- pub fn test_p2wpkh_p2sh() {
+ #[async_test::test]
+ pub async fn test_p2wpkh_p2sh() {
let request = pb::BtcSignMessageRequest {
coin: BtcCoin::Btc as _,
script_config: Some(pb::BtcScriptConfigWithKeypath {
@@ -237,7 +236,7 @@ mod tests {
mock_unlocked();
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(&mut mock_hal, &request)),
+ process(&mut mock_hal, &request).await,
Ok(Response::SignMessage(pb::BtcSignMessageResponse {
signature: b"\x87\x19\x05\x3c\x29\xff\xcf\x54\x31\x40\x69\x86\x75\x8a\xc8\xed\x80\x1c\xff\x3d\x61\x46\xe4\x8c\x46\x25\x75\xb6\x47\x34\x46\xf8\x44\xf1\x38\x7d\x48\xe1\x36\x88\x42\x09\x43\xfa\x8e\x4f\x0a\x23\xaa\x2e\x49\xa8\x3a\xf8\x88\x52\x2c\xec\xa9\x05\x0b\xe6\xc3\x47\x00".to_vec(),
}))
@@ -264,8 +263,8 @@ mod tests {
);
}
- #[test]
- pub fn test_process_user_aborted() {
+ #[async_test::test]
+ pub async fn test_process_user_aborted() {
let request = pb::BtcSignMessageRequest {
coin: BtcCoin::Btc as _,
script_config: Some(pb::BtcScriptConfigWithKeypath {
@@ -284,7 +283,7 @@ mod tests {
// Basic info dialog aborted.
mock_hal.ui.abort_nth(0);
assert_eq!(
- block_on(process(&mut mock_hal, &request)),
+ process(&mut mock_hal, &request).await,
Err(Error::UserAbort)
);
assert_eq!(
@@ -301,7 +300,7 @@ mod tests {
mock_hal.ui.abort_nth(1);
mock_unlocked();
assert_eq!(
- block_on(process(&mut mock_hal, &request)),
+ process(&mut mock_hal, &request).await,
Err(Error::UserAbort)
);
assert_eq!(mock_hal.ui.screens.len(), 2);
@@ -310,18 +309,18 @@ mod tests {
let mut mock_hal = TestingHal::new();
mock_hal.ui.abort_nth(2);
assert_eq!(
- block_on(process(&mut mock_hal, &request)),
+ process(&mut mock_hal, &request).await,
Err(Error::UserAbort)
);
assert_eq!(mock_hal.ui.screens.len(), 3);
}
- #[test]
- pub fn test_process_failures() {
+ #[async_test::test]
+ pub async fn test_process_failures() {
const KEYPATH: &[u32] = &[84 + HARDENED, 0 + HARDENED, 0 + HARDENED, 0, 0];
// Invalid coin
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&pb::BtcSignMessageRequest {
coin: -1,
@@ -334,13 +333,14 @@ mod tests {
msg: MESSAGE.as_bytes().to_vec(),
host_nonce_commitment: None,
}
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
// Invalid script type (invalid simple type)
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&pb::BtcSignMessageRequest {
coin: BtcCoin::Btc as _,
@@ -353,13 +353,14 @@ mod tests {
msg: MESSAGE.as_bytes().to_vec(),
host_nonce_commitment: None,
}
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
// Invalid script type (taproot not supported)
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&pb::BtcSignMessageRequest {
coin: BtcCoin::Btc as _,
@@ -372,13 +373,14 @@ mod tests {
msg: MESSAGE.as_bytes().to_vec(),
host_nonce_commitment: None,
}
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
// Invalid script type (multisig not supported)
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&pb::BtcSignMessageRequest {
coin: BtcCoin::Btc as _,
@@ -393,13 +395,14 @@ mod tests {
msg: MESSAGE.as_bytes().to_vec(),
host_nonce_commitment: None,
}
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
// Message too long
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&pb::BtcSignMessageRequest {
coin: BtcCoin::Btc as _,
@@ -412,14 +415,15 @@ mod tests {
msg: [0; 1025].to_vec(),
host_nonce_commitment: None,
}
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
// Invalid keypath
mock_unlocked();
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&pb::BtcSignMessageRequest {
coin: BtcCoin::Btc as _,
@@ -432,13 +436,14 @@ mod tests {
msg: MESSAGE.as_bytes().to_vec(),
host_nonce_commitment: None,
}
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
// Invalid keypath (mainnet keypath on testnet)
mock_unlocked();
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&pb::BtcSignMessageRequest {
coin: BtcCoin::Tbtc as _,
@@ -451,7 +456,8 @@ mod tests {
msg: MESSAGE.as_bytes().to_vec(),
host_nonce_commitment: None,
}
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
}
diff --git a/src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs b/src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs
index edf5f2a..9804d12 100644
--- a/src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs
@@ -1340,7 +1340,6 @@ mod tests {
use alloc::boxed::Box;
use hex_lit::hex;
use pb::btc_payment_request_request::{Memo, memo};
- use util::bb02_async::block_on;
use util::bip32::HARDENED;
fn extract_next(response: &Response) -> &pb::BtcSignNextResponse {
@@ -1718,8 +1717,8 @@ mod tests {
}));
}
- #[test]
- pub fn test_sign_init_fail() {
+ #[async_test::test]
+ pub async fn test_sign_init_fail() {
*crate::hww::MOCK_NEXT_REQUEST.0.borrow_mut() = None;
let init_req_valid = pb::BtcSignInitRequest {
@@ -1745,7 +1744,7 @@ mod tests {
// test keystore locked
crate::keystore::lock();
assert_eq!(
- block_on(process(&mut TestingHal::new(), &init_req_valid,)),
+ process(&mut TestingHal::new(), &init_req_valid,).await,
Err(Error::InvalidState)
);
}
@@ -1757,7 +1756,7 @@ mod tests {
init_req_invalid.coin = pb::BtcCoin::Ltc as _;
init_req_invalid.format_unit = FormatUnit::Sat as _;
assert_eq!(
- block_on(process(&mut TestingHal::new(), &init_req_invalid)),
+ process(&mut TestingHal::new(), &init_req_invalid).await,
Err(Error::InvalidInput)
);
}
@@ -1767,7 +1766,7 @@ mod tests {
for version in 3..10 {
init_req_invalid.version = version;
assert_eq!(
- block_on(process(&mut TestingHal::new(), &init_req_invalid)),
+ process(&mut TestingHal::new(), &init_req_invalid).await,
Err(Error::InvalidInput)
);
}
@@ -1777,7 +1776,7 @@ mod tests {
let mut init_req_invalid = init_req_valid.clone();
init_req_invalid.locktime = 500000000;
assert_eq!(
- block_on(process(&mut TestingHal::new(), &init_req_invalid)),
+ process(&mut TestingHal::new(), &init_req_invalid).await,
Err(Error::InvalidInput)
);
}
@@ -1786,7 +1785,7 @@ mod tests {
let mut init_req_invalid = init_req_valid.clone();
init_req_invalid.num_inputs = 0;
assert_eq!(
- block_on(process(&mut TestingHal::new(), &init_req_invalid)),
+ process(&mut TestingHal::new(), &init_req_invalid).await,
Err(Error::InvalidInput)
);
}
@@ -1795,7 +1794,7 @@ mod tests {
let mut init_req_invalid = init_req_valid.clone();
init_req_invalid.num_outputs = 0;
assert_eq!(
- block_on(process(&mut TestingHal::new(), &init_req_invalid)),
+ process(&mut TestingHal::new(), &init_req_invalid).await,
Err(Error::InvalidInput)
);
}
@@ -1804,7 +1803,7 @@ mod tests {
let mut init_req_invalid = init_req_valid.clone();
init_req_invalid.coin = 4; // BtcCoin is defined from 0 to 3.
assert_eq!(
- block_on(process(&mut TestingHal::new(), &init_req_invalid)),
+ process(&mut TestingHal::new(), &init_req_invalid).await,
Err(Error::InvalidInput)
);
}
@@ -1813,7 +1812,7 @@ mod tests {
let mut init_req_invalid = init_req_valid.clone();
init_req_invalid.script_configs[0].keypath[2] = HARDENED + 100;
assert_eq!(
- block_on(process(&mut TestingHal::new(), &init_req_invalid)),
+ process(&mut TestingHal::new(), &init_req_invalid).await,
Err(Error::InvalidInput)
);
}
@@ -1822,7 +1821,7 @@ mod tests {
let mut init_req_invalid = init_req_valid.clone();
init_req_invalid.script_configs = vec![];
assert_eq!(
- block_on(process(&mut TestingHal::new(), &init_req_invalid)),
+ process(&mut TestingHal::new(), &init_req_invalid).await,
Err(Error::InvalidInput)
);
}
@@ -1849,7 +1848,7 @@ mod tests {
},
];
assert_eq!(
- block_on(process(&mut TestingHal::new(), &init_req_invalid)),
+ process(&mut TestingHal::new(), &init_req_invalid).await,
Err(Error::InvalidInput)
);
}
@@ -1910,14 +1909,14 @@ mod tests {
},
];
assert_eq!(
- block_on(process(&mut TestingHal::new(), &init_req_invalid)),
+ process(&mut TestingHal::new(), &init_req_invalid).await,
Err(Error::InvalidInput)
);
}
{
// no taproot in Litecoin
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&pb::BtcSignInitRequest {
coin: pb::BtcCoin::Ltc as _,
@@ -1937,7 +1936,8 @@ mod tests {
format_unit: FormatUnit::Default as _,
contains_silent_payment_outputs: false,
}
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
}
@@ -1953,14 +1953,14 @@ mod tests {
keypath: vec![],
}];
assert_eq!(
- block_on(process(&mut TestingHal::new(), &init_req_invalid)),
+ process(&mut TestingHal::new(), &init_req_invalid).await,
Err(Error::InvalidInput)
);
}
}
- #[test]
- pub fn test_process() {
+ #[async_test::test]
+ pub async fn test_process() {
static mut UI_COUNTER: u32 = 0;
static mut PREVTX_REQUESTED: u32 = 0;
@@ -1986,12 +1986,11 @@ mod tests {
}));
mock_unlocked();
- let tx = transaction.borrow();
- let mut init_request = tx.init_request();
+ let mut init_request = transaction.borrow().init_request();
init_request.format_unit = format_unit as _;
let mut mock_hal = TestingHal::new();
- let result = block_on(process(&mut mock_hal, &init_request));
+ let result = process(&mut mock_hal, &init_request).await;
assert_eq!(
mock_hal.ui.screens,
@@ -2100,13 +2099,16 @@ mod tests {
}
_ => panic!("wrong result"),
}
- assert_eq!(unsafe { PREVTX_REQUESTED }, tx.inputs.len() as u32);
+ assert_eq!(
+ unsafe { PREVTX_REQUESTED },
+ transaction.borrow().inputs.len() as u32
+ );
}
}
/// Test that receiving an unexpected message from the host results in an invalid state error.
- #[test]
- pub fn test_invalid_state() {
+ #[async_test::test]
+ pub async fn test_invalid_state() {
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
mock_unlocked();
@@ -2120,17 +2122,15 @@ mod tests {
Ok(Request::BtcSignInput(tx.borrow().inputs[0].input.clone()))
}));
- let result = block_on(process(
- &mut TestingHal::new(),
- &transaction.borrow().init_request(),
- ));
+ let init_request = transaction.borrow().init_request();
+ let result = process(&mut TestingHal::new(), &init_request).await;
assert_eq!(result, Err(Error::InvalidState));
assert_eq!(unsafe { COUNTER }, 2);
}
/// Test signing if all inputs are of type P2WPKH-P2SH.
- #[test]
- pub fn test_script_type_p2wpkh_p2sh() {
+ #[async_test::test]
+ pub async fn test_script_type_p2wpkh_p2sh() {
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
for input in transaction.borrow_mut().inputs.iter_mut() {
@@ -2153,7 +2153,7 @@ mod tests {
}),
keypath: vec![49 + HARDENED, 0 + HARDENED, 10 + HARDENED],
};
- let result = block_on(process(&mut TestingHal::new(), &init_request));
+ let result = process(&mut TestingHal::new(), &init_request).await;
match result {
Ok(Response::BtcSignNext(next)) => {
assert!(next.has_signature);
@@ -2169,8 +2169,8 @@ mod tests {
}
/// Test signing if all inputs are of type P2TR.
- #[test]
- pub fn test_script_type_p2tr() {
+ #[async_test::test]
+ pub async fn test_script_type_p2tr() {
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
for input in transaction.borrow_mut().inputs.iter_mut() {
@@ -2204,7 +2204,7 @@ mod tests {
}),
keypath: vec![86 + HARDENED, 0 + HARDENED, 10 + HARDENED],
};
- let result = block_on(process(&mut TestingHal::new(), &init_request));
+ let result = process(&mut TestingHal::new(), &init_request).await;
match result {
Ok(Response::BtcSignNext(next)) => {
assert!(next.has_signature);
@@ -2222,8 +2222,8 @@ mod tests {
/// Test signing if with mixed inputs, one of them being taproot. Previous transactions of all
/// inputs should be streamed in this case.
- #[test]
- pub fn test_script_type_p2tr_mixed() {
+ #[async_test::test]
+ pub async fn test_script_type_p2tr_mixed() {
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
transaction.borrow_mut().inputs[0].input.script_config_index = 1;
@@ -2253,7 +2253,7 @@ mod tests {
}),
keypath: vec![86 + HARDENED, 0 + HARDENED, 10 + HARDENED],
});
- assert!(block_on(process(&mut TestingHal::new(), &init_request)).is_ok());
+ assert!(process(&mut TestingHal::new(), &init_request).await.is_ok());
assert_eq!(
unsafe { PREVTX_REQUESTED },
transaction.borrow().inputs.len() as u32
@@ -2263,24 +2263,22 @@ mod tests {
/// Test signing UTXOs with high keypath address indices. Even though we don't support verifying
/// receive addresses at these indices (to mitigate ransom attacks), we should still be able to
/// spend them.
- #[test]
- pub fn test_spend_high_address_index() {
+ #[async_test::test]
+ pub async fn test_spend_high_address_index() {
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
transaction.borrow_mut().inputs[0].input.keypath[4] = 100000;
mock_host_responder(transaction.clone());
mock_unlocked();
- let result = block_on(process(
- &mut TestingHal::new(),
- &transaction.borrow().init_request(),
- ));
+ let init_request = transaction.borrow().init_request();
+ let result = process(&mut TestingHal::new(), &init_request).await;
assert!(result.is_ok());
}
/// Test invalid input cases.
- #[test]
- pub fn test_invalid_input() {
+ #[async_test::test]
+ pub async fn test_invalid_input() {
enum TestCase {
// all inputs should be the same coin type.
WrongCoinInput,
@@ -2381,17 +2379,15 @@ mod tests {
}
mock_host_responder(transaction.clone());
mock_unlocked();
- let result = block_on(process(
- &mut TestingHal::new(),
- &transaction.borrow().init_request(),
- ));
+ let init_request = transaction.borrow().init_request();
+ let result = process(&mut TestingHal::new(), &init_request).await;
assert_eq!(result, Err(Error::InvalidInput));
}
}
/// Test signing with mixed input types.
- #[test]
- pub fn test_mixed_inputs() {
+ #[async_test::test]
+ pub async fn test_mixed_inputs() {
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
transaction.borrow_mut().inputs[0].input.script_config_index = 1;
@@ -2409,29 +2405,31 @@ mod tests {
}),
keypath: vec![49 + HARDENED, 0 + HARDENED, 10 + HARDENED],
});
- assert!(block_on(process(&mut TestingHal::new(), &init_request)).is_ok());
+ assert!(process(&mut TestingHal::new(), &init_request).await.is_ok());
}
- #[test]
- fn test_user_aborts() {
+ #[async_test::test]
+ async fn test_user_aborts() {
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
mock_host_responder(transaction.clone());
// We go through all possible user confirmations and abort one of them at a time.
- for counter in 0..transaction.borrow().total_confirmations {
+ let total_confirmations = transaction.borrow().total_confirmations;
+ for counter in 0..total_confirmations {
let mut mock_hal = TestingHal::new();
mock_hal.ui.abort_nth(counter as usize);
mock_unlocked();
+ let init_request = transaction.borrow().init_request();
assert_eq!(
- block_on(process(&mut mock_hal, &transaction.borrow().init_request())),
+ process(&mut mock_hal, &init_request).await,
Err(Error::UserAbort)
);
}
}
/// Check workflow when a locktime applies.
- #[test]
- fn test_locktime() {
+ #[async_test::test]
+ async fn test_locktime() {
struct Test {
coin: pb::BtcCoin,
locktime: u32,
@@ -2501,7 +2499,7 @@ mod tests {
init_request.locktime = test_case.locktime;
let mut mock_hal = TestingHal::new();
- let result = block_on(process(&mut mock_hal, &init_request));
+ let result = process(&mut mock_hal, &init_request).await;
let mut found_locktime = false;
for screen in mock_hal.ui.screens.iter() {
match screen {
@@ -2521,8 +2519,8 @@ mod tests {
}
// Test a transaction with an unusually high fee.
- #[test]
- fn test_high_fee_warning() {
+ #[async_test::test]
+ async fn test_high_fee_warning() {
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
transaction.borrow_mut().outputs[1].value = 1034567890;
@@ -2530,10 +2528,11 @@ mod tests {
transaction.borrow_mut().total_confirmations += 1;
mock_host_responder(transaction.clone());
mock_unlocked();
- let tx = transaction.borrow();
+ let init_request = transaction.borrow().init_request();
+ let total_confirmations = transaction.borrow().total_confirmations;
let mut mock_hal = TestingHal::new();
- assert!(block_on(process(&mut mock_hal, &tx.init_request())).is_ok());
+ assert!(process(&mut mock_hal, &init_request).await.is_ok());
assert!(mock_hal.ui.screens.contains(&Screen::TotalFee {
total: "13.39999900 BTC".into(),
@@ -2547,14 +2546,14 @@ mod tests {
);
assert_eq!(
mock_hal.ui.screens.len() as u32,
- tx.total_confirmations + 1 // plus status screen
+ total_confirmations + 1 // plus status screen
);
}
// Test a P2TR output. It is not part of the default test transaction because Taproot is not
// active on Litecoin yet.
- #[test]
- fn test_p2tr_output() {
+ #[async_test::test]
+ async fn test_p2tr_output() {
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
transaction.borrow_mut().outputs[0].r#type = pb::BtcOutputType::P2tr as _;
@@ -2564,7 +2563,8 @@ mod tests {
mock_unlocked();
let mut mock_hal = TestingHal::new();
- let result = block_on(process(&mut mock_hal, &transaction.borrow().init_request()));
+ let init_request = transaction.borrow().init_request();
+ let result = process(&mut mock_hal, &init_request).await;
assert_eq!(
mock_hal.ui.screens[0],
Screen::Recipient {
@@ -2589,8 +2589,8 @@ mod tests {
}
}
- #[test]
- fn test_silent_payment_output() {
+ #[async_test::test]
+ async fn test_silent_payment_output() {
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
@@ -2637,7 +2637,7 @@ mod tests {
});
let mut mock_hal = TestingHal::new();
- assert!(block_on(process(&mut mock_hal, &init_request)).is_ok());
+ assert!(process(&mut mock_hal, &init_request).await.is_ok());
assert_eq!(
mock_hal.ui.screens[0],
@@ -2649,8 +2649,8 @@ mod tests {
}
// Test an output that is sending to the same account, but is not a change output by keypath.
- #[test]
- fn test_self_send_non_change_output_same_account() {
+ #[async_test::test]
+ async fn test_self_send_non_change_output_same_account() {
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
transaction.borrow_mut().outputs[5].keypath[3] = 0;
@@ -2658,8 +2658,8 @@ mod tests {
mock_unlocked();
let mut mock_hal = TestingHal::new();
-
- let result = block_on(process(&mut mock_hal, &transaction.borrow().init_request()));
+ let init_request = transaction.borrow().init_request();
+ let result = process(&mut mock_hal, &init_request).await;
assert_eq!(
mock_hal.ui.screens[4],
Screen::Recipient {
@@ -2688,8 +2688,8 @@ mod tests {
}
// Test an output that is sending to another account of our keystore.
- #[test]
- fn test_self_send_different_account() {
+ #[async_test::test]
+ async fn test_self_send_different_account() {
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
const DIFFERENT_ACCOUNT: u32 = 20 + HARDENED;
@@ -2698,8 +2698,8 @@ mod tests {
transaction.borrow_mut().outputs[5].output_script_config_index = Some(0);
mock_host_responder(transaction.clone());
mock_unlocked();
- let tx = transaction.borrow();
- let mut init_request = tx.init_request();
+ let coin = transaction.borrow().coin;
+ let mut init_request = transaction.borrow().init_request();
init_request.output_script_configs = vec![pb::BtcScriptConfigWithKeypath {
script_config: Some(pb::BtcScriptConfig {
config: Some(pb::btc_script_config::Config::SimpleType(
@@ -2708,13 +2708,13 @@ mod tests {
}),
keypath: vec![
84 + HARDENED,
- super::super::params::get(tx.coin).bip44_coin,
+ super::super::params::get(coin).bip44_coin,
DIFFERENT_ACCOUNT,
],
}];
let mut mock_hal = TestingHal::new();
- assert!(block_on(process(&mut mock_hal, &init_request)).is_ok());
+ assert!(process(&mut mock_hal, &init_request).await.is_ok());
assert_eq!(
mock_hal.ui.screens[4],
@@ -2726,8 +2726,8 @@ mod tests {
}
/// Exercise the antiklepto protocol
- #[test]
- fn test_antiklepto() {
+ #[async_test::test]
+ async fn test_antiklepto() {
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
let host_nonce = hex!("abababababababababababababababababababababababababababababababab");
@@ -2745,10 +2745,8 @@ mod tests {
.host_nonce_commitment = Some(host_nonce_commitment);
mock_host_responder(transaction.clone());
mock_unlocked();
- let result = block_on(process(
- &mut TestingHal::new(),
- &transaction.borrow().init_request(),
- ));
+ let init_request = transaction.borrow().init_request();
+ let result = process(&mut TestingHal::new(), &init_request).await;
match result {
Ok(Response::Btc(pb::BtcResponse {
response: Some(pb::btc_response::Response::SignNext(next)),
@@ -2766,8 +2764,8 @@ mod tests {
}
/// The sum of the inputs in the 2nd pass can't be higher than in the first for all inputs.
- #[test]
- fn test_input_sum_changes() {
+ #[async_test::test]
+ async fn test_input_sum_changes() {
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
static mut PASS2_INPUT_REQUESTS_COUNTER: u32 = 0;
@@ -2802,10 +2800,8 @@ mod tests {
}))
};
mock_unlocked();
- let result = block_on(process(
- &mut TestingHal::new(),
- &transaction.borrow().init_request(),
- ));
+ let init_request = transaction.borrow().init_request();
+ let result = process(&mut TestingHal::new(), &init_request).await;
assert_eq!(result, Err(Error::InvalidInput));
// Only one input in the 2nd pass was requested, meaning the process failed after validating
// the amount in the first input.
@@ -2814,8 +2810,8 @@ mod tests {
/// At the last input, the sum of the inputs in the 2nd pass must be the same as the sum of the
/// inputs in the first pass.
- #[test]
- fn test_input_sum_last_mismatch() {
+ #[async_test::test]
+ async fn test_input_sum_last_mismatch() {
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
static mut PASS2_INPUT_REQUESTS_COUNTER: u32 = 0;
@@ -2844,10 +2840,8 @@ mod tests {
}))
};
mock_unlocked();
- let result = block_on(process(
- &mut TestingHal::new(),
- &transaction.borrow().init_request(),
- ));
+ let init_request = transaction.borrow().init_request();
+ let result = process(&mut TestingHal::new(), &init_request).await;
assert_eq!(result, Err(Error::InvalidInput));
// All inputs were requested, the failure happens when comparing the sums of the two passes
// at the end.
@@ -2858,8 +2852,8 @@ mod tests {
}
/// Outgoing sum overflows.
- #[test]
- fn test_overflow_output_out() {
+ #[async_test::test]
+ async fn test_overflow_output_out() {
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
*crate::hww::MOCK_NEXT_REQUEST.0.borrow_mut() = {
@@ -2881,16 +2875,14 @@ mod tests {
}))
};
mock_unlocked();
- let result = block_on(process(
- &mut TestingHal::new(),
- &transaction.borrow().init_request(),
- ));
+ let init_request = transaction.borrow().init_request();
+ let result = process(&mut TestingHal::new(), &init_request).await;
assert_eq!(result, Err(Error::InvalidInput));
}
/// Outgoing change overflows.
- #[test]
- fn test_overflow_output_ours() {
+ #[async_test::test]
+ async fn test_overflow_output_ours() {
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
*crate::hww::MOCK_NEXT_REQUEST.0.borrow_mut() = {
@@ -2912,15 +2904,13 @@ mod tests {
}))
};
mock_unlocked();
- let result = block_on(process(
- &mut TestingHal::new(),
- &transaction.borrow().init_request(),
- ));
+ let init_request = transaction.borrow().init_request();
+ let result = process(&mut TestingHal::new(), &init_request).await;
assert_eq!(result, Err(Error::InvalidInput));
}
- #[test]
- fn test_multisig_p2wsh() {
+ #[async_test::test]
+ async fn test_multisig_p2wsh() {
let transaction = alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new_multisig()));
mock_host_responder(transaction.clone());
@@ -2978,7 +2968,7 @@ mod tests {
}
};
- let result = block_on(process(&mut mock_hal, &init_request));
+ let result = process(&mut mock_hal, &init_request).await;
match result {
Ok(Response::BtcSignNext(next)) => {
assert!(next.has_signature);
@@ -3027,8 +3017,8 @@ mod tests {
}
/// If the multisig has not been registered before, signing fails.
- #[test]
- fn test_multisig_not_registered() {
+ #[async_test::test]
+ async fn test_multisig_not_registered() {
let transaction = alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new_multisig()));
mock_host_responder(transaction.clone());
mock_unlocked_using_mnemonic(
@@ -3075,13 +3065,13 @@ mod tests {
}
};
assert_eq!(
- block_on(process(&mut TestingHal::new(), &init_request)),
+ process(&mut TestingHal::new(), &init_request).await,
Err(Error::InvalidInput)
);
}
- #[test]
- fn test_multisig_p2wsh_p2sh() {
+ #[async_test::test]
+ async fn test_multisig_p2wsh_p2sh() {
let transaction = alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new_multisig()));
for input in transaction.borrow_mut().inputs.iter_mut() {
input.input.keypath[3] = 1 + HARDENED;
@@ -3147,7 +3137,7 @@ mod tests {
contains_silent_payment_outputs: false,
}
};
- let result = block_on(process(&mut mock_hal, &init_request));
+ let result = process(&mut mock_hal, &init_request).await;
match result {
Ok(Response::BtcSignNext(next)) => {
assert!(next.has_signature);
@@ -3162,8 +3152,8 @@ mod tests {
}
}
- #[test]
- fn test_multisig_large() {
+ #[async_test::test]
+ async fn test_multisig_large() {
let transaction = alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new_multisig()));
mock_host_responder(transaction.clone());
@@ -3231,7 +3221,7 @@ mod tests {
contains_silent_payment_outputs: false,
}
};
- let result = block_on(process(&mut mock_hal, &init_request));
+ let result = process(&mut mock_hal, &init_request).await;
match result {
Ok(Response::BtcSignNext(next)) => {
assert!(next.has_signature);
@@ -3246,8 +3236,8 @@ mod tests {
}
}
- #[test]
- fn test_policy() {
+ #[async_test::test]
+ async fn test_policy() {
let mut mock_hal = TestingHal::new();
let transaction = alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new_policy()));
@@ -3293,12 +3283,10 @@ mod tests {
.multisig_set_by_hash(&hash, "test policy account name")
.unwrap();
- let result = block_on(process(
- &mut mock_hal,
- &transaction
- .borrow()
- .init_request_policy(policy, keypath_account),
- ));
+ let init_request = transaction
+ .borrow()
+ .init_request_policy(policy, keypath_account);
+ let result = process(&mut mock_hal, &init_request).await;
match result {
Ok(Response::BtcSignNext(next)) => {
assert!(next.has_signature);
@@ -3369,8 +3357,8 @@ mod tests {
/// Same as `test_policy()`, but for a tr() Taproot policy.
/// We check that the previous transactions are not streamed as they are not needed for Taproot.
- #[test]
- fn test_policy_tr() {
+ #[async_test::test]
+ async fn test_policy_tr() {
let transaction = alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new_policy()));
let tx = transaction.clone();
@@ -3417,12 +3405,10 @@ mod tests {
.multisig_set_by_hash(&hash32, "test policy account name")
.unwrap();
- let result = block_on(process(
- &mut mock_hal,
- &transaction
- .borrow()
- .init_request_policy(policy, keypath_account),
- ));
+ let init_request = transaction
+ .borrow()
+ .init_request_policy(policy, keypath_account);
+ let result = process(&mut mock_hal, &init_request).await;
match result {
Ok(Response::BtcSignNext(next)) => {
assert!(next.has_signature);
@@ -3439,8 +3425,8 @@ mod tests {
}
// Tests that unspendable internal Taproot keys are displayed as such.
- #[test]
- fn test_policy_tr_unspendable_internal_key() {
+ #[async_test::test]
+ async fn test_policy_tr_unspendable_internal_key() {
let transaction = alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new_policy()));
mock_host_responder(transaction.clone());
@@ -3484,15 +3470,10 @@ mod tests {
.multisig_set_by_hash(&hash32, "test policy account name")
.unwrap();
- assert!(
- block_on(process(
- &mut mock_hal,
- &transaction
- .borrow()
- .init_request_policy(policy, keypath_account),
- ))
- .is_ok()
- );
+ let init_request = transaction
+ .borrow()
+ .init_request_policy(policy, keypath_account);
+ assert!(process(&mut mock_hal, &init_request).await.is_ok());
assert_eq!(
mock_hal.ui.screens,
@@ -3555,8 +3536,8 @@ mod tests {
}
/// Test that a policy with derivations other than `/**` work.
- #[test]
- fn test_policy_different_multipath_derivations() {
+ #[async_test::test]
+ async fn test_policy_different_multipath_derivations() {
let policy_str = "wsh(multi(2,@0/<10;11>/*,@1/<20;21>/*))";
let transaction = alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new_policy()));
@@ -3599,12 +3580,10 @@ mod tests {
.multisig_set_by_hash(&hash32, "test policy account name")
.unwrap();
- let result = block_on(process(
- &mut mock_hal,
- &transaction
- .borrow()
- .init_request_policy(policy, keypath_account),
- ));
+ let init_request = transaction
+ .borrow()
+ .init_request_policy(policy, keypath_account);
+ let result = process(&mut mock_hal, &init_request).await;
match result {
Ok(Response::BtcSignNext(next)) => {
assert!(next.has_signature);
@@ -3619,8 +3598,8 @@ mod tests {
}
}
- #[test]
- fn test_policy_wrong_account_keypath() {
+ #[async_test::test]
+ async fn test_policy_wrong_account_keypath() {
let transaction = alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new_policy()));
mock_host_responder(transaction.clone());
@@ -3659,20 +3638,18 @@ mod tests {
.multisig_set_by_hash(&hash32, "test policy account name")
.unwrap();
+ let init_request = transaction
+ .borrow()
+ .init_request_policy(policy, wrong_keypath_account);
assert_eq!(
- block_on(process(
- &mut mock_hal,
- &transaction
- .borrow()
- .init_request_policy(policy, wrong_keypath_account)
- )),
+ process(&mut mock_hal, &init_request).await,
Err(Error::InvalidInput)
);
}
/// Avoid change keypaths with a too high address index.
- #[test]
- fn test_policy_wrong_change_keypath() {
+ #[async_test::test]
+ async fn test_policy_wrong_change_keypath() {
let transaction = alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new_policy()));
transaction.borrow_mut().outputs[0].keypath[5] = 10000; // Too high change address index.
mock_host_responder(transaction.clone());
@@ -3711,19 +3688,17 @@ mod tests {
.multisig_set_by_hash(&hash32, "test policy account name")
.unwrap();
+ let init_request = transaction
+ .borrow()
+ .init_request_policy(policy, keypath_account);
assert_eq!(
- block_on(process(
- &mut mock_hal,
- &transaction
- .borrow()
- .init_request_policy(policy, keypath_account)
- )),
+ process(&mut mock_hal, &init_request).await,
Err(Error::InvalidInput)
);
}
- #[test]
- pub fn test_payment_request() {
+ #[async_test::test]
+ pub async fn test_payment_request() {
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
@@ -3760,7 +3735,7 @@ mod tests {
let init_request = transaction.borrow().init_request();
let mut mock_hal = TestingHal::new();
- let result = block_on(process(&mut mock_hal, &init_request));
+ let result = process(&mut mock_hal, &init_request).await;
assert!(result.is_ok());
assert_eq!(
@@ -3890,8 +3865,8 @@ mod tests {
}
#[cfg(feature = "app-ethereum")]
- #[test]
- pub fn test_swap_payment_request() {
+ #[async_test::test]
+ pub async fn test_swap_payment_request() {
// End-to-end swap signing: swap screens appear, then the regular BTC confirmations continue.
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
@@ -3933,7 +3908,7 @@ mod tests {
let init_request = transaction.borrow().init_request();
let mut mock_hal = TestingHal::new();
- let result = block_on(process(&mut mock_hal, &init_request));
+ let result = process(&mut mock_hal, &init_request).await;
assert!(result.is_ok());
assert_eq!(
@@ -3984,8 +3959,8 @@ mod tests {
}
#[cfg(feature = "app-ethereum")]
- #[test]
- pub fn test_swap_payment_request_unsupported_source_coin() {
+ #[async_test::test]
+ pub async fn test_swap_payment_request_unsupported_source_coin() {
// Swap UI is restricted to BTC/LTC source accounts; other BTC-like coins must fail early.
let transaction = alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(
pb::BtcCoin::Tbtc,
@@ -4027,13 +4002,13 @@ mod tests {
let init_request = transaction.borrow().init_request();
assert_eq!(
- block_on(process(&mut TestingHal::new(), &init_request)),
+ process(&mut TestingHal::new(), &init_request).await,
Err(Error::InvalidInput)
);
}
- #[test]
- fn test_op_return() {
+ #[async_test::test]
+ async fn test_op_return() {
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
@@ -4053,7 +4028,7 @@ mod tests {
let init_request = transaction.borrow().init_request();
let mut mock_hal = TestingHal::new();
- let result = block_on(process(&mut mock_hal, &init_request));
+ let result = process(&mut mock_hal, &init_request).await;
match result {
Ok(Response::BtcSignNext(next)) => {
@@ -4071,8 +4046,8 @@ mod tests {
assert!(mock_hal.ui.contains_confirm("OP_RETURN", "hello world"));
}
- #[test]
- fn test_op_return_nonascii() {
+ #[async_test::test]
+ async fn test_op_return_nonascii() {
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
@@ -4092,7 +4067,7 @@ mod tests {
let init_request = transaction.borrow().init_request();
let mut mock_hal = TestingHal::new();
- let result = block_on(process(&mut mock_hal, &init_request));
+ let result = process(&mut mock_hal, &init_request).await;
assert!(result.is_ok());
assert!(
@@ -4102,8 +4077,8 @@ mod tests {
);
}
- #[test]
- fn test_op_return_fail_nonzero_value() {
+ #[async_test::test]
+ async fn test_op_return_fail_nonzero_value() {
let transaction =
alloc::rc::Rc::new(core::cell::RefCell::new(Transaction::new(pb::BtcCoin::Btc)));
@@ -4124,7 +4099,7 @@ mod tests {
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(&mut mock_hal, &init_request)),
+ process(&mut mock_hal, &init_request).await,
Err(Error::InvalidInput)
);
}
diff --git a/src/rust/bitbox02-rust/src/hww/api/bitcoin/xpubs.rs b/src/rust/bitbox02-rust/src/hww/api/bitcoin/xpubs.rs
index 666a064..856e664 100644
--- a/src/rust/bitbox02-rust/src/hww/api/bitcoin/xpubs.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/bitcoin/xpubs.rs
@@ -60,11 +60,10 @@ mod tests {
use super::*;
use crate::keystore::testing::{mock_unlocked, mock_unlocked_using_mnemonic};
- use util::bb02_async::block_on;
use util::bip32::HARDENED;
- #[test]
- pub fn test_process_xpubs() {
+ #[async_test::test]
+ pub async fn test_process_xpubs() {
mock_unlocked_using_mnemonic(
"sleep own lobster state clean thrive tail exist cactus bitter pass soccer clinic riot dream turkey before sport action praise tunnel hood donate man",
"",
@@ -73,7 +72,7 @@ mod tests {
let mut mock_hal = crate::hal::testing::TestingHal::new();
mock_hal.securechip.event_counter_reset();
assert_eq!(
- block_on(process_xpubs(&mut mock_hal, &pb::BtcXpubsRequest {
+ process_xpubs(&mut mock_hal, &pb::BtcXpubsRequest {
coin: BtcCoin::Btc as _,
xpub_type: XPubType::Xpub as _,
keypaths: vec![
@@ -87,7 +86,7 @@ mod tests {
keypath: vec![49 + HARDENED, HARDENED, HARDENED],
},
],
- })),
+ }).await,
Ok(Response::Pubs(pb::PubsResponse {
pubs: vec![
"xpub6CNbmcHwZDudAvCAZVE5kejUoFD63mbkRbRMA2HoF9oNWsCofni87gJKp31qZJ9FsCMQR2vK9AS51mT8dgUMGsHW6SfaAKb4eSzpqJn7zwK".into(),
@@ -100,7 +99,7 @@ mod tests {
// Different output type
assert_eq!(
- block_on(process_xpubs(&mut crate::hal::testing::TestingHal::new(),&pb::BtcXpubsRequest {
+ process_xpubs(&mut crate::hal::testing::TestingHal::new(),&pb::BtcXpubsRequest {
coin: BtcCoin::Btc as _,
xpub_type: XPubType::Tpub as _,
keypaths: vec![
@@ -108,7 +107,7 @@ mod tests {
keypath: vec![84 + HARDENED, HARDENED, HARDENED],
},
],
- })),
+ }).await,
Ok(Response::Pubs(pb::PubsResponse {
pubs: vec![
"tpubDCkEHr7dGVs5SiP21gDAxa4r8NJk3A6oyE1eWaLwb4ZGG9sWk1ZDG7yA456d5o6Vf6tK2cSBgGG7hwwk2YKbAJjoA3QsqrFJEQbEbLKkt5w".into(),
@@ -118,7 +117,7 @@ mod tests {
// Different coin
assert_eq!(
- block_on(process_xpubs(&mut crate::hal::testing::TestingHal::new(),&pb::BtcXpubsRequest {
+ process_xpubs(&mut crate::hal::testing::TestingHal::new(),&pb::BtcXpubsRequest {
coin: BtcCoin::Ltc as _,
xpub_type: XPubType::Xpub as _,
keypaths: vec![
@@ -126,7 +125,7 @@ mod tests {
keypath: vec![84 + HARDENED, 2+HARDENED, HARDENED],
},
],
- })),
+ }).await,
Ok(Response::Pubs(pb::PubsResponse {
pubs: vec![
"xpub6DEKPXTV5HQNcJNGWcSCsdEc2zzoXUHy1L678r3ux3CN2iHqxwKgFaxnzs73nr33VR7SNTDaqFzeyMwHocBEa4j96LEoKacL38N6RAXS3hP".into(),
@@ -136,12 +135,12 @@ mod tests {
}
// Can get up to 20 xpubs and not more..
- #[test]
- pub fn test_process_limit() {
+ #[async_test::test]
+ pub async fn test_process_limit() {
mock_unlocked();
// At limit
- let result = block_on(process_xpubs(
+ let result = process_xpubs(
&mut crate::hal::testing::TestingHal::new(),
&pb::BtcXpubsRequest {
coin: BtcCoin::Btc as _,
@@ -152,7 +151,8 @@ mod tests {
})
.collect(),
},
- ))
+ )
+ .await
.unwrap();
match result {
Response::Pubs(pubs) => assert_eq!(pubs.pubs.len(), 20),
@@ -161,7 +161,7 @@ mod tests {
// Over limit
assert_eq!(
- block_on(process_xpubs(
+ process_xpubs(
&mut crate::hal::testing::TestingHal::new(),
&pb::BtcXpubsRequest {
coin: BtcCoin::Btc as _,
@@ -172,16 +172,17 @@ mod tests {
})
.collect(),
}
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
}
- #[test]
- pub fn test_process_invalid_keypath() {
+ #[async_test::test]
+ pub async fn test_process_invalid_keypath() {
mock_unlocked();
assert_eq!(
- block_on(process_xpubs(
+ process_xpubs(
&mut crate::hal::testing::TestingHal::new(),
&pb::BtcXpubsRequest {
coin: BtcCoin::Ltc as _,
@@ -190,7 +191,8 @@ mod tests {
keypath: vec![84 + HARDENED, 0 + HARDENED, HARDENED],
},],
}
- )),
+ )
+ .await,
Err(Error::InvalidInput),
);
}
diff --git a/src/rust/bitbox02-rust/src/hww/api/bluetooth.rs b/src/rust/bitbox02-rust/src/hww/api/bluetooth.rs
index 33c5ef2..38c5258 100644
--- a/src/rust/bitbox02-rust/src/hww/api/bluetooth.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/bluetooth.rs
@@ -224,7 +224,6 @@ mod tests {
use super::*;
use crate::hal::memory::{BleFirmwareSlot, BleMetadata};
- use util::bb02_async::block_on;
struct MockFuncs {
chunk_requests: Vec<(u32, u32)>,
@@ -269,8 +268,8 @@ mod tests {
}
/// Verifies that successful upgrades request host chunks with exact offset/length boundaries.
- #[test]
- fn test_process_upgrade_helper_chunk_streaming() {
+ #[async_test::test]
+ async fn test_process_upgrade_helper_chunk_streaming() {
struct Test<'a> {
firmware_length: u32,
expected_chunk_requests: &'a [(u32, u32)],
@@ -326,7 +325,7 @@ mod tests {
Sha256::digest(vec![0; test.firmware_length as usize]).into();
assert_eq!(
- block_on(process_upgrade_helper(
+ process_upgrade_helper(
&mut memory,
&mut mock_funcs,
&mut progress,
@@ -334,7 +333,8 @@ mod tests {
firmware_length: test.firmware_length,
},
&allowed_hash,
- )),
+ )
+ .await,
Ok(Response::Success(pb::BluetoothSuccess {}))
);
assert_eq!(mock_funcs.chunk_requests, test.expected_chunk_requests);
@@ -347,8 +347,8 @@ mod tests {
}
/// Verifies that a successful upgrade writes firmware bytes to the inactive slot and updates BLE metadata.
- #[test]
- fn test_process_upgrade_helper_success_updates_metadata_and_slot_data() {
+ #[async_test::test]
+ async fn test_process_upgrade_helper_success_updates_metadata_and_slot_data() {
let mut memory = crate::hal::testing::TestingMemory::new();
let initial_metadata = make_metadata(0);
memory.set_ble_metadata(&initial_metadata).unwrap();
@@ -362,7 +362,7 @@ mod tests {
let mut progress = TestProgress::default();
assert_eq!(
- block_on(process_upgrade_helper(
+ process_upgrade_helper(
&mut memory,
&mut mock_funcs,
&mut progress,
@@ -370,7 +370,8 @@ mod tests {
firmware_length: firmware.len() as u32,
},
&allowed_hash,
- )),
+ )
+ .await,
Ok(Response::Success(pb::BluetoothSuccess {}))
);
assert_eq!(mock_funcs.chunk_requests, vec![(0, 4096), (4096, 5)]);
@@ -402,8 +403,8 @@ mod tests {
}
/// Verifies that when slot 1 is active, a successful upgrade targets slot 0 and flips active index.
- #[test]
- fn test_process_upgrade_helper_success_uses_first_slot_if_second_is_active() {
+ #[async_test::test]
+ async fn test_process_upgrade_helper_success_uses_first_slot_if_second_is_active() {
let mut memory = crate::hal::testing::TestingMemory::new();
let initial_metadata = make_metadata(1);
memory.set_ble_metadata(&initial_metadata).unwrap();
@@ -416,7 +417,7 @@ mod tests {
let mut progress = TestProgress::default();
assert_eq!(
- block_on(process_upgrade_helper(
+ process_upgrade_helper(
&mut memory,
&mut mock_funcs,
&mut progress,
@@ -424,7 +425,8 @@ mod tests {
firmware_length: firmware.len() as u32,
},
&allowed_hash,
- )),
+ )
+ .await,
Ok(Response::Success(pb::BluetoothSuccess {}))
);
assert_eq!(mock_funcs.chunk_requests, vec![(0, 3)]);
diff --git a/src/rust/bitbox02-rust/src/hww/api/cardano/address.rs b/src/rust/bitbox02-rust/src/hww/api/cardano/address.rs
index cc846b8..735e6cb 100644
--- a/src/rust/bitbox02-rust/src/hww/api/cardano/address.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/cardano/address.rs
@@ -417,7 +417,6 @@ mod tests {
use crate::hal::testing::ui::Screen;
use crate::keystore::testing::mock_unlocked;
use alloc::boxed::Box;
- use util::bb02_async::block_on;
use util::bip32::HARDENED;
#[test]
@@ -506,15 +505,16 @@ mod tests {
}
}
- fn do_pkh_skh(keypath_payment: &[u32], keypath_stake: &[u32]) -> Result<Response, Error> {
- block_on(process(
+ async fn do_pkh_skh(keypath_payment: &[u32], keypath_stake: &[u32]) -> Result<Response, Error> {
+ process(
&mut TestingHal::new(),
&pb::CardanoAddressRequest {
network: CardanoNetwork::CardanoMainnet as _,
display: false,
script_config: Some(make_pkh_skh(keypath_payment, keypath_stake)),
},
- ))
+ )
+ .await
}
#[test]
@@ -537,15 +537,16 @@ mod tests {
);
}
- #[test]
- fn test_process_failures() {
+ #[async_test::test]
+ async fn test_process_failures() {
// All good
mock_unlocked();
assert_eq!(
do_pkh_skh(
&[1852 + HARDENED, 1815 + HARDENED, HARDENED, 0, 0],
&[1852 + HARDENED, 1815 + HARDENED, HARDENED, 2, 0],
- ),
+ )
+ .await,
Ok(Response::Pub(pb::PubResponse {
r#pub: "addr1q90tlskd4mh5kncmul7vx887j30tjtfgvap5n0g0rf9qqc7znmndrdhe7rwvqkw5c7mqnp4a3yflnvu6kff7l5dungvqmvu6hs".into()
}))
@@ -557,7 +558,8 @@ mod tests {
do_pkh_skh(
&[1852 + HARDENED, 1815 + HARDENED, HARDENED, 0, 0],
&[1852 + HARDENED, 1815 + HARDENED, HARDENED, 2, 0],
- ),
+ )
+ .await,
Err(Error::Generic)
);
@@ -567,7 +569,8 @@ mod tests {
do_pkh_skh(
&[1815 + HARDENED, 1815 + HARDENED, HARDENED, 0, 0],
&[1815 + HARDENED, 1815 + HARDENED, HARDENED, 2, 0],
- ),
+ )
+ .await,
Err(Error::InvalidInput),
);
@@ -577,7 +580,8 @@ mod tests {
do_pkh_skh(
&[1852 + HARDENED, 1815 + HARDENED, HARDENED, 0, 0],
&[1852 + HARDENED, 1815 + HARDENED, HARDENED + 1, 2, 0],
- ),
+ )
+ .await,
Err(Error::InvalidInput),
);
@@ -587,27 +591,29 @@ mod tests {
do_pkh_skh(
&[1852 + HARDENED, 1815 + HARDENED, HARDENED, 0, 0],
&[1852 + HARDENED, 1815 + HARDENED, HARDENED, 1, 0],
- ),
+ )
+ .await,
Err(Error::InvalidInput),
);
assert_eq!(
do_pkh_skh(
&[1852 + HARDENED, 1815 + HARDENED, HARDENED, 0, 0],
&[1852 + HARDENED, 1815 + HARDENED, HARDENED, 2, 1],
- ),
+ )
+ .await,
Err(Error::InvalidInput),
);
}
- #[test]
- fn test_process_confirm() {
+ #[async_test::test]
+ async fn test_process_confirm() {
const EXPECTED: &str = "addr1q90tlskd4mh5kncmul7vx887j30tjtfgvap5n0g0rf9qqc7znmndrdhe7rwvqkw5c7mqnp4a3yflnvu6kff7l5dungvqmvu6hs";
const EXPECTED_DISPLAYED: &str = "addr1 q90t lskd 4mh5 kncm ul7v x887 j30t jtfg vap5 n0g0 rf9q qc7z nmnd rdhe 7rwv qkw5 c7mq np4a 3yfl nvu6 kff7 l5du ngvq mvu6 hs";
mock_unlocked();
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&pb::CardanoAddressRequest {
network: CardanoNetwork::CardanoMainnet as _,
@@ -617,7 +623,8 @@ mod tests {
&[1852 + HARDENED, 1815 + HARDENED, HARDENED, 2, 0]
)),
}
- )),
+ )
+ .await,
Ok(Response::Pub(pb::PubResponse {
r#pub: EXPECTED.into()
}))
@@ -632,8 +639,8 @@ mod tests {
);
}
- #[test]
- fn test_process_table() {
+ #[async_test::test]
+ async fn test_process_table() {
struct Test<'a> {
keypath_payment: &'a [u32],
keypath_stake: &'a [u32],
@@ -665,7 +672,7 @@ mod tests {
mock_unlocked();
for test in tests {
assert_eq!(
- do_pkh_skh(test.keypath_payment, test.keypath_stake),
+ do_pkh_skh(test.keypath_payment, test.keypath_stake).await,
Ok(Response::Pub(pb::PubResponse {
r#pub: test.expected_address.into()
}))
diff --git a/src/rust/bitbox02-rust/src/hww/api/cardano/sign_transaction.rs b/src/rust/bitbox02-rust/src/hww/api/cardano/sign_transaction.rs
index 2525b7f..80195f1 100644
--- a/src/rust/bitbox02-rust/src/hww/api/cardano/sign_transaction.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/cardano/sign_transaction.rs
@@ -330,7 +330,6 @@ mod tests {
use crate::hal::testing::ui::Screen;
use crate::keystore::testing::mock_unlocked;
use alloc::boxed::Box;
- use util::bb02_async::block_on;
use util::bip32::HARDENED;
use pb::cardano_sign_transaction_request::{Certificate, certificate, certificate::Cert};
@@ -381,8 +380,8 @@ mod tests {
);
}
- #[test]
- fn test_sign_normal_tx() {
+ #[async_test::test]
+ async fn test_sign_normal_tx() {
let tx = pb::CardanoSignTransactionRequest {
network: CardanoNetwork::CardanoMainnet as _,
inputs: vec![pb::cardano_sign_transaction_request::Input {
@@ -433,7 +432,7 @@ mod tests {
mock_unlocked();
let mut mock_hal = TestingHal::new();
- let result = block_on(process(&mut mock_hal, &tx)).unwrap();
+ let result = process(&mut mock_hal, &tx).await.unwrap();
assert_eq!(
result,
Response::SignTransaction(pb::CardanoSignTransactionResponse {
@@ -480,8 +479,8 @@ mod tests {
);
}
- #[test]
- fn test_sign_stake_registration() {
+ #[async_test::test]
+ async fn test_sign_stake_registration() {
let tx = pb::CardanoSignTransactionRequest {
network: CardanoNetwork::CardanoMainnet as _,
inputs: vec![
@@ -535,7 +534,7 @@ mod tests {
mock_unlocked();
let mut mock_hal = TestingHal::new();
- let result = block_on(process(&mut mock_hal, &tx)).unwrap();
+ let result = process(&mut mock_hal, &tx).await.unwrap();
assert_eq!(
result,
Response::SignTransaction(pb::CardanoSignTransactionResponse {
@@ -586,8 +585,8 @@ mod tests {
);
}
- #[test]
- fn test_sign_stake_deregistration() {
+ #[async_test::test]
+ async fn test_sign_stake_deregistration() {
let tx = pb::CardanoSignTransactionRequest {
network: CardanoNetwork::CardanoMainnet as _,
inputs: vec![
@@ -632,7 +631,7 @@ mod tests {
mock_unlocked();
let mut mock_hal = TestingHal::new();
- let result = block_on(process(&mut mock_hal, &tx)).unwrap();
+ let result = process(&mut mock_hal, &tx).await.unwrap();
assert_eq!(
result,
Response::SignTransaction(pb::CardanoSignTransactionResponse {
@@ -678,8 +677,8 @@ mod tests {
);
}
- #[test]
- fn test_sign_vote_delegation() {
+ #[async_test::test]
+ async fn test_sign_vote_delegation() {
let tx = pb::CardanoSignTransactionRequest {
network: CardanoNetwork::CardanoMainnet as _,
inputs: vec![
@@ -722,7 +721,7 @@ mod tests {
mock_unlocked();
let mut mock_hal = TestingHal::new();
- let result = block_on(process(&mut mock_hal, &tx)).unwrap();
+ let result = process(&mut mock_hal, &tx).await.unwrap();
assert_eq!(
result,
Response::SignTransaction(pb::CardanoSignTransactionResponse {
@@ -764,8 +763,8 @@ mod tests {
);
}
- #[test]
- fn test_sign_withdrawal() {
+ #[async_test::test]
+ async fn test_sign_withdrawal() {
let tx = pb::CardanoSignTransactionRequest {
network: CardanoNetwork::CardanoMainnet as _,
inputs: vec![
@@ -803,7 +802,7 @@ mod tests {
mock_unlocked();
let mut mock_hal = TestingHal::new();
- let result = block_on(process(&mut mock_hal, &tx)).unwrap();
+ let result = process(&mut mock_hal, &tx).await.unwrap();
assert_eq!(
result,
Response::SignTransaction(pb::CardanoSignTransactionResponse {
@@ -846,8 +845,8 @@ mod tests {
}
/// Test that ttl=0 is not included in the transaction if allow_ttl_zero is false. Up to v9.8.0, ttl was not included if it was zero.
- #[test]
- fn test_sign_tx_no_ttl() {
+ #[async_test::test]
+ async fn test_sign_tx_no_ttl() {
let tx = pb::CardanoSignTransactionRequest {
network: CardanoNetwork::CardanoMainnet as _,
inputs: vec![pb::cardano_sign_transaction_request::Input {
@@ -880,7 +879,7 @@ mod tests {
};
mock_unlocked();
- let result = block_on(process(&mut TestingHal::new(), &tx)).unwrap();
+ let result = process(&mut TestingHal::new(), &tx).await.unwrap();
assert_eq!(
result,
Response::SignTransaction(pb::CardanoSignTransactionResponse {
@@ -895,8 +894,8 @@ mod tests {
/// Test that ttl=0 is included in the transaction if allow_ttl_zero is true. Up to v9.8.0, ttl was not included if it was zero.
/// ttl=0 also means the transaction cannot be mined.
/// Also test other configurations where the transaction cannot be mined.
- #[test]
- fn test_sign_non_mineable_tx() {
+ #[async_test::test]
+ async fn test_sign_non_mineable_tx() {
let tx = pb::CardanoSignTransactionRequest {
network: CardanoNetwork::CardanoMainnet as _,
inputs: vec![pb::cardano_sign_transaction_request::Input {
@@ -933,7 +932,7 @@ mod tests {
// Second, test with allow_zero_ttl=true, meaning that a zero ttl will be included as 0.
mock_unlocked();
let mut mock_hal = TestingHal::new();
- let result = block_on(process(&mut mock_hal, &tx)).unwrap();
+ let result = process(&mut mock_hal, &tx).await.unwrap();
assert_eq!(
result,
Response::SignTransaction(pb::CardanoSignTransactionResponse {
@@ -973,8 +972,8 @@ mod tests {
);
}
- #[test]
- fn test_sign_tx_valid_interval_start() {
+ #[async_test::test]
+ async fn test_sign_tx_valid_interval_start() {
let tx = pb::CardanoSignTransactionRequest {
network: CardanoNetwork::CardanoMainnet as _,
inputs: vec![pb::cardano_sign_transaction_request::Input {
@@ -1009,7 +1008,7 @@ mod tests {
mock_unlocked();
let mut mock_hal = TestingHal::new();
- assert!(block_on(process(&mut mock_hal, &tx)).is_ok());
+ assert!(process(&mut mock_hal, &tx).await.is_ok());
assert_eq!(
mock_hal.ui.screens[0],
Screen::Confirm {
@@ -1020,8 +1019,8 @@ mod tests {
);
}
- #[test]
- fn test_sign_tx_invalid_interval_start() {
+ #[async_test::test]
+ async fn test_sign_tx_invalid_interval_start() {
let tx = pb::CardanoSignTransactionRequest {
network: CardanoNetwork::CardanoMainnet as _,
inputs: vec![pb::cardano_sign_transaction_request::Input {
@@ -1058,7 +1057,7 @@ mod tests {
mock_unlocked();
let mut mock_hal = TestingHal::new();
- assert!(block_on(process(&mut mock_hal, &tx)).is_ok());
+ assert!(process(&mut mock_hal, &tx).await.is_ok());
assert_eq!(
mock_hal.ui.screens[0],
Screen::Confirm {
@@ -1069,8 +1068,8 @@ mod tests {
);
}
- #[test]
- fn test_sign_tx_tokens() {
+ #[async_test::test]
+ async fn test_sign_tx_tokens() {
let tx = pb::CardanoSignTransactionRequest {
network: CardanoNetwork::CardanoMainnet as _,
inputs: vec![pb::cardano_sign_transaction_request::Input {
@@ -1138,7 +1137,7 @@ mod tests {
mock_unlocked();
let mut mock_hal = TestingHal::new();
- let result = block_on(process(&mut mock_hal, &tx)).unwrap();
+ let result = process(&mut mock_hal, &tx).await.unwrap();
assert_eq!(
result,
Response::SignTransaction(pb::CardanoSignTransactionResponse {
@@ -1189,8 +1188,8 @@ mod tests {
}
// Test a transaction with an unusually high fee.
- #[test]
- fn test_high_fee_warning() {
+ #[async_test::test]
+ async fn test_high_fee_warning() {
let tx = pb::CardanoSignTransactionRequest {
network: CardanoNetwork::CardanoMainnet as _,
inputs: vec![pb::cardano_sign_transaction_request::Input {
@@ -1225,7 +1224,7 @@ mod tests {
mock_unlocked();
let mut mock_hal = TestingHal::new();
- assert!(block_on(process(&mut mock_hal, &tx)).is_ok());
+ assert!(process(&mut mock_hal, &tx).await.is_ok());
assert!(
mock_hal
.ui
@@ -1233,8 +1232,8 @@ mod tests {
);
}
- #[test]
- fn test_sign_tx_tag_cbor_sets() {
+ #[async_test::test]
+ async fn test_sign_tx_tag_cbor_sets() {
let tx = pb::CardanoSignTransactionRequest {
network: CardanoNetwork::CardanoMainnet as _,
inputs: vec![pb::cardano_sign_transaction_request::Input {
@@ -1267,7 +1266,7 @@ mod tests {
..Default::default()
};
mock_unlocked();
- let result = block_on(process(&mut TestingHal::new(), &tx)).unwrap();
+ let result = process(&mut TestingHal::new(), &tx).await.unwrap();
assert_eq!(
result,
Response::SignTransaction(pb::CardanoSignTransactionResponse {
diff --git a/src/rust/bitbox02-rust/src/hww/api/change_password.rs b/src/rust/bitbox02-rust/src/hww/api/change_password.rs
index 5c487ed..c3e3f6b 100644
--- a/src/rust/bitbox02-rust/src/hww/api/change_password.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/change_password.rs
@@ -44,24 +44,23 @@ mod tests {
use alloc::boxed::Box;
use bitbox02::testing::mock_memory;
use hex_lit::hex;
- use util::bb02_async::block_on;
// Test the intended success path
- #[test]
- fn test_process_success() {
+ #[async_test::test]
+ async fn test_process_success() {
//set up dummy (initialized, retained seed and bip39-seed)
mock_memory();
let seed = hex!("c7940c13479b8d9a6498f4e50d5a42e0d617bc8e8ac9f2b8cecf97e94c2b035c");
let old_password = "old_password";
let new_password = "new_password";
+ let mut prompt_counter = 0u32;
let mut hal = TestingHal::new();
keystore::encrypt_and_store_seed(&mut hal, &seed, old_password).unwrap();
- block_on(unlock::unlock_bip39(&mut hal, &seed));
+ unlock::unlock_bip39(&mut hal, &seed).await;
hal.memory.set_initialized().unwrap();
// Allow exactly 3 prompts
- let mut prompt_counter = 0u32;
hal.ui.set_enter_string(Box::new(|params| {
prompt_counter += 1;
match prompt_counter {
@@ -83,7 +82,7 @@ mod tests {
// reset the chip counter
hal.securechip.event_counter_reset();
// call process
- let result = block_on(process(&mut hal));
+ let result = process(&mut hal).await;
// assert success
assert_eq!(result, Ok(Response::Success(pb::Success {})));
// assert correct screens
@@ -111,12 +110,13 @@ mod tests {
// check that the old password is no longer valid
keystore::lock();
assert!(matches!(
- block_on(keystore::unlock(&mut hal, old_password)),
+ keystore::unlock(&mut hal, old_password).await,
Err(keystore::Error::IncorrectPassword)
));
// check that the new password is valid
assert_eq!(
- block_on(keystore::unlock(&mut hal, new_password))
+ keystore::unlock(&mut hal, new_password)
+ .await
.unwrap()
.as_slice(),
seed.as_slice()
@@ -127,20 +127,20 @@ mod tests {
}
// Test that we fail if the unlock fails
- #[test]
- fn test_process_unlock_failure() {
+ #[async_test::test]
+ async fn test_process_unlock_failure() {
mock_memory();
let seed = hex!("c7940c13479b8d9a6498f4e50d5a42e0d617bc8e8ac9f2b8cecf97e94c2b035c");
let correct_password = "correct_password";
+ let mut prompt_counter = 0u32;
let mut hal = TestingHal::new();
keystore::encrypt_and_store_seed(&mut hal, &seed, correct_password).unwrap();
- block_on(unlock::unlock_bip39(&mut hal, &seed));
+ unlock::unlock_bip39(&mut hal, &seed).await;
hal.memory.set_initialized().unwrap();
keystore::lock();
- let mut prompt_counter = 0u32;
hal.ui.set_enter_string(Box::new(|params| {
prompt_counter += 1;
assert_eq!(params.title, "Unlock device");
@@ -148,7 +148,7 @@ mod tests {
}));
hal.securechip.event_counter_reset();
- let result = block_on(process(&mut hal));
+ let result = process(&mut hal).await;
assert_eq!(result, Err(Error::Generic));
assert_eq!(
@@ -170,7 +170,8 @@ mod tests {
// check that the old password is still valid
assert_eq!(
- block_on(keystore::unlock(&mut hal, correct_password))
+ keystore::unlock(&mut hal, correct_password)
+ .await
.unwrap()
.as_slice(),
seed.as_slice()
@@ -181,8 +182,8 @@ mod tests {
}
// Test that we fail if the confirm password mismatch
- #[test]
- fn test_process_confirm_password_mismatch() {
+ #[async_test::test]
+ async fn test_process_confirm_password_mismatch() {
mock_memory();
let seed = hex!("c7940c13479b8d9a6498f4e50d5a42e0d617bc8e8ac9f2b8cecf97e94c2b035c");
@@ -190,13 +191,13 @@ mod tests {
let first_password = "first_password";
let second_password = "mismatch";
+ let mut prompt_counter = 0u32;
let mut hal = TestingHal::new();
keystore::encrypt_and_store_seed(&mut hal, &seed, old_password).unwrap();
- block_on(unlock::unlock_bip39(&mut hal, &seed));
+ unlock::unlock_bip39(&mut hal, &seed).await;
hal.memory.set_initialized().unwrap();
keystore::lock();
- let mut prompt_counter = 0u32;
hal.ui.set_enter_string(Box::new(|params| {
prompt_counter += 1;
match prompt_counter {
@@ -215,12 +216,13 @@ mod tests {
_ => panic!("unexpected password prompt"),
}
}));
- let result = block_on(process(&mut hal));
+ let result = process(&mut hal).await;
assert_eq!(result, Err(Error::Generic));
// check that the old password is still valid
assert_eq!(
- block_on(keystore::unlock(&mut hal, old_password))
+ keystore::unlock(&mut hal, old_password)
+ .await
.unwrap()
.as_slice(),
seed.as_slice()
diff --git a/src/rust/bitbox02-rust/src/hww/api/electrum.rs b/src/rust/bitbox02-rust/src/hww/api/electrum.rs
index b62326d..498d035 100644
--- a/src/rust/bitbox02-rust/src/hww/api/electrum.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/electrum.rs
@@ -43,20 +43,19 @@ mod tests {
use crate::keystore::testing::mock_unlocked;
use alloc::boxed::Box;
- use util::bb02_async::block_on;
- #[test]
- pub fn test_process() {
+ #[async_test::test]
+ pub async fn test_process() {
mock_unlocked();
// All good.
assert_eq!(
- block_on(process(&mut crate::hal::testing::TestingHal::new(),&pb::ElectrumEncryptionKeyRequest {
+ process(&mut crate::hal::testing::TestingHal::new(),&pb::ElectrumEncryptionKeyRequest {
keypath: vec![
ELECTRUM_WALLET_ENCRYPTION_KEYPATH_LEVEL_ONE,
ELECTRUM_WALLET_ENCRYPTION_KEYPATH_LEVEL_TWO
]
- })),
+ }).await,
Ok(Response::ElectrumEncryptionKey(
pb::ElectrumEncryptionKeyResponse {
key: "xpub6AWqZzUWTTxAzVFXAavh7oX2apTkQAnjX9FU5pUMMjHiFzHLGLVWx9tAVvocV8c2WeoL7sUj2gZmdp3rDWaqmugZdSCYQVHCxCsVajQP7Cx".into()
@@ -66,18 +65,19 @@ mod tests {
// Invalid keypath.
assert_eq!(
- block_on(process(
+ process(
&mut crate::hal::testing::TestingHal::new(),
&pb::ElectrumEncryptionKeyRequest {
keypath: vec![ELECTRUM_WALLET_ENCRYPTION_KEYPATH_LEVEL_ONE, 0]
}
- )),
+ )
+ .await,
Err(Error::InvalidInput),
);
// Invalid keypath (wrong length).
assert_eq!(
- block_on(process(
+ process(
&mut crate::hal::testing::TestingHal::new(),
&pb::ElectrumEncryptionKeyRequest {
keypath: vec![
@@ -86,7 +86,8 @@ mod tests {
0
]
}
- )),
+ )
+ .await,
Err(Error::InvalidInput),
);
}
diff --git a/src/rust/bitbox02-rust/src/hww/api/ethereum/pubrequest.rs b/src/rust/bitbox02-rust/src/hww/api/ethereum/pubrequest.rs
index 921c152..eff4a57 100644
--- a/src/rust/bitbox02-rust/src/hww/api/ethereum/pubrequest.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/ethereum/pubrequest.rs
@@ -92,11 +92,10 @@ mod tests {
use crate::keystore::testing::mock_unlocked;
use alloc::boxed::Box;
use hex_lit::hex;
- use util::bb02_async::block_on;
use util::bip32::HARDENED;
- #[test]
- pub fn test_process_xpub() {
+ #[async_test::test]
+ pub async fn test_process_xpub() {
const EXPECTED_XPUB: &str = "xpub6FNKHYBc1HTwuwZcj4dz7xiG1kN7Hs3v7efYmgtzu1Gv6wJXxaCnFdQDRodbQpJKwdeVBf1RRNHARa6FsUMTCuRe2gKR7xCkSDdnppUp9oW";
let request = pb::EthPubRequest {
output_type: OutputType::Xpub as _,
@@ -110,7 +109,7 @@ mod tests {
// All good.
mock_unlocked();
assert_eq!(
- block_on(process(&mut TestingHal::new(), &request)),
+ process(&mut TestingHal::new(), &request).await,
Ok(Response::Pub(pb::PubResponse {
r#pub: EXPECTED_XPUB.into()
}))
@@ -120,20 +119,20 @@ mod tests {
let mut invalid_request = request.clone();
invalid_request.keypath[1] = 61 + HARDENED;
assert_eq!(
- block_on(process(&mut TestingHal::new(), &invalid_request)),
+ process(&mut TestingHal::new(), &invalid_request).await,
Err(Error::InvalidInput)
);
// xpub fetching/encoding failed.
keystore::lock();
assert_eq!(
- block_on(process(&mut TestingHal::new(), &request)),
+ process(&mut TestingHal::new(), &request).await,
Err(Error::InvalidInput)
);
}
- #[test]
- pub fn test_process_address() {
+ #[async_test::test]
+ pub async fn test_process_address() {
const ADDRESS: &str = "0x773A77b9D32589be03f9132AF759e294f7851be9";
const DISPLAY_ADDRESS: &str = "0x 773A 77b9 D325 89be 03f9 132A F759 e294 f785 1be9";
@@ -149,7 +148,7 @@ mod tests {
// All good.
mock_unlocked();
assert_eq!(
- block_on(process(&mut TestingHal::new(), &request)),
+ process(&mut TestingHal::new(), &request).await,
Ok(Response::Pub(pb::PubResponse {
r#pub: ADDRESS.into()
}))
@@ -159,7 +158,7 @@ mod tests {
mock_unlocked();
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&pb::EthPubRequest {
output_type: OutputType::Address as _,
@@ -169,7 +168,8 @@ mod tests {
contract_address: b"".to_vec(),
chain_id: 0,
}
- )),
+ )
+ .await,
Ok(Response::Pub(pb::PubResponse {
r#pub: ADDRESS.into()
}))
@@ -187,7 +187,7 @@ mod tests {
mock_unlocked();
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&pb::EthPubRequest {
output_type: OutputType::Address as _,
@@ -197,7 +197,8 @@ mod tests {
contract_address: b"".to_vec(),
chain_id: 11155111,
}
- )),
+ )
+ .await,
Ok(Response::Pub(pb::PubResponse {
r#pub: ADDRESS.into()
}))
@@ -221,7 +222,7 @@ mod tests {
// Keystore locked.
keystore::lock();
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&pb::EthPubRequest {
output_type: OutputType::Address as _,
@@ -231,7 +232,8 @@ mod tests {
contract_address: b"".to_vec(),
chain_id: 0,
}
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
@@ -239,7 +241,7 @@ mod tests {
let mut invalid_request = request.clone();
invalid_request.coin = 100;
assert_eq!(
- block_on(process(&mut TestingHal::new(), &invalid_request)),
+ process(&mut TestingHal::new(), &invalid_request).await,
Err(Error::InvalidInput)
);
@@ -247,13 +249,13 @@ mod tests {
let mut invalid_request = request.clone();
invalid_request.keypath[1] = 61 + HARDENED;
assert_eq!(
- block_on(process(&mut TestingHal::new(), &invalid_request)),
+ process(&mut TestingHal::new(), &invalid_request).await,
Err(Error::InvalidInput)
);
// Wrong keypath (account too high)
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&pb::EthPubRequest {
output_type: OutputType::Address as _,
@@ -263,13 +265,14 @@ mod tests {
contract_address: b"".to_vec(),
chain_id: 0,
}
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
}
- #[test]
- pub fn test_process_erc20_address() {
+ #[async_test::test]
+ pub async fn test_process_erc20_address() {
const ADDRESS: &str = "0x773A77b9D32589be03f9132AF759e294f7851be9";
const DISPLAY_ADDRESS: &str = "0x 773A 77b9 D325 89be 03f9 132A F759 e294 f785 1be9";
const CONTRACT_ADDRESS: [u8; 20] = hex!("dac17f958d2ee523a2206206994597c13d831ec7");
@@ -286,7 +289,7 @@ mod tests {
// All good.
mock_unlocked();
assert_eq!(
- block_on(process(&mut TestingHal::new(), &request)),
+ process(&mut TestingHal::new(), &request).await,
Ok(Response::Pub(pb::PubResponse {
r#pub: ADDRESS.into()
}))
@@ -296,7 +299,7 @@ mod tests {
mock_unlocked();
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&pb::EthPubRequest {
output_type: OutputType::Address as _,
@@ -306,7 +309,8 @@ mod tests {
contract_address: CONTRACT_ADDRESS.to_vec(),
chain_id: 0,
}
- )),
+ )
+ .await,
Ok(Response::Pub(pb::PubResponse {
r#pub: ADDRESS.into()
}))
@@ -322,7 +326,7 @@ mod tests {
// ERC20 params not found / invalid contract address.
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&pb::EthPubRequest {
output_type: OutputType::Address as _,
@@ -332,7 +336,8 @@ mod tests {
contract_address: b"aaaaaaaaaaaaaaaaaaaa".to_vec(),
chain_id: 0,
}
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
}
diff --git a/src/rust/bitbox02-rust/src/hww/api/ethereum/sighash.rs b/src/rust/bitbox02-rust/src/hww/api/ethereum/sighash.rs
index e665c3f..a96c9cb 100644
--- a/src/rust/bitbox02-rust/src/hww/api/ethereum/sighash.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/ethereum/sighash.rs
@@ -356,7 +356,6 @@ pub mod tests {
use alloc::boxed::Box;
use alloc::string::String;
use serde::Deserialize;
- use util::bb02_async::block_on;
pub fn setup_chunk_responder(data: Vec<u8>) {
*crate::hww::MOCK_NEXT_REQUEST.0.borrow_mut() = Some(Box::new(
@@ -413,8 +412,8 @@ pub mod tests {
const DATA_THRESHOLD: usize = 6144;
- #[test]
- fn test_compute_eip1559() {
+ #[async_test::test]
+ async fn test_compute_eip1559() {
let json_data = include_str!("testdata/eip1559_tests.json");
let tests: Vec<Eip1559TestCase> = serde_json::from_str(json_data).unwrap();
@@ -440,7 +439,7 @@ pub mod tests {
value: &value,
data: &mut producer,
};
- let result = block_on(compute_eip1559(&mut params)).unwrap();
+ let result = compute_eip1559(&mut params).await.unwrap();
assert_eq!(
result, expected_sighash,
"EIP1559 test {} failed (ChunkingProducer::from_data)",
@@ -459,7 +458,7 @@ pub mod tests {
value: &value,
data: &mut producer,
};
- let result = block_on(compute_eip1559(&mut params)).unwrap();
+ let result = compute_eip1559(&mut params).await.unwrap();
assert_eq!(
result, expected_sighash,
"EIP1559 test {} failed (ChunkingProducer::from_host)",
@@ -470,8 +469,8 @@ pub mod tests {
}
}
- #[test]
- fn test_compute_legacy() {
+ #[async_test::test]
+ async fn test_compute_legacy() {
let json_data = include_str!("testdata/legacy_tests.json");
let tests: Vec<LegacyTestCase> = serde_json::from_str(json_data).unwrap();
@@ -495,7 +494,7 @@ pub mod tests {
data: &mut producer,
chain_id: test.chain_id,
};
- let result = block_on(compute_legacy(&mut params)).unwrap();
+ let result = compute_legacy(&mut params).await.unwrap();
assert_eq!(
result, expected_sighash,
"Legacy test {} failed (ChunkingProducer::from_data)",
@@ -513,7 +512,7 @@ pub mod tests {
data: &mut producer,
chain_id: test.chain_id,
};
- let result = block_on(compute_legacy(&mut params)).unwrap();
+ let result = compute_legacy(&mut params).await.unwrap();
assert_eq!(
result, expected_sighash,
"Legacy test {} failed (ChunkingProducer::from_host)",
@@ -524,53 +523,53 @@ pub mod tests {
}
}
- #[test]
- fn test_chunking_producer_inline_empty() {
+ #[async_test::test]
+ async fn test_chunking_producer_inline_empty() {
let mut producer = ChunkingProducer::from_data(&[]);
assert_eq!(producer.len(), 0);
- let chunk = block_on(producer.next());
+ let chunk = producer.next().await;
assert_eq!(chunk, Ok(Some(vec![])));
- let chunk2 = block_on(producer.next());
+ let chunk2 = producer.next().await;
assert_eq!(chunk2, Ok(None));
}
- #[test]
- fn test_chunking_producer_inline_single_byte() {
+ #[async_test::test]
+ async fn test_chunking_producer_inline_single_byte() {
let mut producer = ChunkingProducer::from_data(&[0x42]);
assert_eq!(producer.len(), 1);
- assert_eq!(block_on(producer.first_byte()).unwrap(), 0x42);
+ assert_eq!(producer.first_byte().await.unwrap(), 0x42);
- let chunk = block_on(producer.next());
+ let chunk = producer.next().await;
assert_eq!(chunk, Ok(Some(vec![0x42])));
- let chunk2 = block_on(producer.next());
+ let chunk2 = producer.next().await;
assert_eq!(chunk2, Ok(None));
}
- #[test]
- fn test_chunking_producer_inline_4096_bytes() {
+ #[async_test::test]
+ async fn test_chunking_producer_inline_4096_bytes() {
let data = vec![0xAB; 4096];
let mut producer = ChunkingProducer::from_data(&data);
assert_eq!(producer.len(), 4096);
- assert_eq!(block_on(producer.first_byte()).unwrap(), 0xAB);
+ assert_eq!(producer.first_byte().await.unwrap(), 0xAB);
- let chunk = block_on(producer.next());
+ let chunk = producer.next().await;
assert_eq!(chunk, Ok(Some(data.clone())));
- let chunk2 = block_on(producer.next());
+ let chunk2 = producer.next().await;
assert_eq!(chunk2, Ok(None));
}
- #[test]
- fn test_chunking_producer_inline_10kb() {
+ #[async_test::test]
+ async fn test_chunking_producer_inline_10kb() {
let data = vec![0xCD; 10000];
let mut producer = ChunkingProducer::from_data(&data);
assert_eq!(producer.len(), 10000);
- assert_eq!(block_on(producer.first_byte()).unwrap(), 0xCD);
+ assert_eq!(producer.first_byte().await.unwrap(), 0xCD);
- let chunk = block_on(producer.next());
+ let chunk = producer.next().await;
assert_eq!(chunk, Ok(Some(data)));
}
@@ -582,61 +581,61 @@ pub mod tests {
assert_eq!(ChunkingProducer::from_host(10000).len(), 10000);
}
- #[test]
- fn test_chunking_producer_single_chunk() {
+ #[async_test::test]
+ async fn test_chunking_producer_single_chunk() {
let data = vec![0xAB; 100];
setup_chunk_responder(data.clone());
let mut producer = ChunkingProducer::from_host(100);
assert_eq!(producer.len(), 100);
- let chunk = block_on(producer.next()).unwrap();
+ let chunk = producer.next().await.unwrap();
assert_eq!(chunk, Some(data));
- assert_eq!(block_on(producer.first_byte()).unwrap(), 0xAB);
+ assert_eq!(producer.first_byte().await.unwrap(), 0xAB);
- let chunk2 = block_on(producer.next()).unwrap();
+ let chunk2 = producer.next().await.unwrap();
assert_eq!(chunk2, None);
clear_chunk_responder();
}
- #[test]
- fn test_chunking_producer_multiple_chunks() {
+ #[async_test::test]
+ async fn test_chunking_producer_multiple_chunks() {
let data = vec![0xCD; 10000];
setup_chunk_responder(data);
let mut producer = ChunkingProducer::from_host(10000);
assert_eq!(producer.len(), 10000);
- let chunk1 = block_on(producer.next()).unwrap().unwrap();
+ let chunk1 = producer.next().await.unwrap().unwrap();
assert_eq!(chunk1.len(), 4096);
- let chunk2 = block_on(producer.next()).unwrap().unwrap();
+ let chunk2 = producer.next().await.unwrap().unwrap();
assert_eq!(chunk2.len(), 4096);
- let chunk3 = block_on(producer.next()).unwrap().unwrap();
+ let chunk3 = producer.next().await.unwrap().unwrap();
assert_eq!(chunk3.len(), 1808);
- let chunk4 = block_on(producer.next()).unwrap();
+ let chunk4 = producer.next().await.unwrap();
assert_eq!(chunk4, None);
clear_chunk_responder();
}
- #[test]
- fn test_chunking_producer_first_byte_before_next() {
+ #[async_test::test]
+ async fn test_chunking_producer_first_byte_before_next() {
let data = vec![0xEF];
setup_chunk_responder(data);
let mut producer = ChunkingProducer::from_host(1);
assert_eq!(producer.len(), 1);
- assert_eq!(block_on(producer.first_byte()).unwrap(), 0xEF);
+ assert_eq!(producer.first_byte().await.unwrap(), 0xEF);
- let chunk = block_on(producer.next()).unwrap();
+ let chunk = producer.next().await.unwrap();
assert_eq!(chunk, Some(vec![0xEF]));
- let chunk2 = block_on(producer.next()).unwrap();
+ let chunk2 = producer.next().await.unwrap();
assert_eq!(chunk2, None);
clear_chunk_responder();
diff --git a/src/rust/bitbox02-rust/src/hww/api/ethereum/sign.rs b/src/rust/bitbox02-rust/src/hww/api/ethereum/sign.rs
index 0cf43af..a8e114b 100644
--- a/src/rust/bitbox02-rust/src/hww/api/ethereum/sign.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/ethereum/sign.rs
@@ -593,7 +593,6 @@ mod tests {
use crate::hal::testing::ui::Screen;
use crate::keystore::testing::mock_unlocked;
use alloc::boxed::Box;
- use util::bb02_async::block_on;
use util::bip32::HARDENED;
use super::super::super::payment_request;
@@ -710,8 +709,8 @@ mod tests {
}
/// Standard ETH transaction with no data field.
- #[test]
- pub fn test_process_standard_transaction() {
+ #[async_test::test]
+ pub async fn test_process_standard_transaction() {
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
mock_unlocked();
@@ -738,7 +737,7 @@ mod tests {
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(&mut mock_hal, &Transaction::Legacy(&pb::EthSignRequest {
+ process(&mut mock_hal, &Transaction::Legacy(&pb::EthSignRequest {
coin: pb::EthCoin::Eth as _,
keypath: KEYPATH.to_vec(),
nonce: hex!("1fdc").to_vec(),
@@ -751,7 +750,7 @@ mod tests {
chain_id: 0,
address_case: pb::EthAddressCase::Mixed as _,
data_length: 0,
- }))),
+ })).await,
Ok(Response::Sign(pb::EthSignResponse {
signature: hex!("c3ae24c167e216cfb75c72b5e03ef97acc2b607f3acf63865f80960f76f656470f8e23f1d2788fb0070e28c2a5c8aaf15b5dbf30b40907ff6c5068fdcbc11a2d00")
.to_vec()
@@ -761,7 +760,7 @@ mod tests {
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(&mut mock_hal, &Transaction::Eip1559(&pb::EthSignEip1559Request {
+ process(&mut mock_hal, &Transaction::Eip1559(&pb::EthSignEip1559Request {
keypath: KEYPATH.to_vec(),
nonce: hex!("1fdc").to_vec(),
max_priority_fee_per_gas: b"".to_vec(),
@@ -775,7 +774,7 @@ mod tests {
address_case: pb::EthAddressCase::Mixed as _,
data_length: 0,
payment_request: None,
- }))),
+ })).await,
Ok(Response::Sign(pb::EthSignResponse {
signature: hex!("289111770dc067895780de3e9b30454e331ba6661f046e9e26431576d7f08a496ffe6deffb07dd8d4713d8c523b6c33b53dd6ef2dc9c394d6e21f64307d2bcf001")
.to_vec()
@@ -785,15 +784,15 @@ mod tests {
}
/// Test a transaction with an unusually high fee.
- #[test]
- fn test_high_fee_warning() {
+ #[async_test::test]
+ async fn test_high_fee_warning() {
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
mock_unlocked();
let mut mock_hal = TestingHal::new();
assert!(
- block_on(process(
+ process(
&mut mock_hal,
&Transaction::Legacy(&pb::EthSignRequest {
coin: pb::EthCoin::Eth as _,
@@ -811,7 +810,8 @@ mod tests {
address_case: pb::EthAddressCase::Mixed as _,
data_length: 0,
})
- ))
+ )
+ .await
.is_ok()
);
@@ -846,14 +846,14 @@ mod tests {
}
/// Test an EIP-1559 transaction with an unusually high fee.
- #[test]
- fn test_high_fee_warning_eip1559() {
+ #[async_test::test]
+ async fn test_high_fee_warning_eip1559() {
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
mock_unlocked();
let mut mock_hal = TestingHal::new();
assert!(
- block_on(process(
+ process(
&mut mock_hal,
&Transaction::Eip1559(&pb::EthSignEip1559Request {
keypath: KEYPATH.to_vec(),
@@ -872,7 +872,8 @@ mod tests {
data_length: 0,
payment_request: None,
})
- ))
+ )
+ .await
.is_ok()
);
@@ -907,13 +908,13 @@ mod tests {
}
/// Standard ETH transaction on an unusual keypath (Sepolia on mainnet keypath)
- #[test]
- pub fn test_process_warn_unusual_keypath() {
+ #[async_test::test]
+ pub async fn test_process_warn_unusual_keypath() {
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
mock_unlocked();
let mut mock_hal = TestingHal::new();
- block_on(process(
+ process(
&mut mock_hal,
&Transaction::Legacy(&pb::EthSignRequest {
coin: pb::EthCoin::Eth as _,
@@ -929,7 +930,8 @@ mod tests {
address_case: pb::EthAddressCase::Mixed as _,
data_length: 0,
}),
- ))
+ )
+ .await
.unwrap();
assert_eq!(
@@ -963,14 +965,14 @@ mod tests {
}
/// Standard ETH transaction with an unknown data field.
- #[test]
- pub fn test_process_standard_transaction_with_data() {
+ #[async_test::test]
+ pub async fn test_process_standard_transaction_with_data() {
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
mock_unlocked();
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(&mut mock_hal, &Transaction::Legacy(&pb::EthSignRequest {
+ process(&mut mock_hal, &Transaction::Legacy(&pb::EthSignRequest {
coin: pb::EthCoin::Eth as _,
keypath: KEYPATH.to_vec(),
nonce: hex!("1fdc").to_vec(),
@@ -983,7 +985,7 @@ mod tests {
chain_id: 0,
address_case: pb::EthAddressCase::Mixed as _,
data_length: 0,
- }))),
+ })).await,
Ok(Response::Sign(pb::EthSignResponse {
signature: hex!("7d3f3713e3cf1082791d5c0fc68ec29eaff5e1ee8467a8ec547dc796e85a79042b7c01692fb72f5576ab50dcaa621ad1eeabd9975973b86256f40c6f8550ef4400")
.to_vec()
@@ -1030,14 +1032,14 @@ mod tests {
}
/// EIP-1559 ETH transaction with an unknown data field.
- #[test]
- pub fn test_process_eip1559_transaction_with_data() {
+ #[async_test::test]
+ pub async fn test_process_eip1559_transaction_with_data() {
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
mock_unlocked();
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(&mut mock_hal, &Transaction::Eip1559(&pb::EthSignEip1559Request {
+ process(&mut mock_hal, &Transaction::Eip1559(&pb::EthSignEip1559Request {
keypath: KEYPATH.to_vec(),
nonce: hex!("1fdc").to_vec(),
max_priority_fee_per_gas: hex!("3b9aca00").to_vec(),
@@ -1051,7 +1053,7 @@ mod tests {
address_case: pb::EthAddressCase::Mixed as _,
data_length: 0,
payment_request: None,
- }))),
+ })).await,
Ok(Response::Sign(pb::EthSignResponse {
signature: hex!("c5d9639a778a3415f63a11c03a58bede6b3cafff4f2ce6ea16411e76fba946f72166f09e313c07e78b7b1fff87450c4321170c02df2d36c44c3a021abf20546001")
.to_vec()
@@ -1097,14 +1099,14 @@ mod tests {
);
}
- #[test]
- fn test_process_eip1559_payment_request_invalid_contract_shape() {
+ #[async_test::test]
+ async fn test_process_eip1559_payment_request_invalid_contract_shape() {
// Payment requests only support plain ETH transfers or standard ERC20 transfers.
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&Transaction::Eip1559(&pb::EthSignEip1559Request {
keypath: KEYPATH.to_vec(),
@@ -1121,7 +1123,8 @@ mod tests {
data_length: 0,
payment_request: Some(Default::default()),
}),
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
assert_eq!(
@@ -1134,8 +1137,8 @@ mod tests {
);
}
- #[test]
- fn test_process_eip1559_payment_request_plain_eth() {
+ #[async_test::test]
+ async fn test_process_eip1559_payment_request_plain_eth() {
// Native ETH swaps use the tx recipient/value as the signed source-side output.
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
@@ -1189,7 +1192,7 @@ mod tests {
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&Transaction::Eip1559(&pb::EthSignEip1559Request {
keypath: KEYPATH.to_vec(),
@@ -1206,7 +1209,7 @@ mod tests {
data_length: 0,
payment_request: Some(payment_request),
}),
- )),
+ ).await,
Ok(Response::Sign(pb::EthSignResponse {
signature: hex!("289111770dc067895780de3e9b30454e331ba6661f046e9e26431576d7f08a496ffe6deffb07dd8d4713d8c523b6c33b53dd6ef2dc9c394d6e21f64307d2bcf001")
.to_vec()
@@ -1215,8 +1218,8 @@ mod tests {
assert_eq!(mock_hal.ui.screens, expected_screens);
}
- #[test]
- fn test_process_eip1559_payment_request_known_erc20() {
+ #[async_test::test]
+ async fn test_process_eip1559_payment_request_known_erc20() {
// Known ERC20 swaps decode the transfer recipient/amount and show the token unit.
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
// function selector + recipient address (left padded) + token amount
@@ -1269,7 +1272,7 @@ mod tests {
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&Transaction::Eip1559(&pb::EthSignEip1559Request {
keypath: KEYPATH.to_vec(),
@@ -1286,7 +1289,7 @@ mod tests {
data_length: 0,
payment_request: Some(payment_request),
}),
- )),
+ ).await,
Ok(Response::Sign(pb::EthSignResponse {
signature: hex!("3162487880abdea1f352d9a4e3d56066f122f04ff112117c8ca3cd220f1666302dacd5e5e8da4cd39704e33443a9a7f32602d332bb52567c2e34aafe9ed48feb01")
.to_vec()
@@ -1297,8 +1300,8 @@ mod tests {
/// ERC20 transaction: recipient is an ERC20 contract address, and
/// the data field contains an ERC20 transfer method invocation.
- #[test]
- pub fn test_process_standard_erc20_transaction() {
+ #[async_test::test]
+ pub async fn test_process_standard_erc20_transaction() {
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
let expected_screens = vec![
@@ -1325,7 +1328,7 @@ mod tests {
mock_unlocked();
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(&mut mock_hal, &Transaction::Legacy(&pb::EthSignRequest {
+ process(&mut mock_hal, &Transaction::Legacy(&pb::EthSignRequest {
coin: pb::EthCoin::RopstenEth as _, // ignored because chain_id > 0
keypath: KEYPATH.to_vec(),
nonce: hex!("2367").to_vec(),
@@ -1338,7 +1341,7 @@ mod tests {
chain_id: 1,
address_case: pb::EthAddressCase::Mixed as _,
data_length: 0,
- }))),
+ })).await,
Ok(Response::Sign(pb::EthSignResponse {
signature: hex!("674e9a0170eee0ca8c406ec9a7df2e3a6bdd179cf69385800e1fd378e7cfb19c4d55162c547b04d1818e43901691aec988ef75cd67d9bb301d14902fd6e6929201")
.to_vec()
@@ -1348,7 +1351,7 @@ mod tests {
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(&mut mock_hal, &Transaction::Eip1559(&pb::EthSignEip1559Request {
+ process(&mut mock_hal, &Transaction::Eip1559(&pb::EthSignEip1559Request {
keypath: KEYPATH.to_vec(),
nonce: hex!("2367").to_vec(),
max_priority_fee_per_gas: hex!("3b9aca00").to_vec(),
@@ -1362,7 +1365,7 @@ mod tests {
address_case: pb::EthAddressCase::Mixed as _,
data_length: 0,
payment_request: None,
- }))),
+ })).await,
Ok(Response::Sign(pb::EthSignResponse {
signature: hex!("3162487880abdea1f352d9a4e3d56066f122f04ff112117c8ca3cd220f1666302dacd5e5e8da4cd39704e33443a9a7f32602d332bb52567c2e34aafe9ed48feb01")
.to_vec()
@@ -1372,8 +1375,8 @@ mod tests {
}
/// An ERC20 transaction which is not in our list of supported ERC20 tokens.
- #[test]
- pub fn test_process_standard_unknown_erc20_transaction() {
+ #[async_test::test]
+ pub async fn test_process_standard_unknown_erc20_transaction() {
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
let expected_screens = vec![
@@ -1399,7 +1402,7 @@ mod tests {
mock_unlocked();
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(&mut mock_hal, &Transaction::Legacy(&pb::EthSignRequest {
+ process(&mut mock_hal, &Transaction::Legacy(&pb::EthSignRequest {
coin: pb::EthCoin::Eth as _,
keypath: KEYPATH.to_vec(),
nonce: hex!("b9").to_vec(),
@@ -1412,7 +1415,7 @@ mod tests {
chain_id: 0,
address_case: pb::EthAddressCase::Mixed as _,
data_length: 0,
- }))),
+ })).await,
Ok(Response::Sign(pb::EthSignResponse {
signature: hex!("ec6e530c8ee25434fc440e9ac0f888e9c63cf07ebcf1c2f8a83e2e8c39832c551512716f6e1a8b66ce3811a726bcb244664ef26f98ee35c0c9db4caab073985600")
.to_vec()
@@ -1422,7 +1425,7 @@ mod tests {
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(&mut mock_hal, &Transaction::Eip1559(&pb::EthSignEip1559Request {
+ process(&mut mock_hal, &Transaction::Eip1559(&pb::EthSignEip1559Request {
keypath: KEYPATH.to_vec(),
nonce: hex!("b9").to_vec(),
max_priority_fee_per_gas: b"".to_vec(),
@@ -1436,7 +1439,7 @@ mod tests {
address_case: pb::EthAddressCase::Mixed as _,
data_length: 0,
payment_request: None,
- }))),
+ })).await,
Ok(Response::Sign(pb::EthSignResponse {
signature: hex!("8203d80b600dce8e77cdcb119d45db7f60d7ca34e7369140e92d93919221f85a0a119d2464dfab65833095c12763fed37c072feb29610e1437f388958d77562801")
.to_vec()
@@ -1445,8 +1448,8 @@ mod tests {
assert_eq!(mock_hal.ui.screens, expected_screens);
}
- #[test]
- pub fn test_process_unhappy() {
+ #[async_test::test]
+ pub async fn test_process_unhappy() {
let valid_request = pb::EthSignRequest {
coin: pb::EthCoin::Eth as _,
keypath: vec![44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0],
@@ -1466,11 +1469,9 @@ mod tests {
// Check that the above is valid before making invalid variants.
mock_unlocked();
assert!(
- block_on(process(
- &mut TestingHal::new(),
- &Transaction::Legacy(&valid_request)
- ))
- .is_ok()
+ process(&mut TestingHal::new(), &Transaction::Legacy(&valid_request))
+ .await
+ .is_ok()
);
}
@@ -1479,10 +1480,11 @@ mod tests {
let mut invalid_request = valid_request.clone();
invalid_request.coin = 100;
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&Transaction::Legacy(&invalid_request)
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
}
@@ -1492,10 +1494,11 @@ mod tests {
let mut invalid_request = valid_request.clone();
invalid_request.keypath = vec![44 + HARDENED, 0 + HARDENED, 0 + HARDENED, 0, 0];
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&Transaction::Legacy(&invalid_request)
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
}
@@ -1505,10 +1508,11 @@ mod tests {
let mut invalid_request = valid_request.clone();
invalid_request.keypath = vec![44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 100];
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&Transaction::Legacy(&invalid_request)
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
}
@@ -1518,10 +1522,11 @@ mod tests {
let mut invalid_request = valid_request.clone();
invalid_request.data = vec![0; 6145];
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&Transaction::Legacy(&invalid_request)
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
}
@@ -1531,10 +1536,11 @@ mod tests {
let mut invalid_request = valid_request.clone();
invalid_request.recipient = vec![b'a'; 21];
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&Transaction::Legacy(&invalid_request)
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
}
@@ -1544,10 +1550,11 @@ mod tests {
let mut invalid_request = valid_request.clone();
invalid_request.recipient = vec![0; 20];
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&Transaction::Legacy(&invalid_request)
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
}
@@ -1558,7 +1565,7 @@ mod tests {
let mut mock_hal = TestingHal::new();
mock_hal.ui.abort_nth(i);
assert_eq!(
- block_on(process(&mut mock_hal, &Transaction::Legacy(&valid_request))),
+ process(&mut mock_hal, &Transaction::Legacy(&valid_request)).await,
Err(Error::UserAbort)
);
let mut expected_screens = [
@@ -1590,17 +1597,14 @@ mod tests {
// Keystore locked.
keystore::lock();
assert_eq!(
- block_on(process(
- &mut TestingHal::new(),
- &Transaction::Legacy(&valid_request)
- )),
+ process(&mut TestingHal::new(), &Transaction::Legacy(&valid_request)).await,
Err(Error::Generic)
);
}
}
- #[test]
- pub fn test_process_unhappy_eip1559() {
+ #[async_test::test]
+ pub async fn test_process_unhappy_eip1559() {
let valid_request = pb::EthSignEip1559Request {
keypath: vec![44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0],
nonce: hex!("1fdc").to_vec(),
@@ -1621,10 +1625,11 @@ mod tests {
// Check that the above is valid before making invalid variants.
mock_unlocked();
assert!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&Transaction::Eip1559(&valid_request)
- ))
+ )
+ .await
.is_ok()
);
}
@@ -1634,10 +1639,11 @@ mod tests {
let mut invalid_request = valid_request.clone();
invalid_request.chain_id = 0;
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&Transaction::Eip1559(&invalid_request)
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
}
@@ -1647,10 +1653,11 @@ mod tests {
let mut invalid_request = valid_request.clone();
invalid_request.max_fee_per_gas = hex!("000165a0bc00").to_vec();
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&Transaction::Eip1559(&invalid_request)
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
}
@@ -1660,24 +1667,25 @@ mod tests {
let mut invalid_request = valid_request.clone();
invalid_request.max_priority_fee_per_gas = hex!("003b9aca00").to_vec();
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&Transaction::Eip1559(&invalid_request)
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
}
}
/// Unknown chain ID (network params not hardcoded in in the firmware).
- #[test]
- pub fn test_process_unknown_network() {
+ #[async_test::test]
+ pub async fn test_process_unknown_network() {
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
mock_unlocked();
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(&mut mock_hal, &Transaction::Legacy(&pb::EthSignRequest {
+ process(&mut mock_hal, &Transaction::Legacy(&pb::EthSignRequest {
coin: pb::EthCoin::Eth as _,
keypath: KEYPATH.to_vec(),
nonce: hex!("1fdc").to_vec(),
@@ -1690,7 +1698,7 @@ mod tests {
chain_id: 12345,
address_case: pb::EthAddressCase::Mixed as _,
data_length: 0,
- }))),
+ })).await,
Ok(Response::Sign(pb::EthSignResponse {
signature: hex!("b1b6b34e15a0309ddc2603df4c4038ea8665ed85d3f2c81e7f1aa0254b2138720d601f4219fb29ab3d5ff776eae1be1526b467e2b0e630e8e634a4da4a822e3900").to_vec()
}))
@@ -1726,14 +1734,14 @@ mod tests {
}
/// Test that the chain confirmation screen appears for known non-mainnet networks.
- #[test]
- pub fn test_chain_confirmation() {
+ #[async_test::test]
+ pub async fn test_chain_confirmation() {
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
// Test with Arbitrum (chain_id 42161)
mock_unlocked();
let mut mock_hal = TestingHal::new();
- block_on(process(
+ process(
&mut mock_hal,
&Transaction::Legacy(&pb::EthSignRequest {
coin: pb::EthCoin::Eth as _,
@@ -1749,7 +1757,8 @@ mod tests {
address_case: pb::EthAddressCase::Mixed as _,
data_length: 0,
}),
- ))
+ )
+ .await
.unwrap();
assert_eq!(
@@ -1763,14 +1772,14 @@ mod tests {
}
/// Test that EIP-1559 transactions also get the chain confirmation screen
- #[test]
- pub fn test_chain_confirmation_for_eip1559() {
+ #[async_test::test]
+ pub async fn test_chain_confirmation_for_eip1559() {
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
// Test with Polygon network (chain_id 137)
mock_unlocked();
let mut mock_hal = TestingHal::new();
- block_on(process(
+ process(
&mut mock_hal,
&Transaction::Eip1559(&pb::EthSignEip1559Request {
keypath: KEYPATH.to_vec(),
@@ -1787,7 +1796,8 @@ mod tests {
data_length: 0,
payment_request: None,
}),
- ))
+ )
+ .await
.unwrap();
assert_eq!(
mock_hal.ui.screens[0],
@@ -1799,14 +1809,14 @@ mod tests {
);
}
- #[test]
- pub fn test_streaming_equivalence_legacy() {
+ #[async_test::test]
+ pub async fn test_streaming_equivalence_legacy() {
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
let test_data: Vec<u8> = (0..4000u32).map(|i| (i % 256) as u8).collect();
mock_unlocked();
let mut mock_hal_nonstreaming = TestingHal::new();
- let nonstreaming_result = block_on(process(
+ let nonstreaming_result = process(
&mut mock_hal_nonstreaming,
&Transaction::Legacy(&pb::EthSignRequest {
coin: pb::EthCoin::Eth as _,
@@ -1822,12 +1832,13 @@ mod tests {
address_case: pb::EthAddressCase::Mixed as _,
data_length: 0,
}),
- ));
+ )
+ .await;
setup_chunk_responder(test_data.clone());
mock_unlocked();
let mut mock_hal_streaming = TestingHal::new();
- let streaming_result = block_on(process(
+ let streaming_result = process(
&mut mock_hal_streaming,
&Transaction::Legacy(&pb::EthSignRequest {
coin: pb::EthCoin::Eth as _,
@@ -1843,7 +1854,8 @@ mod tests {
address_case: pb::EthAddressCase::Mixed as _,
data_length: 4000,
}),
- ));
+ )
+ .await;
clear_chunk_responder();
assert!(nonstreaming_result.is_ok());
@@ -1856,14 +1868,14 @@ mod tests {
}
}
- #[test]
- pub fn test_streaming_equivalence_eip1559() {
+ #[async_test::test]
+ pub async fn test_streaming_equivalence_eip1559() {
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
let test_data: Vec<u8> = (0..4000u32).map(|i| (i % 256) as u8).collect();
mock_unlocked();
let mut mock_hal_nonstreaming = TestingHal::new();
- let nonstreaming_result = block_on(process(
+ let nonstreaming_result = process(
&mut mock_hal_nonstreaming,
&Transaction::Eip1559(&pb::EthSignEip1559Request {
keypath: KEYPATH.to_vec(),
@@ -1880,12 +1892,13 @@ mod tests {
data_length: 0,
payment_request: None,
}),
- ));
+ )
+ .await;
setup_chunk_responder(test_data.clone());
mock_unlocked();
let mut mock_hal_streaming = TestingHal::new();
- let streaming_result = block_on(process(
+ let streaming_result = process(
&mut mock_hal_streaming,
&Transaction::Eip1559(&pb::EthSignEip1559Request {
keypath: KEYPATH.to_vec(),
@@ -1902,7 +1915,8 @@ mod tests {
data_length: 4000,
payment_request: None,
}),
- ));
+ )
+ .await;
clear_chunk_responder();
assert!(nonstreaming_result.is_ok());
@@ -1915,8 +1929,8 @@ mod tests {
}
}
- #[test]
- pub fn test_streaming_large_data_legacy() {
+ #[async_test::test]
+ pub async fn test_streaming_large_data_legacy() {
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
let test_data: Vec<u8> = (0..10000u32).map(|i| (i % 256) as u8).collect();
@@ -1924,7 +1938,7 @@ mod tests {
mock_unlocked();
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&Transaction::Legacy(&pb::EthSignRequest {
coin: pb::EthCoin::Eth as _,
@@ -1941,7 +1955,7 @@ mod tests {
address_case: pb::EthAddressCase::Mixed as _,
data_length: 10000,
}),
- )),
+ ).await,
Ok(Response::Sign(pb::EthSignResponse {
signature: hex!("f00a05084c540bb69b9d0d1e7783a0fe315ffc3ffdc0edc32a3d0e9d00f9d8a86c7b5c36fc136062adc1857e2edcf73eb75138d5390ed807b2cb0b90652fef2201")
.to_vec()
@@ -1988,15 +2002,15 @@ mod tests {
);
}
- #[test]
- pub fn test_streaming_1_byte_legacy() {
+ #[async_test::test]
+ pub async fn test_streaming_1_byte_legacy() {
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
let test_data: Vec<u8> = vec![0x42];
setup_chunk_responder(test_data);
mock_unlocked();
let mut mock_hal = TestingHal::new();
- let result = block_on(process(
+ let result = process(
&mut mock_hal,
&Transaction::Legacy(&pb::EthSignRequest {
coin: pb::EthCoin::Eth as _,
@@ -2012,7 +2026,8 @@ mod tests {
address_case: pb::EthAddressCase::Mixed as _,
data_length: 1,
}),
- ));
+ )
+ .await;
clear_chunk_responder();
match result {
Ok(Response::Sign(ref sig)) => {
@@ -2022,8 +2037,8 @@ mod tests {
}
}
- #[test]
- pub fn test_streaming_large_data_eip1559() {
+ #[async_test::test]
+ pub async fn test_streaming_large_data_eip1559() {
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
let test_data: Vec<u8> = (0..12000u32).map(|i| (i % 256) as u8).collect();
@@ -2031,7 +2046,7 @@ mod tests {
mock_unlocked();
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&Transaction::Eip1559(&pb::EthSignEip1559Request {
keypath: KEYPATH.to_vec(),
@@ -2049,7 +2064,7 @@ mod tests {
data_length: 12000,
payment_request: None,
}),
- )),
+ ).await,
Ok(Response::Sign(pb::EthSignResponse {
signature: hex!("dc853640b4a75390b5b59478c18b1fba135025bf40bb41d54f95d35628443e1900376e1be2916829be4cbb0d897cc69ad80987a57a489254d561dfd3071a0db101")
.to_vec()
diff --git a/src/rust/bitbox02-rust/src/hww/api/ethereum/sign_typed_msg.rs b/src/rust/bitbox02-rust/src/hww/api/ethereum/sign_typed_msg.rs
index d15e93c..6c07873 100644
--- a/src/rust/bitbox02-rust/src/hww/api/ethereum/sign_typed_msg.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/ethereum/sign_typed_msg.rs
@@ -679,7 +679,6 @@ mod tests {
use crate::hal::testing::TestingHal;
use crate::hal::testing::ui::Screen;
use crate::keystore::testing::mock_unlocked;
- use util::bb02_async::block_on;
use util::bip32::HARDENED;
use alloc::boxed::Box;
@@ -754,7 +753,7 @@ mod tests {
]
}
- fn run_single_message_typed_msg(
+ async fn run_single_message_typed_msg(
member_type: MemberType,
message_obj: Object<'static>,
) -> TestingHal<'static> {
@@ -780,22 +779,19 @@ mod tests {
}));
}
let mut mock_hal = TestingHal::new();
- block_on(eip712_sighash(
- &mut mock_hal,
- &typed_msg.types,
- typed_msg.primary_type,
- ))
- .unwrap();
+ eip712_sighash(&mut mock_hal, &typed_msg.types, typed_msg.primary_type)
+ .await
+ .unwrap();
mock_hal
}
- fn run_single_string_message(message: String) -> TestingHal<'static> {
+ async fn run_single_string_message(message: String) -> TestingHal<'static> {
let message = Box::leak(message.into_boxed_str());
- run_single_message_typed_msg(mk_type(DataType::String), Object::String(message))
+ run_single_message_typed_msg(mk_type(DataType::String), Object::String(message)).await
}
- fn run_single_streaming_bytes_message(data: Vec<u8>) -> TestingHal<'static> {
- run_single_message_typed_msg(mk_type(DataType::Bytes), Object::StreamingBytes(data))
+ async fn run_single_streaming_bytes_message(data: Vec<u8>) -> TestingHal<'static> {
+ run_single_message_typed_msg(mk_type(DataType::Bytes), Object::StreamingBytes(data)).await
}
/// A utility structure to build domain/message objects for testing.
@@ -1167,11 +1163,11 @@ mod tests {
assert!(truncated_body.len() > MAX_DISPLAY_SIZE);
}
- #[test]
- fn test_multiline_warning_not_shown_when_each_line_fits() {
+ #[async_test::test]
+ async fn test_multiline_warning_not_shown_when_each_line_fits() {
let line1 = "a".repeat(400);
let line2 = "b".repeat(300);
- let mock_hal = run_single_string_message(format!("{line1}\n{line2}"));
+ let mock_hal = run_single_string_message(format!("{line1}\n{line2}")).await;
assert_eq!(
mock_hal.ui.screens,
@@ -1195,10 +1191,10 @@ mod tests {
);
}
- #[test]
- fn test_multiline_warning_shown_only_for_overlong_line() {
+ #[async_test::test]
+ async fn test_multiline_warning_shown_only_for_overlong_line() {
let line2 = "b".repeat(MAX_DISPLAY_SIZE);
- let mock_hal = run_single_string_message(format!("ok\n{line2}"));
+ let mock_hal = run_single_string_message(format!("ok\n{line2}")).await;
assert_eq!(
mock_hal.ui.screens,
@@ -1227,10 +1223,10 @@ mod tests {
);
}
- #[test]
- fn test_streaming_bytes_show_display_size_and_truncated_body() {
+ #[async_test::test]
+ async fn test_streaming_bytes_show_display_size_and_truncated_body() {
let data: Vec<u8> = (0u8..=255).cycle().take(10_000).collect();
- let mock_hal = run_single_streaming_bytes_message(data);
+ let mock_hal = run_single_streaming_bytes_message(data).await;
assert_eq!(mock_hal.ui.confirm_display_sizes, vec![0, 0, 10_000]);
assert_eq!(
@@ -1271,8 +1267,8 @@ mod tests {
}
/// Test computation of the domain separator, which is `hashStruct(domain)`.
- #[test]
- fn test_domain_separator() {
+ #[async_test::test]
+ async fn test_domain_separator() {
let typed_msg = alloc::rc::Rc::new(TypedMessage::new(
make_types(),
"Mail",
@@ -1291,7 +1287,7 @@ mod tests {
}));
}
let mut mock_hal = TestingHal::new();
- let domain_separator = block_on(hash_struct(
+ let domain_separator = hash_struct(
&mut mock_hal,
&typed_msg.types,
RootObject::Domain,
@@ -1299,7 +1295,8 @@ mod tests {
&[],
&[],
None,
- ))
+ )
+ .await
.unwrap();
assert_eq!(
domain_separator,
@@ -1414,8 +1411,8 @@ mod tests {
///
/// console.log("sighash:", util.TypedDataUtils.eip712Hash(msgParams, 'V4').toString('hex'));
/// ```
- #[test]
- fn test_exhaustive_data() {
+ #[async_test::test]
+ async fn test_exhaustive_data() {
const EXPECTED_DIALOGS: &[(&str, &str)] = &[
("Domain (1/4)", "name: Ether Mail"),
("Domain (2/4)", "version: 1"),
@@ -1815,12 +1812,9 @@ mod tests {
}));
}
let mut mock_hal = TestingHal::new();
- let sighash = block_on(eip712_sighash(
- &mut mock_hal,
- &typed_msg.types,
- typed_msg.primary_type,
- ))
- .unwrap();
+ let sighash = eip712_sighash(&mut mock_hal, &typed_msg.types, typed_msg.primary_type)
+ .await
+ .unwrap();
assert_eq!(
sighash,
*b"\x0e\xfe\x31\xa8\x81\x9b\x6c\x38\x1c\x9e\x97\xcf\xd2\x99\x5a\xa6\xf2\x1e\x4a\x72\x87\x9a\xc1\x31\xb2\xf6\x48\xd0\x83\x28\x1c\x83",
@@ -1868,8 +1862,8 @@ mod tests {
///
/// console.log("sighash:", util.TypedDataUtils.eip712Hash(msgParams, 'V4').toString('hex'));
/// ```
- #[test]
- fn test_no_message() {
+ #[async_test::test]
+ async fn test_no_message() {
let typed_msg = alloc::rc::Rc::new(TypedMessage::new(
vec![StructType {
name: "EIP712Domain".into(),
@@ -1900,11 +1894,12 @@ mod tests {
Ok(typed_msg.handle_host_response(&response).unwrap())
}));
}
- let sighash = block_on(eip712_sighash(
+ let sighash = eip712_sighash(
&mut TestingHal::new(),
&typed_msg.types,
typed_msg.primary_type,
- ))
+ )
+ .await
.unwrap();
assert_eq!(
sighash,
@@ -1987,8 +1982,8 @@ mod tests {
/// Verify streaming and inline sighashes match expected values, verify display screens,
/// and optionally verify signatures. Test vectors generated by
/// testdata/gen_typed_msg_streaming_tests.js using @metamask/eth-sig-util v4.0.1.
- #[test]
- fn test_streaming_equivalence() {
+ #[async_test::test]
+ async fn test_streaming_equivalence() {
let tests = load_streaming_test_cases();
for tc in &tests {
let expected: [u8; 32] = decode_hex(&tc.expected_sighash).try_into().unwrap();
@@ -2021,11 +2016,12 @@ mod tests {
*crate::hww::MOCK_NEXT_REQUEST.0.borrow_mut() = Some(Box::new(move |response| {
Ok(typed_msg_clone.handle_host_response(&response).unwrap())
}));
- let inline_sighash = block_on(eip712_sighash(
+ let inline_sighash = eip712_sighash(
&mut TestingHal::new(),
&typed_msg.types,
typed_msg.primary_type,
- ))
+ )
+ .await
.unwrap();
assert_eq!(
inline_sighash, expected,
@@ -2048,12 +2044,10 @@ mod tests {
Ok(typed_msg_clone.handle_host_response(&response).unwrap())
}));
let mut mock_hal = TestingHal::new();
- let streaming_sighash = block_on(eip712_sighash(
- &mut mock_hal,
- &typed_msg.types,
- typed_msg.primary_type,
- ))
- .unwrap();
+ let streaming_sighash =
+ eip712_sighash(&mut mock_hal, &typed_msg.types, typed_msg.primary_type)
+ .await
+ .unwrap();
assert_eq!(
streaming_sighash, expected,
"streaming sighash mismatch for: {}",
@@ -2086,12 +2080,10 @@ mod tests {
Ok(typed_msg_clone.handle_host_response(&response).unwrap())
}));
let mut mock_hal = TestingHal::new();
- let sighash = block_on(eip712_sighash(
- &mut mock_hal,
- &typed_msg.types,
- typed_msg.primary_type,
- ))
- .unwrap();
+ let sighash =
+ eip712_sighash(&mut mock_hal, &typed_msg.types, typed_msg.primary_type)
+ .await
+ .unwrap();
assert_eq!(
sighash, expected,
"sighash mismatch for: {}",
@@ -2131,7 +2123,7 @@ mod tests {
}));
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&pb::EthSignTypedMessageRequest {
chain_id: 1,
@@ -2140,7 +2132,8 @@ mod tests {
primary_type: tc.primary_type.clone(),
host_nonce_commitment: None,
}
- )),
+ )
+ .await,
Ok(Response::Sign(pb::EthSignResponse {
signature: expected_sig,
})),
@@ -2174,8 +2167,8 @@ mod tests {
}
/// Streaming is rejected for non-streamable types (e.g. uint).
- #[test]
- fn test_streaming_rejected_for_uint() {
+ #[async_test::test]
+ async fn test_streaming_rejected_for_uint() {
let typed_msg = alloc::rc::Rc::new(TypedMessage::new(
vec![
StructType {
@@ -2198,17 +2191,13 @@ mod tests {
}));
}
let mut mock_hal = TestingHal::new();
- let result = block_on(eip712_sighash(
- &mut mock_hal,
- &typed_msg.types,
- typed_msg.primary_type,
- ));
+ let result = eip712_sighash(&mut mock_hal, &typed_msg.types, typed_msg.primary_type).await;
assert_eq!(result, Err(Error::InvalidInput));
}
/// Streaming is rejected for fixed-size bytes (e.g. bytes32).
- #[test]
- fn test_streaming_rejected_for_fixed_bytes() {
+ #[async_test::test]
+ async fn test_streaming_rejected_for_fixed_bytes() {
let typed_msg = alloc::rc::Rc::new(TypedMessage::new(
vec![
StructType {
@@ -2231,17 +2220,13 @@ mod tests {
}));
}
let mut mock_hal = TestingHal::new();
- let result = block_on(eip712_sighash(
- &mut mock_hal,
- &typed_msg.types,
- typed_msg.primary_type,
- ));
+ let result = eip712_sighash(&mut mock_hal, &typed_msg.types, typed_msg.primary_type).await;
assert_eq!(result, Err(Error::InvalidInput));
}
/// data_length exceeding the max is rejected.
- #[test]
- fn test_streaming_exceeding_max_rejected() {
+ #[async_test::test]
+ async fn test_streaming_exceeding_max_rejected() {
*crate::hww::MOCK_NEXT_REQUEST.0.borrow_mut() =
Some(Box::new(|response| match &response {
pb::response::Response::Eth(pb::EthResponse {
@@ -2281,13 +2266,13 @@ mod tests {
},
];
let mut mock_hal = TestingHal::new();
- let result = block_on(eip712_sighash(&mut mock_hal, &types, "Msg"));
+ let result = eip712_sighash(&mut mock_hal, &types, "Msg").await;
assert_eq!(result, Err(Error::InvalidInput));
}
/// Both value and data_length non-empty is rejected.
- #[test]
- fn test_streaming_value_and_data_length_both_set_rejected() {
+ #[async_test::test]
+ async fn test_streaming_value_and_data_length_both_set_rejected() {
*crate::hww::MOCK_NEXT_REQUEST.0.borrow_mut() = Some(Box::new(|response| {
match &response {
pb::response::Response::Eth(pb::EthResponse {
@@ -2329,7 +2314,7 @@ mod tests {
},
];
let mut mock_hal = TestingHal::new();
- let result = block_on(eip712_sighash(&mut mock_hal, &types, "Msg"));
+ let result = eip712_sighash(&mut mock_hal, &types, "Msg").await;
assert_eq!(result, Err(Error::InvalidInput));
}
}
diff --git a/src/rust/bitbox02-rust/src/hww/api/ethereum/signmsg.rs b/src/rust/bitbox02-rust/src/hww/api/ethereum/signmsg.rs
index 289e5d0..1073884 100644
--- a/src/rust/bitbox02-rust/src/hww/api/ethereum/signmsg.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/ethereum/signmsg.rs
@@ -97,27 +97,26 @@ mod tests {
use crate::keystore::testing::mock_unlocked;
use alloc::boxed::Box;
use hex_lit::hex;
- use util::bb02_async::block_on;
use util::bip32::HARDENED;
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
const MESSAGE: &str = "message";
const EXPECTED_ADDRESS: &str = "0x 773A 77b9 D325 89be 03f9 132A F759 e294 f785 1be9";
- #[test]
- pub fn test_process() {
+ #[async_test::test]
+ pub async fn test_process() {
const SIGNATURE: [u8; 64] = [b'1'; 64];
mock_unlocked();
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(&mut mock_hal, &pb::EthSignMessageRequest {
+ process(&mut mock_hal, &pb::EthSignMessageRequest {
coin: pb::EthCoin::Eth as _,
keypath: KEYPATH.to_vec(),
msg: MESSAGE.as_bytes().to_vec(),
host_nonce_commitment: None,
chain_id: 0,
- })),
+ }).await,
Ok(Response::Sign(pb::EthSignResponse {
signature: hex!(
"34885e9374375a12e8c5186ef9870b036b2bd251b3f20b979511912dd41894725c0a504a3419ae21d69e2243ca18e9c6eee75b2e16ea57b4f647fd106be83fd201"
@@ -142,13 +141,13 @@ mod tests {
);
}
- #[test]
- pub fn test_process_warn_unusual_keypath() {
+ #[async_test::test]
+ pub async fn test_process_warn_unusual_keypath() {
const SIGNATURE: [u8; 64] = [b'1'; 64];
mock_unlocked();
let mut mock_hal = TestingHal::new();
- block_on(process(
+ process(
&mut mock_hal,
&pb::EthSignMessageRequest {
coin: pb::EthCoin::Eth as _,
@@ -157,7 +156,8 @@ mod tests {
host_nonce_commitment: None,
chain_id: 11155111,
},
- ))
+ )
+ .await
.unwrap();
assert_eq!(
mock_hal.ui.screens,
@@ -181,8 +181,8 @@ mod tests {
);
}
- #[test]
- pub fn test_process_user_aborted() {
+ #[async_test::test]
+ pub async fn test_process_user_aborted() {
let request = pb::EthSignMessageRequest {
coin: pb::EthCoin::Eth as _,
keypath: KEYPATH.to_vec(),
@@ -198,7 +198,7 @@ mod tests {
// User abort address verification.
mock_hal.ui.abort_nth(0);
assert_eq!(
- block_on(process(&mut mock_hal, &request)),
+ process(&mut mock_hal, &request).await,
Err(Error::UserAbort)
);
assert_eq!(
@@ -215,7 +215,7 @@ mod tests {
// User abort message verification.
mock_hal.ui.abort_nth(1);
assert_eq!(
- block_on(process(&mut mock_hal, &request)),
+ process(&mut mock_hal, &request).await,
Err(Error::UserAbort)
);
assert_eq!(
@@ -235,13 +235,13 @@ mod tests {
);
}
- #[test]
- pub fn test_process_failures() {
+ #[async_test::test]
+ pub async fn test_process_failures() {
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
// Message too long
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&pb::EthSignMessageRequest {
coin: pb::EthCoin::Eth as _,
@@ -250,14 +250,15 @@ mod tests {
host_nonce_commitment: None,
chain_id: 0,
}
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
// Keystore locked.
keystore::lock();
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&pb::EthSignMessageRequest {
coin: pb::EthCoin::Eth as _,
@@ -266,7 +267,8 @@ mod tests {
host_nonce_commitment: None,
chain_id: 0,
}
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
}
diff --git a/src/rust/bitbox02-rust/src/hww/api/payment_request.rs b/src/rust/bitbox02-rust/src/hww/api/payment_request.rs
index 3551140..71ad87d 100644
--- a/src/rust/bitbox02-rust/src/hww/api/payment_request.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/payment_request.rs
@@ -497,7 +497,6 @@ mod tests {
use crate::hww::api::bitcoin::params;
#[cfg(feature = "app-ethereum")]
use crate::hww::api::ethereum::params as eth_params;
- use util::bb02_async::block_on;
fn make_text_memo(note: &str) -> Memo {
Memo {
@@ -1372,11 +1371,11 @@ mod tests {
));
}
- #[test]
- fn test_user_verify_text_memos() {
+ #[async_test::test]
+ async fn test_user_verify_text_memos() {
// Baseline Pocket flow: recipient screen, memo intro, memo contents.
let mut mock_hal = TestingHal::new();
- block_on(user_verify(
+ user_verify(
&mut mock_hal,
&pb::BtcPaymentRequestRequest {
recipient_name: "POCKET".into(),
@@ -1386,7 +1385,8 @@ mod tests {
signature: vec![],
},
"12.34567890 BTC",
- ))
+ )
+ .await
.unwrap();
assert_eq!(
@@ -1411,11 +1411,11 @@ mod tests {
}
#[cfg(feature = "app-ethereum")]
- #[test]
- fn test_user_verify_swap() {
+ #[async_test::test]
+ async fn test_user_verify_swap() {
// Happy-path swap flow: recipient screen plus two swap-specific confirms.
let mut mock_hal = TestingHal::new();
- block_on(user_verify(
+ user_verify(
&mut mock_hal,
&pb::BtcPaymentRequestRequest {
recipient_name: "SWAPKIT (Provider)".into(),
@@ -1430,7 +1430,8 @@ mod tests {
signature: vec![],
},
"0.25000000 BTC",
- ))
+ )
+ .await
.unwrap();
assert_eq!(
@@ -1455,11 +1456,11 @@ mod tests {
}
#[cfg(feature = "app-litecoin")]
- #[test]
- fn test_user_verify_swap_btc_destination() {
+ #[async_test::test]
+ async fn test_user_verify_swap_btc_destination() {
// BTC -> LTC swap
let mut mock_hal = TestingHal::new();
- block_on(user_verify(
+ user_verify(
&mut mock_hal,
&pb::BtcPaymentRequestRequest {
recipient_name: "SWAPKIT (Provider)".into(),
@@ -1483,7 +1484,8 @@ mod tests {
signature: vec![],
},
"0.25000000 BTC",
- ))
+ )
+ .await
.unwrap();
assert_eq!(
@@ -1609,8 +1611,8 @@ mod tests {
}
#[cfg(all(feature = "app-litecoin", feature = "app-ethereum"))]
- #[test]
- fn test_user_verify_swap_invalid() {
+ #[async_test::test]
+ async fn test_user_verify_swap_invalid() {
// Invalid swap requests that user_verify must reject because the
// UI cannot render them safely.
for payment_request in [
@@ -1688,11 +1690,7 @@ mod tests {
] {
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(user_verify(
- &mut mock_hal,
- &payment_request,
- "0.25000000 BTC",
- )),
+ user_verify(&mut mock_hal, &payment_request, "0.25000000 BTC",).await,
Err(Error::InvalidInput)
);
}
diff --git a/src/rust/bitbox02-rust/src/hww/api/reset.rs b/src/rust/bitbox02-rust/src/hww/api/reset.rs
index 5a3d0b4..5cd9c84 100644
--- a/src/rust/bitbox02-rust/src/hww/api/reset.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/reset.rs
@@ -31,17 +31,16 @@ mod tests {
use crate::hal::{Memory, testing::TestingHal};
use alloc::boxed::Box;
use bitbox02::testing::mock_memory;
- use util::bb02_async::block_on;
- #[test]
- pub fn test_reset() {
+ #[async_test::test]
+ pub async fn test_reset() {
mock_memory();
// User aborted confirmation.
let mut mock_hal = TestingHal::new();
mock_hal.memory.set_device_name("test device name").unwrap();
mock_hal.ui.abort_nth(0);
- assert_eq!(block_on(process(&mut mock_hal)), Err(Error::Generic));
+ assert_eq!(process(&mut mock_hal).await, Err(Error::Generic));
assert_eq!(
mock_hal.ui.screens,
vec![Screen::Confirm {
@@ -59,7 +58,7 @@ mod tests {
let mut mock_hal = TestingHal::new();
mock_hal.memory.set_device_name("test device name").unwrap();
assert_eq!(
- block_on(process(&mut mock_hal)),
+ process(&mut mock_hal).await,
Ok(Response::Success(pb::Success {}))
);
assert_eq!(
diff --git a/src/rust/bitbox02-rust/src/hww/api/restore.rs b/src/rust/bitbox02-rust/src/hww/api/restore.rs
index 1bc0f67..118daf8 100644
--- a/src/rust/bitbox02-rust/src/hww/api/restore.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/restore.rs
@@ -159,13 +159,12 @@ mod tests {
use crate::hal::testing::TestingHal;
use bitbox02::memory;
- use util::bb02_async::block_on;
use alloc::boxed::Box;
use alloc::vec::Vec;
- #[test]
- fn test_from_mnemonic() {
+ #[async_test::test]
+ async fn test_from_mnemonic() {
crate::keystore::lock();
let mnemonic_words: Vec<&str> = "boring mistake dish oyster truth pigeon viable emerge sort crash wire portion cannon couple enact box walk height pull today solid off enable tide"
.split(' ')
@@ -185,13 +184,14 @@ mod tests {
mock_hal.securechip.event_counter_reset();
assert_eq!(
- block_on(from_mnemonic(
+ from_mnemonic(
&mut mock_hal,
&pb::RestoreFromMnemonicRequest {
timestamp: 0,
timezone_offset: 0,
}
- )),
+ )
+ .await,
Ok(Response::Success(pb::Success {}))
);
assert_eq!(mock_hal.securechip.get_event_counter(), 5);
diff --git a/src/rust/bitbox02-rust/src/hww/api/sdcard.rs b/src/rust/bitbox02-rust/src/hww/api/sdcard.rs
index 267f710..280700e 100644
--- a/src/rust/bitbox02-rust/src/hww/api/sdcard.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/sdcard.rs
@@ -31,20 +31,20 @@ mod tests {
use crate::hal::testing::TestingHal;
use alloc::boxed::Box;
- use util::bb02_async::block_on;
- #[test]
- pub fn test_reset() {
+ #[async_test::test]
+ pub async fn test_reset() {
// already inserted.
let mut mock_hal = TestingHal::new();
mock_hal.sd.inserted = Some(true);
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&pb::InsertRemoveSdCardRequest {
action: SdCardAction::InsertCard as _,
}
- )),
+ )
+ .await,
Ok(Response::Success(pb::Success {}))
);
@@ -52,12 +52,13 @@ mod tests {
let mut mock_hal = TestingHal::new();
mock_hal.sd.inserted = Some(false);
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&pb::InsertRemoveSdCardRequest {
action: SdCardAction::RemoveCard as _,
}
- )),
+ )
+ .await,
Ok(Response::Success(pb::Success {}))
);
@@ -65,12 +66,13 @@ mod tests {
let mut mock_hal = TestingHal::new();
mock_hal.sd.inserted = Some(false);
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&pb::InsertRemoveSdCardRequest {
action: SdCardAction::InsertCard as _,
}
- )),
+ )
+ .await,
Ok(Response::Success(pb::Success {}))
);
@@ -78,12 +80,13 @@ mod tests {
let mut mock_hal = TestingHal::new();
mock_hal.sd.inserted = Some(true);
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&pb::InsertRemoveSdCardRequest {
action: SdCardAction::RemoveCard as _,
}
- )),
+ )
+ .await,
Ok(Response::Success(pb::Success {}))
);
}
diff --git a/src/rust/bitbox02-rust/src/hww/api/set_device_name.rs b/src/rust/bitbox02-rust/src/hww/api/set_device_name.rs
index 550eec2..3c4217c 100644
--- a/src/rust/bitbox02-rust/src/hww/api/set_device_name.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/set_device_name.rs
@@ -37,21 +37,21 @@ mod tests {
use crate::hal::testing::TestingHal;
use crate::hal::testing::ui::Screen;
use alloc::boxed::Box;
- use util::bb02_async::block_on;
- #[test]
- pub fn test_set_device_name() {
+ #[async_test::test]
+ pub async fn test_set_device_name() {
const SOME_NAME: &str = "foo";
// All good.
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&pb::SetDeviceNameRequest {
name: SOME_NAME.into()
}
- )),
+ )
+ .await,
Ok(Response::Success(pb::Success {}))
);
assert_eq!(
@@ -68,12 +68,13 @@ mod tests {
let mut mock_hal = TestingHal::new();
mock_hal.ui.abort_nth(0);
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&pb::SetDeviceNameRequest {
name: SOME_NAME.into()
}
- )),
+ )
+ .await,
Err(Error::UserAbort)
);
assert_eq!(
@@ -87,34 +88,37 @@ mod tests {
// Non-ascii character.
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&pb::SetDeviceNameRequest {
name: "emoji are 😃, 😭, and 😈".into()
}
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
// Non-printable character.
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&pb::SetDeviceNameRequest {
name: "foo\nbar".into()
}
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
// Too long.
assert_eq!(
- block_on(process(
+ process(
&mut TestingHal::new(),
&pb::SetDeviceNameRequest {
name: core::str::from_utf8(&[b'a'; 500]).unwrap().into()
}
- )),
+ )
+ .await,
Err(Error::InvalidInput)
);
}
diff --git a/src/rust/bitbox02-rust/src/hww/api/set_mnemonic_passphrase_enabled.rs b/src/rust/bitbox02-rust/src/hww/api/set_mnemonic_passphrase_enabled.rs
index cd824c9..6c9ce51 100644
--- a/src/rust/bitbox02-rust/src/hww/api/set_mnemonic_passphrase_enabled.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/set_mnemonic_passphrase_enabled.rs
@@ -39,19 +39,19 @@ mod tests {
use crate::hal::testing::TestingHal;
use crate::hal::testing::ui::Screen;
use alloc::boxed::Box;
- use util::bb02_async::block_on;
- #[test]
- pub fn test_mnemonic_passphrase_enabled() {
+ #[async_test::test]
+ pub async fn test_mnemonic_passphrase_enabled() {
// All good.
// Enable:
let mut mock_hal = TestingHal::new();
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&pb::SetMnemonicPassphraseEnabledRequest { enabled: true }
- )),
+ )
+ .await,
Ok(Response::Success(pb::Success {}))
);
assert_eq!(
@@ -67,10 +67,11 @@ mod tests {
// Disable:
mock_hal.ui.screens.clear();
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&pb::SetMnemonicPassphraseEnabledRequest { enabled: false }
- )),
+ )
+ .await,
Ok(Response::Success(pb::Success {}))
);
assert_eq!(
@@ -87,10 +88,11 @@ mod tests {
let mut mock_hal = TestingHal::new();
mock_hal.ui.abort_nth(0);
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&pb::SetMnemonicPassphraseEnabledRequest { enabled: true }
- )),
+ )
+ .await,
Err(Error::UserAbort)
);
}
diff --git a/src/rust/bitbox02-rust/src/hww/api/set_password.rs b/src/rust/bitbox02-rust/src/hww/api/set_password.rs
index 5b127dd..7788aff 100644
--- a/src/rust/bitbox02-rust/src/hww/api/set_password.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/set_password.rs
@@ -39,12 +39,11 @@ mod tests {
use crate::hal::testing::TestingHal;
use bitbox02::testing::mock_memory;
- use util::bb02_async::block_on;
use alloc::boxed::Box;
- #[test]
- fn test_process() {
+ #[async_test::test]
+ async fn test_process() {
mock_memory();
keystore::lock();
let mut counter = 0u32;
@@ -61,12 +60,13 @@ mod tests {
mock_hal.securechip.event_counter_reset();
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&pb::SetPasswordRequest {
entropy: b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_vec(),
}
- )),
+ )
+ .await,
Ok(Response::Success(pb::Success {}))
);
assert_eq!(mock_hal.securechip.get_event_counter(), 6);
@@ -78,8 +78,8 @@ mod tests {
}
/// Shorter host entropy results in shorter seed.
- #[test]
- fn test_process_16_bytes() {
+ #[async_test::test]
+ async fn test_process_16_bytes() {
mock_memory();
keystore::lock();
let mut mock_hal = TestingHal::new();
@@ -87,12 +87,13 @@ mod tests {
.ui
.set_enter_string(Box::new(|_params| Ok("password".into())));
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&pb::SetPasswordRequest {
entropy: b"aaaaaaaaaaaaaaaa".to_vec(),
}
- )),
+ )
+ .await,
Ok(Response::Success(pb::Success {}))
);
assert!(!keystore::is_locked());
@@ -100,8 +101,8 @@ mod tests {
}
/// Invalid host entropy size.
- #[test]
- fn test_process_invalid_host_entropy() {
+ #[async_test::test]
+ async fn test_process_invalid_host_entropy() {
mock_memory();
keystore::lock();
let mut mock_hal = TestingHal::new();
@@ -110,19 +111,20 @@ mod tests {
.set_enter_string(Box::new(|_params| Ok("password".into())));
assert!(keystore::is_locked());
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&pb::SetPasswordRequest {
entropy: b"aaaaaaaaaaaaaaaaa".to_vec(),
}
- )),
+ )
+ .await,
Err(Error::InvalidInput),
);
assert!(keystore::is_locked());
}
- #[test]
- fn test_process_2nd_password_doesnt_match() {
+ #[async_test::test]
+ async fn test_process_2nd_password_doesnt_match() {
mock_memory();
keystore::lock();
let mut counter = 0u32;
@@ -136,12 +138,13 @@ mod tests {
})
}));
assert_eq!(
- block_on(process(
+ process(
&mut mock_hal,
&pb::SetPasswordRequest {
entropy: b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_vec(),
}
- )),
+ )
+ .await,
Err(Error::Generic),
);
assert!(keystore::is_locked());
diff --git a/src/rust/bitbox02-rust/src/hww/api/show_mnemonic.rs b/src/rust/bitbox02-rust/src/hww/api/show_mnemonic.rs
index dec00c2..08effe9 100644
--- a/src/rust/bitbox02-rust/src/hww/api/show_mnemonic.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/show_mnemonic.rs
@@ -66,14 +66,13 @@ mod tests {
use crate::hal::testing::ui::Screen;
use crate::hal::testing::{TestingHal, TestingUi};
use bitbox02::testing::mock_memory;
- use util::bb02_async::block_on;
const MNEMONIC: &str = "shy parrot age monkey rhythm snake mystery burden topic hello mouse script gesture tattoo demand float verify shoe recycle cool network better aspect list";
/// When not yet initialized, we show the mnemonic without a password check. This happens during
/// wallet setup.
- #[test]
- fn test_process_uninitialized() {
+ #[async_test::test]
+ async fn test_process_uninitialized() {
mock_memory();
let mut mock_hal = TestingHal::new();
crate::keystore::encrypt_and_store_seed(
@@ -95,7 +94,7 @@ mod tests {
mock_hal.securechip.event_counter_reset();
assert_eq!(
- block_on(process(&mut mock_hal)),
+ process(&mut mock_hal).await,
Ok(Response::Success(pb::Success {}))
);
// 1 operation for one copy_seed() to get the seed to display it.
@@ -130,9 +129,10 @@ mod tests {
);
}
/// When initialized, a password check is prompted before displaying the mnemonic.
- #[test]
- fn test_process_initialized() {
+ #[async_test::test]
+ async fn test_process_initialized() {
mock_memory();
+ let mut password_entered: bool = false;
let mut mock_hal = TestingHal::new();
crate::keystore::encrypt_and_store_seed(
&mut mock_hal,
@@ -145,8 +145,6 @@ mod tests {
mock_hal.memory.set_initialized().unwrap();
- let mut password_entered: bool = false;
-
mock_hal.ui.set_enter_string(Box::new(|_params| {
password_entered = true;
Ok("password".into())
@@ -157,7 +155,7 @@ mod tests {
mock_hal.securechip.event_counter_reset();
assert_eq!(
- block_on(process(&mut mock_hal)),
+ process(&mut mock_hal).await,
Ok(Response::Success(pb::Success {}))
);
assert_eq!(mock_hal.securechip.get_event_counter(), 4);
@@ -196,8 +194,8 @@ mod tests {
/// When initialized, a password check is prompted before displaying the mnemonic.
/// This tests that we fail early if the wrong password is entered.
- #[test]
- fn test_process_initialized_wrong_password() {
+ #[async_test::test]
+ async fn test_process_initialized_wrong_password() {
mock_memory();
let mut mock_hal = TestingHal::new();
@@ -217,7 +215,7 @@ mod tests {
.set_enter_string(Box::new(|_params| Ok("wrong password".into())));
mock_hal.securechip.event_counter_reset();
- assert_eq!(block_on(process(&mut mock_hal)), Err(Error::Generic));
+ assert_eq!(process(&mut mock_hal).await, Err(Error::Generic));
assert_eq!(mock_hal.securechip.get_event_counter(), 4);
assert_eq!(
diff --git a/src/rust/bitbox02-rust/src/hww/api/system.rs b/src/rust/bitbox02-rust/src/hww/api/system.rs
index b255d39..f78f184 100644
--- a/src/rust/bitbox02-rust/src/hww/api/system.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/system.rs
@@ -35,33 +35,32 @@ mod tests {
use super::*;
use crate::hal::testing::TestingHal;
- use crate::hal::testing::ui::Screen;
- use alloc::boxed::Box;
- use util::bb02_async::block_on;
- #[test]
+ #[async_test::test]
#[should_panic(expected = "reboot_to_bootloader called")]
- pub fn test_reboot_to_bootloader() {
- block_on(reboot_to_bootloader(
+ async fn test_reboot_to_bootloader() {
+ reboot_to_bootloader(
&mut TestingHal::new(),
&pb::RebootRequest {
purpose: Purpose::Upgrade as _,
},
- ))
+ )
+ .await
.unwrap();
}
- #[test]
- pub fn test_reboot_to_bootloader_aborted() {
+ #[async_test::test]
+ async fn test_reboot_to_bootloader_aborted() {
let mut mock_hal = TestingHal::new();
mock_hal.ui.abort_nth(0);
assert_eq!(
- block_on(reboot_to_bootloader(
+ reboot_to_bootloader(
&mut mock_hal,
&pb::RebootRequest {
purpose: Purpose::Upgrade as _
}
- )),
+ )
+ .await,
Err(Error::UserAbort),
);
}
diff --git a/src/rust/bitbox02-rust/src/keystore.rs b/src/rust/bitbox02-rust/src/keystore.rs
index e66435c..a1cafeb 100644
--- a/src/rust/bitbox02-rust/src/keystore.rs
+++ b/src/rust/bitbox02-rust/src/keystore.rs
@@ -861,7 +861,6 @@ mod tests {
use bitbox02::testing::mock_memory;
use testing::{TEST_MNEMONIC, mock_unlocked, mock_unlocked_using_mnemonic};
- use util::bb02_async::block_on;
use bitcoin::secp256k1;
@@ -983,8 +982,8 @@ mod tests {
));
}
- #[test]
- fn test_re_encrypt_seed_changes_password() {
+ #[async_test::test]
+ async fn test_re_encrypt_seed_changes_password() {
mock_memory();
lock();
@@ -995,16 +994,17 @@ mod tests {
assert!(encrypt_and_store_seed(&mut mock_hal, &seed, "old_password").is_ok());
// Step 2: Unlock with initial password and set up BIP39
- let unlocked_seed = block_on(unlock(&mut mock_hal, "old_password")).unwrap();
+ let unlocked_seed = unlock(&mut mock_hal, "old_password").await.unwrap();
assert_eq!(unlocked_seed.as_slice(), seed.as_slice());
assert!(
- block_on(unlock_bip39(
+ unlock_bip39(
&mut KeystoreHalImpl::from_hal(&mut mock_hal),
&seed,
"",
async || {},
- ))
+ )
+ .await
.is_ok()
);
@@ -1014,17 +1014,17 @@ mod tests {
// Step 4: Lock and verify old password no longer works
lock();
assert!(matches!(
- block_on(unlock(&mut mock_hal, "old_password")),
+ unlock(&mut mock_hal, "old_password").await,
Err(Error::IncorrectPassword)
));
// Step 5: Verify new password works
- let unlocked_seed_new = block_on(unlock(&mut mock_hal, "new_password")).unwrap();
+ let unlocked_seed_new = unlock(&mut mock_hal, "new_password").await.unwrap();
assert_eq!(unlocked_seed_new.as_slice(), seed.as_slice());
}
- #[test]
- fn test_re_encrypt_seed_preserves_seeds_and_fingerprint() {
+ #[async_test::test]
+ async fn test_re_encrypt_seed_preserves_seeds_and_fingerprint() {
mock_memory();
lock();
@@ -1035,12 +1035,13 @@ mod tests {
assert!(encrypt_and_store_seed(&mut mock_hal, &seed, "password1").is_ok());
assert!(
- block_on(unlock_bip39(
+ unlock_bip39(
&mut KeystoreHalImpl::from_hal(&mut mock_hal),
&seed,
"",
async || {},
- ))
+ )
+ .await
.is_ok()
);
@@ -1066,8 +1067,8 @@ mod tests {
}
}
- #[test]
- fn test_re_encrypt_seed_invalid_seed_size() {
+ #[async_test::test]
+ async fn test_re_encrypt_seed_invalid_seed_size() {
mock_memory();
lock();
@@ -1076,15 +1077,16 @@ mod tests {
// Initial setup
assert!(encrypt_and_store_seed(&mut mock_hal, &seed, "password").is_ok());
- block_on(unlock(&mut mock_hal, "password")).unwrap();
+ unlock(&mut mock_hal, "password").await.unwrap();
assert!(
- block_on(unlock_bip39(
+ unlock_bip39(
&mut KeystoreHalImpl::from_hal(&mut mock_hal),
&seed,
"",
async || {},
- ))
+ )
+ .await
.is_ok()
);
@@ -1168,8 +1170,8 @@ mod tests {
);
}
- #[test]
- fn test_lock() {
+ #[async_test::test]
+ async fn test_lock() {
let mut mock_hal = TestingHal::new();
lock();
assert!(is_locked());
@@ -1178,12 +1180,13 @@ mod tests {
assert!(encrypt_and_store_seed(&mut mock_hal, &seed, "password").is_ok());
assert!(is_locked()); // still locked, it is only unlocked after unlock_bip39.
assert!(
- block_on(unlock_bip39(
+ unlock_bip39(
&mut KeystoreHalImpl::from_hal(&mut mock_hal),
&seed,
"foo",
async || {},
- ))
+ )
+ .await
.is_ok()
);
assert!(!is_locked());
@@ -1191,15 +1194,15 @@ mod tests {
assert!(is_locked());
}
- #[test]
- fn test_unlock() {
+ #[async_test::test]
+ async fn test_unlock() {
mock_memory();
lock();
let mut mock_hal = TestingHal::new();
assert!(matches!(
- block_on(unlock(&mut mock_hal, "password")),
+ unlock(&mut mock_hal, "password").await,
Err(Error::Unseeded)
));
@@ -1220,9 +1223,7 @@ mod tests {
// First call: unlock. The first one does a seed rentention (1 securechip event).
mock_hal.securechip.event_counter_reset();
assert_eq!(
- block_on(unlock(&mut mock_hal, "password"))
- .unwrap()
- .as_slice(),
+ unlock(&mut mock_hal, "password").await.unwrap().as_slice(),
seed
);
assert_eq!(mock_hal.securechip.get_event_counter(), 5);
@@ -1233,9 +1234,7 @@ mod tests {
// so it ends up needing one secure chip operation less.
mock_hal.securechip.event_counter_reset();
assert_eq!(
- block_on(unlock(&mut mock_hal, "password"))
- .unwrap()
- .as_slice(),
+ unlock(&mut mock_hal, "password").await.unwrap().as_slice(),
seed
);
assert_eq!(mock_hal.securechip.get_event_counter(), 4);
@@ -1256,7 +1255,7 @@ mod tests {
// First 9 wrong attempts.
for i in 1..MAX_UNLOCK_ATTEMPTS {
assert!(matches!(
- block_on(unlock(&mut mock_hal, "invalid password")),
+ unlock(&mut mock_hal, "invalid password").await,
Err(Error::IncorrectPassword)
));
assert_eq!(
@@ -1270,20 +1269,20 @@ mod tests {
}
// Last attempt, triggers reset.
assert!(matches!(
- block_on(unlock(&mut mock_hal, "invalid password")),
+ unlock(&mut mock_hal, "invalid password").await,
Err(Error::MaxAttemptsExceeded),
));
// Last wrong attempt locks & resets. There is no more seed.
assert!(!mock_hal.memory.is_seeded());
assert!(copy_seed(&mut mock_hal).is_err());
assert!(matches!(
- block_on(unlock(&mut mock_hal, "password")),
+ unlock(&mut mock_hal, "password").await,
Err(Error::Unseeded)
));
}
- #[test]
- fn test_unlock_lockout_while_locked() {
+ #[async_test::test]
+ async fn test_unlock_lockout_while_locked() {
mock_memory();
lock();
@@ -1301,7 +1300,7 @@ mod tests {
for attempt in 1..MAX_UNLOCK_ATTEMPTS {
assert!(matches!(
- block_on(unlock(&mut mock_hal, "invalid password")),
+ unlock(&mut mock_hal, "invalid password").await,
Err(Error::IncorrectPassword),
));
@@ -1315,14 +1314,14 @@ mod tests {
}
assert!(matches!(
- block_on(unlock(&mut mock_hal, "invalid password")),
+ unlock(&mut mock_hal, "invalid password").await,
Err(Error::MaxAttemptsExceeded)
));
assert!(is_locked());
assert!(copy_seed(&mut mock_hal).is_err());
assert!(!mock_hal.memory.is_seeded());
assert!(matches!(
- block_on(unlock(&mut mock_hal, "password")),
+ unlock(&mut mock_hal, "password").await,
Err(Error::Unseeded)
));
}
@@ -1330,8 +1329,8 @@ mod tests {
/// Ensures that if the recorded unlock attempts already reached the maximum before calling
/// `unlock()`, the keystore immediately returns `MaxAttemptsExceeded` without performing any
/// secure chip operations.
- #[test]
- fn test_unlock_preexisting_lockout() {
+ #[async_test::test]
+ async fn test_unlock_preexisting_lockout() {
mock_memory();
lock();
@@ -1354,7 +1353,7 @@ mod tests {
assert_eq!(mock_hal.eeprom.get_unlock_attempts(), MAX_UNLOCK_ATTEMPTS);
assert!(matches!(
- block_on(unlock(&mut mock_hal, "password")),
+ unlock(&mut mock_hal, "password").await,
Err(Error::MaxAttemptsExceeded)
));
assert!(is_locked());
@@ -1364,8 +1363,8 @@ mod tests {
/// Ensures the failed-attempt counter resets once a correct password is entered while the
/// keystore is locked, so a later wrong attempt after relocking still sees the full allowance.
- #[test]
- fn test_unlock_failed_attempts_reset_locked() {
+ #[async_test::test]
+ async fn test_unlock_failed_attempts_reset_locked() {
mock_memory();
lock();
@@ -1379,21 +1378,19 @@ mod tests {
assert!(encrypt_and_store_seed(&mut mock_hal, &seed, "password").is_ok());
lock();
- fn wrong_attempt(hal: &mut impl crate::hal::Hal) {
+ async fn wrong_attempt(hal: &mut impl crate::hal::Hal) {
assert!(matches!(
- block_on(unlock(hal, "wrong")),
+ unlock(hal, "wrong").await,
Err(Error::IncorrectPassword)
));
assert_eq!(get_remaining_unlock_attempts(hal), MAX_UNLOCK_ATTEMPTS - 1);
}
- wrong_attempt(&mut mock_hal);
+ wrong_attempt(&mut mock_hal).await;
assert!(copy_seed(&mut mock_hal).is_err());
assert_eq!(
- block_on(unlock(&mut mock_hal, "password"))
- .unwrap()
- .as_slice(),
+ unlock(&mut mock_hal, "password").await.unwrap().as_slice(),
seed
);
assert!(copy_seed(&mut mock_hal).is_ok());
@@ -1401,15 +1398,15 @@ mod tests {
lock();
assert!(copy_seed(&mut mock_hal).is_err());
- wrong_attempt(&mut mock_hal);
+ wrong_attempt(&mut mock_hal).await;
assert!(copy_seed(&mut mock_hal).is_err());
assert!(mock_hal.memory.is_seeded());
}
/// Ensures the failed-attempt counter resets when the keystore stays unlocked throughout, so
/// interleaving wrong attempts with successful unlocks cannot exhaust the counter prematurely.
- #[test]
- fn test_unlock_failed_attempts_reset_unlocked() {
+ #[async_test::test]
+ async fn test_unlock_failed_attempts_reset_unlocked() {
mock_memory();
lock();
@@ -1424,39 +1421,35 @@ mod tests {
lock();
assert_eq!(
- block_on(unlock(&mut mock_hal, "password"))
- .unwrap()
- .as_slice(),
+ unlock(&mut mock_hal, "password").await.unwrap().as_slice(),
seed
);
assert!(copy_seed(&mut mock_hal).is_ok());
- fn wrong_attempt(hal: &mut impl crate::hal::Hal) {
+ async fn wrong_attempt(hal: &mut impl crate::hal::Hal) {
assert!(matches!(
- block_on(unlock(hal, "wrong")),
+ unlock(hal, "wrong").await,
Err(Error::IncorrectPassword)
));
assert_eq!(get_remaining_unlock_attempts(hal), MAX_UNLOCK_ATTEMPTS - 1);
}
- wrong_attempt(&mut mock_hal);
+ wrong_attempt(&mut mock_hal).await;
assert!(copy_seed(&mut mock_hal).is_ok());
assert_eq!(
- block_on(unlock(&mut mock_hal, "password"))
- .unwrap()
- .as_slice(),
+ unlock(&mut mock_hal, "password").await.unwrap().as_slice(),
seed
);
assert!(copy_seed(&mut mock_hal).is_ok());
- wrong_attempt(&mut mock_hal);
+ wrong_attempt(&mut mock_hal).await;
assert!(copy_seed(&mut mock_hal).is_ok());
assert!(mock_hal.memory.is_seeded());
}
- #[test]
- fn test_unlock_migrate_password_algo() {
+ #[async_test::test]
+ async fn test_unlock_migrate_password_algo() {
lock();
let mut mock_hal = TestingHal::new();
@@ -1495,9 +1488,7 @@ mod tests {
// Unlock will migrate from V0 to V1.
mock_hal.securechip.event_counter_reset();
assert_eq!(
- block_on(unlock(&mut mock_hal, password))
- .unwrap()
- .as_slice(),
+ unlock(&mut mock_hal, password).await.unwrap().as_slice(),
seed
);
assert_eq!(mock_hal.securechip.get_event_counter(), 9);
@@ -1510,24 +1501,20 @@ mod tests {
// Password check still works
assert_eq!(
- block_on(unlock(&mut mock_hal, "password"))
- .unwrap()
- .as_slice(),
+ unlock(&mut mock_hal, "password").await.unwrap().as_slice(),
seed
);
// Unlocking from scratch still works
lock();
assert_eq!(
- block_on(unlock(&mut mock_hal, "password"))
- .unwrap()
- .as_slice(),
+ unlock(&mut mock_hal, "password").await.unwrap().as_slice(),
seed
);
}
- #[test]
- fn test_unlock_bip39() {
+ #[async_test::test]
+ async fn test_unlock_bip39() {
mock_memory();
lock();
let mut mock_hal = TestingHal::new();
@@ -1543,12 +1530,13 @@ mod tests {
assert!(root_fingerprint().is_err());
// Incorrect seed passed
assert!(
- block_on(unlock_bip39(
+ unlock_bip39(
&mut KeystoreHalImpl::from_hal(&mut mock_hal),
b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"foo",
async || {},
- ))
+ )
+ .await
.is_err()
);
// Correct seed passed.
@@ -1560,12 +1548,13 @@ mod tests {
mock_hal.securechip.event_counter_reset();
assert!(
- block_on(unlock_bip39(
+ unlock_bip39(
&mut KeystoreHalImpl::from_hal(&mut mock_hal),
&seed,
"foo",
async || {},
- ))
+ )
+ .await
.is_ok()
);
assert_eq!(mock_hal.securechip.get_event_counter(), 1);
@@ -1909,8 +1898,8 @@ mod tests {
assert!(bip85_ln(&mut TestingHal::new(), HARDENED).is_err());
}
- #[test]
- fn test_fixtures() {
+ #[async_test::test]
+ async fn test_fixtures() {
struct Test {
seed_len: usize,
mnemonic_passphrase: &'static str,
@@ -1967,12 +1956,13 @@ mod tests {
let mut mock_hal = TestingHal::new();
assert!(
- block_on(unlock_bip39(
+ unlock_bip39(
&mut KeystoreHalImpl::from_hal(&mut mock_hal),
seed,
test.mnemonic_passphrase,
async || {},
- ))
+ )
+ .await
.is_err()
);
@@ -1984,12 +1974,13 @@ mod tests {
mock_hal.securechip.event_counter_reset();
assert!(
- block_on(unlock_bip39(
+ unlock_bip39(
&mut KeystoreHalImpl::from_hal(&mut mock_hal),
seed,
test.mnemonic_passphrase,
async || {},
- ))
+ )
+ .await
.is_ok()
);
assert_eq!(mock_hal.securechip.get_event_counter(), 1);
@@ -2135,8 +2126,8 @@ mod tests {
}
// Functional test to store seeds, lock/unlock, retrieve seed.
- #[test]
- fn test_seeds() {
+ #[async_test::test]
+ async fn test_seeds() {
let seed = hex!("cb33c20cea62a5c277527e2002da82e6e2b37450a755143a540a54cea8da9044");
for seed_size in [16, 24, 32] {
@@ -2161,7 +2152,7 @@ mod tests {
// Wrong password.
assert!(matches!(
- block_on(unlock(&mut mock_hal, "bar")),
+ unlock(&mut mock_hal, "bar").await,
Err(Error::IncorrectPassword)
));
assert_eq!(get_remaining_unlock_attempts(&mut mock_hal), 9);
@@ -2169,7 +2160,7 @@ mod tests {
// Correct password. First time: unlock. After unlock, it becomes a password check.
for _ in 0..3 {
assert_eq!(
- block_on(unlock(&mut mock_hal, "foo")).unwrap().as_slice(),
+ unlock(&mut mock_hal, "foo").await.unwrap().as_slice(),
&seed[..seed_size]
);
}
diff --git a/src/rust/bitbox02-rust/src/reset.rs b/src/rust/bitbox02-rust/src/reset.rs
index 0b335a9..ee4ea1f 100644
--- a/src/rust/bitbox02-rust/src/reset.rs
+++ b/src/rust/bitbox02-rust/src/reset.rs
@@ -77,10 +77,9 @@ mod tests {
use crate::keystore;
use crate::keystore::testing::mock_unlocked;
use bitbox02::testing::mock_memory;
- use util::bb02_async::block_on;
- #[test]
- fn test_reset_success() {
+ #[async_test::test]
+ async fn test_reset_success() {
mock_memory();
let mut hal = TestingHal::new();
@@ -98,7 +97,7 @@ mod tests {
hal.securechip.u2f_counter_set(42).unwrap();
hal.securechip.event_counter_reset();
- block_on(reset(&mut hal, true));
+ reset(&mut hal, true).await;
// Secure chip operations happened as expected: reset_keys() was retried once, but only the
// successful call increments the event counter.
assert_eq!(hal.securechip.get_event_counter(), 3);
@@ -123,12 +122,12 @@ mod tests {
);
}
- #[test]
- fn test_reset_status_failure() {
+ #[async_test::test]
+ async fn test_reset_status_failure() {
mock_memory();
let mut hal = TestingHal::new();
- block_on(reset(&mut hal, false));
+ reset(&mut hal, false).await;
assert_eq!(
hal.ui.screens,
diff --git a/src/rust/bitbox02-rust/src/workflow/mnemonic.rs b/src/rust/bitbox02-rust/src/workflow/mnemonic.rs
index cec4770..d4821ed 100644
--- a/src/rust/bitbox02-rust/src/workflow/mnemonic.rs
+++ b/src/rust/bitbox02-rust/src/workflow/mnemonic.rs
@@ -382,7 +382,6 @@ mod tests {
use super::*;
use crate::hal::testing::{TestingRandom, TestingUi};
- use util::bb02_async::block_on;
fn bruteforce_lastword(mnemonic: &[&str]) -> Vec<zeroize::Zeroizing<String>> {
let mut result = Vec::new();
@@ -416,8 +415,8 @@ mod tests {
assert_eq!(unique.len(), choices.len());
}
- #[test]
- fn test_show_and_confirm_mnemonic() {
+ #[async_test::test]
+ async fn test_show_and_confirm_mnemonic() {
let words: Vec<&str> = "boring mistake dish oyster truth pigeon viable emerge sort crash wire portion cannon couple enact box walk height pull today solid off enable tide"
.split(' ')
.collect();
@@ -425,20 +424,20 @@ mod tests {
let mut random = TestingRandom::new();
ui.prepare_show_and_confirm_mnemonic(&mut random, words.len());
- let result = block_on(show_and_confirm_mnemonic(&mut ui, &mut random, &words));
+ let result = show_and_confirm_mnemonic(&mut ui, &mut random, &words).await;
assert!(result.is_ok());
TestingUi::assert_show_and_confirm_mnemonic_screens(&ui.screens, &words);
}
- #[test]
- fn test_get() {
+ #[async_test::test]
+ async fn test_get() {
let words: Vec<&str> = "boring mistake dish oyster truth pigeon viable emerge sort crash wire portion cannon couple enact box walk height pull today solid off enable tide"
.split(' ')
.collect();
let mut ui = TestingUi::new();
ui.prepare_get_mnemonic_24_words(&words);
- let result = block_on(get(&mut ui));
+ let result = get(&mut ui).await;
assert!(result.is_ok());
let mnemonic = match result {
Ok(mnemonic) => mnemonic,
diff --git a/src/rust/bitbox02-rust/src/workflow/pairing.rs b/src/rust/bitbox02-rust/src/workflow/pairing.rs
index 2a42810..ad4d7da 100644
--- a/src/rust/bitbox02-rust/src/workflow/pairing.rs
+++ b/src/rust/bitbox02-rust/src/workflow/pairing.rs
@@ -37,17 +37,16 @@ mod tests {
use crate::hal::testing::TestingHal;
use crate::hal::testing::ui::Screen;
- use util::bb02_async::block_on;
use alloc::boxed::Box;
- #[test]
- fn test_confirm() {
+ #[async_test::test]
+ async fn test_confirm() {
let mut mock_hal = TestingHal::new();
- assert!(block_on(confirm(
+ assert!(confirm(
&mut mock_hal,
- b"\x59\x28\x9b\xdb\xbb\xb6\xb6\x8e\x8f\x12\x7f\x49\xa5\x25\xb0\x30\x13\x50\x0b\x3c\x1a\xf2\x62\x6f\x40\x07\xeb\xe4\x4f\x09\xc8\x6b")).is_ok());
+ b"\x59\x28\x9b\xdb\xbb\xb6\xb6\x8e\x8f\x12\x7f\x49\xa5\x25\xb0\x30\x13\x50\x0b\x3c\x1a\xf2\x62\x6f\x40\x07\xeb\xe4\x4f\x09\xc8\x6b").await.is_ok());
assert_eq!(
mock_hal.ui.screens,
diff --git a/src/rust/bitbox02-rust/src/workflow/password.rs b/src/rust/bitbox02-rust/src/workflow/password.rs
index 34a610c..40083ed 100644
--- a/src/rust/bitbox02-rust/src/workflow/password.rs
+++ b/src/rust/bitbox02-rust/src/workflow/password.rs
@@ -147,10 +147,9 @@ mod tests {
use super::*;
use crate::hal::testing::TestingHal;
use alloc::boxed::Box;
- use util::bb02_async::block_on;
- #[test]
- fn test_enter_default_to_digits_atecc() {
+ #[async_test::test]
+ async fn test_enter_default_to_digits_atecc() {
let mut hal = TestingHal::new();
hal.memory.set_securechip_type(SecurechipType::Atecc);
hal.ui.set_enter_string(Box::new(|params| {
@@ -158,19 +157,20 @@ mod tests {
Ok("pw".into())
}));
- let password = block_on(enter(
+ let password = enter(
&mut hal,
"Enter password",
PasswordType::DevicePassword,
CanCancel::No,
- ))
+ )
+ .await
.unwrap();
assert_eq!(password.as_str(), "pw");
}
- #[test]
- fn test_enter_default_to_digits_optiga() {
+ #[async_test::test]
+ async fn test_enter_default_to_digits_optiga() {
let mut hal = TestingHal::new();
hal.memory.set_securechip_type(SecurechipType::Optiga);
hal.ui.set_enter_string(Box::new(|params| {
@@ -178,29 +178,31 @@ mod tests {
Ok("pw".into())
}));
- let password = block_on(enter(
+ let password = enter(
&mut hal,
"Enter password",
PasswordType::DevicePassword,
CanCancel::No,
- ))
+ )
+ .await
.unwrap();
assert_eq!(password.as_str(), "pw");
}
- #[test]
- fn test_enter_cancelled() {
+ #[async_test::test]
+ async fn test_enter_cancelled() {
let mut hal = TestingHal::new();
hal.memory.set_securechip_type(SecurechipType::Atecc);
hal.ui.set_enter_string(Box::new(|_params| Err(UserAbort)));
- let result = block_on(enter(
+ let result = enter(
&mut hal,
"Enter password",
PasswordType::DevicePassword,
CanCancel::Yes,
- ));
+ )
+ .await;
assert!(matches!(result, Err(EnterError::Cancelled)));
assert!(
diff --git a/src/rust/bitbox02-rust/src/workflow/unlock.rs b/src/rust/bitbox02-rust/src/workflow/unlock.rs
index b320cb9..a61f732 100644
--- a/src/rust/bitbox02-rust/src/workflow/unlock.rs
+++ b/src/rust/bitbox02-rust/src/workflow/unlock.rs
@@ -224,12 +224,12 @@ mod tests {
use crate::hal::testing::ui::Screen;
use crate::keystore::testing::{mock_unlocked, mock_unlocked_using_mnemonic};
use alloc::boxed::Box;
- use util::bb02_async::block_on;
use hex_lit::hex;
- #[test]
- fn test_unlock_success() {
+ #[async_test::test]
+ async fn test_unlock_success() {
+ let mut password_entered = false;
let mut mock_hal = TestingHal::new();
// Set up an initialized wallet with password
@@ -245,14 +245,12 @@ mod tests {
// Lock the keystore to simulate the normal locked state
crate::keystore::lock();
- let mut password_entered = false;
-
mock_hal.ui.set_enter_string(Box::new(|_params| {
password_entered = true;
Ok("password".into())
}));
mock_hal.securechip.event_counter_reset();
- assert_eq!(block_on(unlock(&mut mock_hal)), Ok(()));
+ assert_eq!(unlock(&mut mock_hal).await, Ok(()));
// 6 for keystore unlock, 1 for keystore bip39 unlock.
assert_eq!(mock_hal.securechip.get_event_counter(), 6);
@@ -271,8 +269,9 @@ mod tests {
assert!(password_entered);
}
- #[test]
- fn test_unlock_keystore_wrong_password() {
+ #[async_test::test]
+ async fn test_unlock_keystore_wrong_password() {
+ let mut password_entered = false;
let mut mock_hal = TestingHal::new();
// Set up an initialized wallet with password
@@ -288,8 +287,6 @@ mod tests {
// Lock the keystore to simulate the normal locked state
crate::keystore::lock();
- let mut password_entered = false;
-
mock_hal.ui.set_enter_string(Box::new(|_params| {
password_entered = true;
Ok("wrong password".into())
@@ -297,7 +294,7 @@ mod tests {
mock_hal.securechip.event_counter_reset();
assert!(matches!(
- block_on(unlock_keystore(&mut mock_hal, "title", CanCancel::No,)),
+ unlock_keystore(&mut mock_hal, "title", CanCancel::No,).await,
Err(UnlockError::IncorrectPassword),
));
assert_eq!(mock_hal.securechip.get_event_counter(), 4);
@@ -317,8 +314,9 @@ mod tests {
assert!(password_entered);
}
- #[test]
- fn test_unlock_keystore_warning_before_password() {
+ #[async_test::test]
+ async fn test_unlock_keystore_warning_before_password() {
+ let mut password_entered = false;
let mut mock_hal = TestingHal::new();
// Set up an initialized wallet with password
@@ -336,15 +334,13 @@ mod tests {
mock_hal.eeprom.set_unlock_attempts_for_testing(1);
- let mut password_entered = false;
-
mock_hal.ui.set_enter_string(Box::new(|_params| {
password_entered = true;
Ok("wrong password".into())
}));
assert!(matches!(
- block_on(unlock_keystore(&mut mock_hal, "title", CanCancel::No,)),
+ unlock_keystore(&mut mock_hal, "title", CanCancel::No,).await,
Err(UnlockError::IncorrectPassword),
));
@@ -367,8 +363,8 @@ mod tests {
assert!(password_entered);
}
- #[test]
- fn test_unlock_keystore_last_attempt_warning() {
+ #[async_test::test]
+ async fn test_unlock_keystore_last_attempt_warning() {
let mut mock_hal = TestingHal::new();
mock_hal
@@ -378,7 +374,7 @@ mod tests {
mock_hal.ui.abort_nth(0);
assert!(matches!(
- block_on(unlock_keystore(&mut mock_hal, "title", CanCancel::No,)),
+ unlock_keystore(&mut mock_hal, "title", CanCancel::No,).await,
Err(UnlockError::UserAbort),
));
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.