Skip to content

Commit

Permalink
Merge branch 'lazystatic'
Browse files Browse the repository at this point in the history
  • Loading branch information
benma committed Jul 26, 2024
2 parents cb481ba + becda2e commit a717448
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 39 deletions.
8 changes: 0 additions & 8 deletions src/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ resolver = "2"
[workspace.dependencies]
bitcoin = { version = "0.32.2", default-features = false }
hex = { version = "0.4", default-features = false, features = ["alloc"] }
lazy_static = { version = "1.4.0" }
num-bigint = { version = "0.4.3", default-features = false }
sha2 = { version = "0.10.8", default-features = false }
sha3 = { version = "0.10.8", default-features = false }
Expand Down
4 changes: 0 additions & 4 deletions src/rust/bitbox02-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ blake2 = { version = "0.10.6", default-features = false, features = ["size_opt"]
minicbor = { version = "0.24.0", default-features = false, features = ["alloc"], optional = true }
crc = { version = "3.0.1", optional = true }
ed25519-dalek = { version = "2.1.1", default-features = false, features = ["hazmat", "digest"], optional = true }
lazy_static = { workspace = true, optional = true }
hmac = { version = "0.12.1", default-features = false, features = ["reset"] }

miniscript = { version = "12.0.0", default-features = false, features = ["no-std"], optional = true }
Expand Down Expand Up @@ -110,9 +109,6 @@ app-cardano = [
]

testing = [
# enable these deps
"lazy_static",

# enable these features
"bitbox02/testing"
]
Expand Down
21 changes: 9 additions & 12 deletions src/rust/bitbox02-rust/src/hww.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,17 @@ pub struct SafeData<T>(T);
unsafe impl<T> Sync for SafeData<T> {}

#[cfg(feature = "testing")]
lazy_static! {
pub static ref MOCK_NEXT_REQUEST: SafeData<
core::cell::RefCell<
Option<
alloc::boxed::Box<
dyn Fn(
crate::pb::response::Response,
)
-> Result<crate::pb::request::Request, api::error::Error>,
>,
pub static MOCK_NEXT_REQUEST: SafeData<
core::cell::RefCell<
Option<
alloc::boxed::Box<
dyn Fn(
crate::pb::response::Response,
) -> Result<crate::pb::request::Request, api::error::Error>,
>,
>,
> = SafeData(core::cell::RefCell::new(None));
}
>,
> = SafeData(core::cell::RefCell::new(None));

/// Set `MOCK_NEXT_REQUEST` to mock requests from the host.
#[cfg(feature = "testing")]
Expand Down
4 changes: 0 additions & 4 deletions src/rust/bitbox02-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ mod xpubcache;
#[macro_use]
extern crate alloc;

#[cfg(feature = "testing")]
#[macro_use]
extern crate lazy_static;

#[cfg(test)]
mod test {
use super::*;
Expand Down
3 changes: 1 addition & 2 deletions src/rust/bitbox02/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ license = "Apache-2.0"
bitbox02-sys = {path="../bitbox02-sys"}
util = {path = "../util"}
zeroize = { workspace = true }
lazy_static = { workspace = true, optional = true }

[features]
# Only to be enabled in unit tests.
testing = ["lazy_static"]
testing = []
# Active when the Rust code is compiled to be linked into the C unit tests and simulator.
c-unit-testing = []

Expand Down
4 changes: 0 additions & 4 deletions src/rust/bitbox02/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ extern crate alloc;

use alloc::string::String;

#[cfg(feature = "testing")]
#[macro_use]
extern crate lazy_static;

#[cfg(feature = "testing")]
pub mod testing;

Expand Down
13 changes: 9 additions & 4 deletions src/rust/bitbox02/src/testing.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Shift Crypto AG
// Copyright 2020-2024 Shift Crypto AG
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,9 +37,14 @@ pub struct SafeData(pub RefCell<Data>);
// Safety: must not be accessed concurrently.
unsafe impl Sync for SafeData {}

lazy_static! {
pub static ref DATA: SafeData = SafeData(RefCell::new(Default::default()));
}
pub static DATA: SafeData = SafeData(RefCell::new(Data {
ui_confirm_create: None,
sdcard_inserted: None,
ui_sdcard_create_arg: None,
ui_transaction_address_create: None,
ui_transaction_fee_create: None,
ui_trinary_input_string_create: None,
}));

/// Provide mock implementations and data. This also locks the keystore - use `mock_unlocked()` to mock a seeded and unlocked keystore.
pub fn mock(data: Data) {
Expand Down

0 comments on commit a717448

Please sign in to comment.