forked from BitBoxSwiss/bitbox02-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simulator: implement a simulator for bitbox02 device
HWI is thinking of updating its support policy such that supported wallets must implement a simulator/emulator. See bitcoin-core/HWI#685. That's why a simulator is implemented for bitbox02, supporting functionalities of its API. This first version of the simulator is capable of nearly every functionality of a normal Bitbox02 device, without promising any security or production use. Its main aim is to be able to run unit tests for features and test the API. In addition, it will be configured to run automated tests in CI, which helps both us and HWI integration. Right now, the simulator has 3 different ways to communicate with a client: giving inputs/getting output from CLI, using pipes or opening sockets. Socket is the most convenient and reliable choice in this version. It expects the clients to open a socket on port 15432, which is selected intentionally to avoid possible conflicts. The simulator resides with C unit-tests since it uses same mocks, therefore it can be built by `make unit-test`. Lastly, Python client implemented in `py/send_message.py` is updated to support communicating with simulator with the socket configuration mentioned above. Client can be started up with `./py/send_message.py --simulator` command. To run the simulator, `build-build/bin/test_simulator` command is sufficient. Signed-off-by: asi345 <[email protected]>
- Loading branch information
Showing
13 changed files
with
657 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
.ccls-cache | ||
compile_commands.json | ||
compile_flags.txt | ||
.vscode | ||
|
||
# gnu global | ||
/src/GPATH | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
// Copyright 2020 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. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//! Stubs for testing. | ||
pub use super::types::{ | ||
AcceptRejectCb, ConfirmParams, ContinueCancelCb, Font, MenuParams, SelectWordCb, TrinaryChoice, | ||
TrinaryChoiceCb, TrinaryInputStringParams, | ||
}; | ||
|
||
use crate::input::SafeInputString; | ||
|
||
use core::marker::PhantomData; | ||
|
||
extern crate alloc; | ||
|
||
pub struct Component<'a> { | ||
is_pushed: bool, | ||
_p: PhantomData<&'a ()>, | ||
} | ||
|
||
impl<'a> Component<'a> { | ||
pub fn screen_stack_push(&mut self) { | ||
if self.is_pushed { | ||
panic!("component pushed twice"); | ||
} | ||
self.is_pushed = true; | ||
} | ||
} | ||
|
||
impl<'a> Drop for Component<'a> { | ||
fn drop(&mut self) { | ||
if !self.is_pushed { | ||
panic!("component not pushed"); | ||
} | ||
} | ||
} | ||
|
||
pub fn trinary_input_string_create<'a, F>( | ||
_params: &TrinaryInputStringParams, | ||
mut confirm_callback: F, | ||
_cancel_callback: Option<ContinueCancelCb<'a>>, | ||
) -> Component<'a> | ||
where | ||
F: FnMut(SafeInputString) + 'a, | ||
{ | ||
confirm_callback(SafeInputString::new()); | ||
Component { | ||
is_pushed: false, | ||
_p: PhantomData, | ||
} | ||
} | ||
|
||
pub fn confirm_create<'a, F>(_params: &ConfirmParams, mut result_callback: F) -> Component<'a> | ||
where | ||
F: FnMut(bool) + 'a, | ||
{ | ||
result_callback(true); | ||
Component { | ||
is_pushed: false, | ||
_p: PhantomData, | ||
} | ||
} | ||
|
||
pub fn screen_process() {} | ||
|
||
pub fn status_create<'a, F>(_text: &str, _status_success: bool, mut callback: F) -> Component<'a> | ||
where | ||
F: FnMut() + 'a, | ||
{ | ||
callback(); | ||
Component { | ||
is_pushed: false, | ||
_p: PhantomData, | ||
} | ||
} | ||
|
||
pub fn sdcard_create<'a, F>(_insert: bool, mut continue_callback: F) -> Component<'a> | ||
where | ||
F: FnMut() + 'a, | ||
{ | ||
continue_callback(); | ||
Component { | ||
is_pushed: false, | ||
_p: PhantomData, | ||
} | ||
} | ||
|
||
pub fn menu_create(_params: MenuParams<'_>) -> Component<'_> { | ||
panic!("not implemented"); | ||
} | ||
|
||
pub fn trinary_choice_create<'a>( | ||
_message: &'a str, | ||
_label_left: &'a str, | ||
_label_middle: &'a str, | ||
_label_right: &'a str, | ||
_chosen_callback: TrinaryChoiceCb, | ||
) -> Component<'a> { | ||
panic!("not implemented") | ||
} | ||
|
||
pub fn confirm_transaction_address_create<'a, 'b>( | ||
_amount: &'a str, | ||
_address: &'a str, | ||
mut callback: AcceptRejectCb<'b>, | ||
) -> Component<'b> { | ||
callback(true); | ||
Component { | ||
is_pushed: false, | ||
_p: PhantomData, | ||
} | ||
} | ||
|
||
pub fn confirm_transaction_fee_create<'a, 'b>( | ||
_amount: &'a str, | ||
_fee: &'a str, | ||
_longtouch: bool, | ||
mut callback: AcceptRejectCb<'b>, | ||
) -> Component<'b> { | ||
callback(true); | ||
Component { | ||
is_pushed: false, | ||
_p: PhantomData, | ||
} | ||
} | ||
|
||
pub fn trinary_input_string_set_input(_component: &mut Component, _word: &str) { | ||
panic!("not implemented") | ||
} | ||
|
||
pub fn with_lock_animation<F: Fn()>(f: F) { | ||
f() | ||
} | ||
|
||
pub fn screen_stack_pop_all() {} | ||
|
||
pub fn progress_create<'a>(_title: &str) -> Component<'a> { | ||
Component { | ||
is_pushed: false, | ||
_p: PhantomData, | ||
} | ||
} | ||
|
||
pub fn progress_set(_component: &mut Component, _progress: f32) {} | ||
|
||
pub fn empty_create<'a>() -> Component<'a> { | ||
Component { | ||
is_pushed: false, | ||
_p: PhantomData, | ||
} | ||
} |
Binary file not shown.
Oops, something went wrong.