What changed, and why it matters
This commit only changes test code. It removes an old test helper called mock_memory() and updates unit tests to use a newer testing framework (HAL, or Hardware Abstraction Layer). There is no change to the actual firmware that runs on the BitBox02 device, so it cannot affect real users or introduce a security vulnerability in shipped code.
No security action required. Treat as routine test-code cleanup. If reviewing further, verify that the new TestingHal memory mock provides equivalent test coverage and isolation compared with the removed mock_memory helper.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff deletes calls to bitbox02::testing::mock_memory() across nine Rust test modules and removes one unused import of bitbox02::memory. The tests now rely on TestingHal and its mock memory implementation instead of a separate global mock. No production code paths are modified. This is a refactoring of the test harness with no runtime security relevance.
Changed components
src/rust/bitbox02-rust/src/hww.rs (tests only)src/rust/bitbox02-rust/src/hww/api/backup.rs (tests only)src/rust/bitbox02-rust/src/hww/api/change_password.rs (tests only)src/rust/bitbox02-rust/src/hww/api/reset.rs (tests only)src/rust/bitbox02-rust/src/hww/api/restore.rs (tests only)src/rust/bitbox02-rust/src/hww/api/set_password.rs (tests only)src/rust/bitbox02-rust/src/hww/api/show_mnemonic.rs (tests only)src/rust/bitbox02-rust/src/keystore.rs (tests only)src/rust/bitbox02-rust/src/reset.rs (tests only)Inspect captured patch +0 / −61
diff --git a/src/rust/bitbox02-rust/src/hww.rs b/src/rust/bitbox02-rust/src/hww.rs
index 9476628..81709fe 100644
--- a/src/rust/bitbox02-rust/src/hww.rs
+++ b/src/rust/bitbox02-rust/src/hww.rs
@@ -131,7 +131,6 @@ mod tests {
use crate::hal::testing::TestingHal;
use crate::hal::testing::ui::Screen;
- use bitbox02::testing::mock_memory;
use util::bb02_async::block_on;
use prost::Message;
@@ -218,7 +217,6 @@ mod tests {
/// Can't unlock when the device is not initialized yet (not seeded).
#[async_test::test]
async fn test_cant_unlock() {
- mock_memory();
assert_eq!(
process_packet(&mut TestingHal::new(), vec![OP_UNLOCK]).await,
[OP_STATUS_FAILURE_UNINITIALIZED].to_vec()
@@ -228,7 +226,6 @@ mod tests {
/// Test establishing a noise channel and sending/receiving an API request over it.
#[test]
fn test_noise() {
- mock_memory();
let mut make_request = init_noise();
let request = crate::pb::Request {
request: Some(crate::pb::request::Request::ListBackups(
@@ -251,8 +248,6 @@ mod tests {
/// Can initiate noise and send the Reboot protobuf request when the device is not seeded.
#[test]
fn test_reboot_when_uninitialized() {
- mock_memory();
-
let mut make_request = init_noise();
let request = crate::pb::Request {
request: Some(crate::pb::request::Request::Reboot(
@@ -286,8 +281,6 @@ mod tests {
/// Can initiate noise and send the Reboot protobuf request when the device is seeded.
#[test]
fn test_reboot_when_seeded() {
- mock_memory();
-
let mut make_request = init_noise();
let mut mock_hal = TestingHal::new();
@@ -354,8 +347,6 @@ mod tests {
/// Can initiate noise and send the Reboot protobuf request when the device is initialized.
#[async_test::test]
async fn test_reboot_when_initialized() {
- mock_memory();
-
let mut make_request = init_noise();
crate::keystore::lock();
@@ -476,7 +467,6 @@ mod tests {
&b"aaaaaaaaaaaaaaaa"[..],
] {
crate::keystore::lock();
- mock_memory();
let mut make_request = init_noise();
let mut mock_hal = TestingHal::new();
diff --git a/src/rust/bitbox02-rust/src/hww/api/backup.rs b/src/rust/bitbox02-rust/src/hww/api/backup.rs
index c2b82da..7b2d052 100644
--- a/src/rust/bitbox02-rust/src/hww/api/backup.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/backup.rs
@@ -155,7 +155,6 @@ mod tests {
use crate::hal::testing::ui::Screen;
use crate::keystore::testing::{mock_unlocked, mock_unlocked_using_mnemonic};
use alloc::boxed::Box;
- use bitbox02::testing::mock_memory;
/// Test backup creation on a uninitialized keystore.
#[async_test::test]
@@ -163,7 +162,6 @@ mod tests {
const EXPECTED_TIMESTMAP: u32 = 1601281809;
// All good.
- mock_memory();
mock_unlocked();
let mut mock_hal = TestingHal::new();
@@ -210,8 +208,6 @@ mod tests {
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")
@@ -272,7 +268,6 @@ mod tests {
async fn test_fixture() {
const EXPECTED_ID: &str =
"577782fdfffbe314b23acaeefc39ad5e8641fba7e7dbe418a35956a879a67dd2";
- mock_memory();
mock_unlocked_using_mnemonic(
"memory raven era cave phone system dice come mechanic split moon repeat",
"",
@@ -342,7 +337,6 @@ mod tests {
);
// Create one backup.
- mock_memory();
mock_unlocked_using_mnemonic(
"purity concert above invest pigeon category peace tuition hazard vivid latin since legal speak nation session onion library travel spell region blast estate stay",
"",
@@ -378,7 +372,6 @@ mod tests {
// because the above backup creation set the initialized flag.
mock_hal.memory.reset_hww().unwrap();
- mock_memory();
mock_unlocked_using_mnemonic(
"goddess item rack improve shaft occur actress rib emerge salad rich blame model glare lounge stable electric height scrub scrub oyster now dinner oven",
"",
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 e331527..f8241ff 100644
--- a/src/rust/bitbox02-rust/src/hww/api/change_password.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/change_password.rs
@@ -42,14 +42,12 @@ mod tests {
use crate::hal::{Memory, testing::TestingHal};
use crate::workflow::unlock;
use alloc::boxed::Box;
- use bitbox02::testing::mock_memory;
use hex_lit::hex;
// Test the intended success path
#[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";
@@ -131,8 +129,6 @@ mod tests {
// Test that we fail if the unlock fails
#[async_test::test]
async fn test_process_unlock_failure() {
- mock_memory();
-
let seed = hex!("c7940c13479b8d9a6498f4e50d5a42e0d617bc8e8ac9f2b8cecf97e94c2b035c");
let correct_password = "correct_password";
@@ -188,8 +184,6 @@ mod tests {
// Test that we fail if the confirm password mismatch
#[async_test::test]
async fn test_process_confirm_password_mismatch() {
- mock_memory();
-
let seed = hex!("c7940c13479b8d9a6498f4e50d5a42e0d617bc8e8ac9f2b8cecf97e94c2b035c");
let old_password = "old_password";
let first_password = "first_password";
diff --git a/src/rust/bitbox02-rust/src/hww/api/reset.rs b/src/rust/bitbox02-rust/src/hww/api/reset.rs
index 5cd9c84..7a19755 100644
--- a/src/rust/bitbox02-rust/src/hww/api/reset.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/reset.rs
@@ -30,12 +30,9 @@ mod tests {
use crate::hal::testing::ui::Screen;
use crate::hal::{Memory, testing::TestingHal};
use alloc::boxed::Box;
- use bitbox02::testing::mock_memory;
#[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();
diff --git a/src/rust/bitbox02-rust/src/hww/api/restore.rs b/src/rust/bitbox02-rust/src/hww/api/restore.rs
index c7d35b6..21ee5f4 100644
--- a/src/rust/bitbox02-rust/src/hww/api/restore.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/restore.rs
@@ -158,7 +158,6 @@ mod tests {
use super::*;
use crate::hal::testing::TestingHal;
- use bitbox02::memory;
use alloc::boxed::Box;
use alloc::vec::Vec;
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 614646f..717fe08 100644
--- a/src/rust/bitbox02-rust/src/hww/api/set_password.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/set_password.rs
@@ -38,13 +38,11 @@ mod tests {
use super::*;
use crate::hal::testing::TestingHal;
- use bitbox02::testing::mock_memory;
use alloc::boxed::Box;
#[async_test::test]
async fn test_process() {
- mock_memory();
keystore::lock();
let mut counter = 0u32;
let mut mock_hal = TestingHal::new();
@@ -80,7 +78,6 @@ mod tests {
/// Shorter host entropy results in shorter seed.
#[async_test::test]
async fn test_process_16_bytes() {
- mock_memory();
keystore::lock();
let mut mock_hal = TestingHal::new();
mock_hal
@@ -103,7 +100,6 @@ mod tests {
/// Invalid host entropy size.
#[async_test::test]
async fn test_process_invalid_host_entropy() {
- mock_memory();
keystore::lock();
let mut mock_hal = TestingHal::new();
mock_hal
@@ -125,7 +121,6 @@ mod tests {
#[async_test::test]
async fn test_process_2nd_password_doesnt_match() {
- mock_memory();
keystore::lock();
let mut counter = 0u32;
let mut mock_hal = TestingHal::new();
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 c3b882f..e7b5d28 100644
--- a/src/rust/bitbox02-rust/src/hww/api/show_mnemonic.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/show_mnemonic.rs
@@ -65,7 +65,6 @@ mod tests {
use crate::hal::testing::ui::Screen;
use crate::hal::testing::{TestingHal, TestingUi};
- use bitbox02::testing::mock_memory;
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";
@@ -73,7 +72,6 @@ mod tests {
/// wallet setup.
#[async_test::test]
async fn test_process_uninitialized() {
- mock_memory();
let mut mock_hal = TestingHal::new();
crate::keystore::encrypt_and_store_seed(
&mut mock_hal,
@@ -132,7 +130,6 @@ mod tests {
/// When initialized, a password check is prompted before displaying the mnemonic.
#[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(
@@ -198,8 +195,6 @@ mod tests {
/// This tests that we fail early if the wrong password is entered.
#[async_test::test]
async fn test_process_initialized_wrong_password() {
- mock_memory();
-
let mut mock_hal = TestingHal::new();
crate::keystore::encrypt_and_store_seed(
diff --git a/src/rust/bitbox02-rust/src/keystore.rs b/src/rust/bitbox02-rust/src/keystore.rs
index 3bf4d9d..9b1a5dd 100644
--- a/src/rust/bitbox02-rust/src/keystore.rs
+++ b/src/rust/bitbox02-rust/src/keystore.rs
@@ -891,7 +891,6 @@ mod tests {
use hex_lit::hex;
use sha2::Digest;
- use bitbox02::testing::mock_memory;
use testing::{TEST_MNEMONIC, mock_unlocked, mock_unlocked_using_mnemonic};
use bitcoin::secp256k1;
@@ -931,7 +930,6 @@ mod tests {
#[async_test::test]
async fn test_encrypt_and_store_seed_invalid_size() {
- mock_memory();
lock();
assert!(matches!(
encrypt_and_store_seed(&mut TestingHal::new(), &[0; 31], "foo").await,
@@ -1014,7 +1012,6 @@ mod tests {
#[async_test::test]
async fn test_re_encrypt_seed() {
- mock_memory();
lock();
let mut mock_hal = TestingHal::new();
@@ -1029,7 +1026,6 @@ mod tests {
#[async_test::test]
async fn test_re_encrypt_seed_changes_password() {
- mock_memory();
lock();
let mut mock_hal = TestingHal::new();
@@ -1078,7 +1074,6 @@ mod tests {
#[async_test::test]
async fn test_re_encrypt_seed_preserves_seeds_and_fingerprint() {
- mock_memory();
lock();
let mut mock_hal = TestingHal::new();
@@ -1130,7 +1125,6 @@ mod tests {
#[async_test::test]
async fn test_re_encrypt_seed_invalid_seed_size() {
- mock_memory();
lock();
let mut mock_hal = TestingHal::new();
@@ -1164,7 +1158,6 @@ mod tests {
#[async_test::test]
async fn test_retain_bip39_seed() {
- mock_memory();
lock();
let mut mock_hal = TestingHal::new();
@@ -1189,7 +1182,6 @@ mod tests {
#[async_test::test]
async fn test_retain_bip39_seed_overwrites_previous() {
- mock_memory();
lock();
let mut mock_hal = TestingHal::new();
let bip39_seed1 = hex!(
@@ -1227,7 +1219,6 @@ mod tests {
// but before creating a backup, in which case a new seed is created.
#[async_test::test]
async fn test_create_and_unlock_twice() {
- mock_memory();
lock();
let seed = hex!("cb33c20cea62a5c277527e2002da82e6e2b37450a755143a540a54cea8da9044");
@@ -1279,7 +1270,6 @@ mod tests {
#[async_test::test]
async fn test_unlock() {
- mock_memory();
lock();
let mut mock_hal = TestingHal::new();
@@ -1370,7 +1360,6 @@ mod tests {
#[async_test::test]
async fn test_unlock_lockout_while_locked() {
- mock_memory();
lock();
let mut mock_hal = TestingHal::new();
@@ -1422,7 +1411,6 @@ mod tests {
/// secure chip operations.
#[async_test::test]
async fn test_unlock_preexisting_lockout() {
- mock_memory();
lock();
let mut mock_hal = TestingHal::new();
@@ -1460,7 +1448,6 @@ mod tests {
/// keystore is locked, so a later wrong attempt after relocking still sees the full allowance.
#[async_test::test]
async fn test_unlock_failed_attempts_reset_locked() {
- mock_memory();
lock();
let mut mock_hal = TestingHal::new();
@@ -1506,7 +1493,6 @@ mod tests {
/// interleaving wrong attempts with successful unlocks cannot exhaust the counter prematurely.
#[async_test::test]
async fn test_unlock_failed_attempts_reset_unlocked() {
- mock_memory();
lock();
let mut mock_hal = TestingHal::new();
@@ -1618,7 +1604,6 @@ mod tests {
#[async_test::test]
async fn test_unlock_bip39() {
- mock_memory();
lock();
let mut mock_hal = TestingHal::new();
@@ -1917,7 +1902,6 @@ mod tests {
#[async_test::test]
async fn test_stretch_retained_seed_encryption_key_success() {
- mock_memory();
let mut mock_hal = TestingHal::new();
let salt_root = hex!("0000000000000000111111111111111122222222222222223333333333333333");
mock_hal.memory.set_salt_root(&salt_root);
@@ -1940,7 +1924,6 @@ mod tests {
#[async_test::test]
async fn test_stretch_retained_seed_encryption_key_salt_error() {
- mock_memory();
let mut mock_hal = TestingHal::new();
mock_hal.memory.set_salt_root(&[0xffu8; 32]);
@@ -2107,7 +2090,6 @@ mod tests {
];
for test in tests {
- mock_memory();
lock();
let seed = &seed[..test.seed_len];
@@ -2298,7 +2280,6 @@ mod tests {
let seed = hex!("cb33c20cea62a5c277527e2002da82e6e2b37450a755143a540a54cea8da9044");
for seed_size in [16, 24, 32] {
- mock_memory();
lock();
let mut mock_hal = TestingHal::new();
diff --git a/src/rust/bitbox02-rust/src/reset.rs b/src/rust/bitbox02-rust/src/reset.rs
index 2198ae1..d48a628 100644
--- a/src/rust/bitbox02-rust/src/reset.rs
+++ b/src/rust/bitbox02-rust/src/reset.rs
@@ -76,12 +76,9 @@ mod tests {
use crate::hal::testing::ui::Screen;
use crate::keystore;
use crate::keystore::testing::mock_unlocked;
- use bitbox02::testing::mock_memory;
#[async_test::test]
async fn test_reset_success() {
- mock_memory();
-
let mut hal = TestingHal::new();
keystore::lock();
@@ -124,8 +121,6 @@ mod tests {
#[async_test::test]
async fn test_reset_status_failure() {
- mock_memory();
-
let mut hal = TestingHal::new();
reset(&mut hal, false).await;
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.