Skip to content

Commit

Permalink
Update code + test snapshots following C string conversion support in…
Browse files Browse the repository at this point in the history
… Rust SDK.
  • Loading branch information
agrojean-ledger committed Apr 23, 2024
1 parent 2210005 commit 7ac5f79
Show file tree
Hide file tree
Showing 36 changed files with 69 additions and 34 deletions.
49 changes: 37 additions & 12 deletions Cargo.lock

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

10 changes: 8 additions & 2 deletions src/app_ui/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ use ledger_device_sdk::ui::bitmaps::{CROSSMARK, EYE, VALIDATE_14};
use ledger_device_sdk::ui::gadgets::{Field, MultiFieldReview};

#[cfg(target_os = "stax")]
use ledger_device_sdk::nbgl::NbglAddressConfirm;
use ledger_device_sdk::nbgl::{NbglAddressConfirm, NbglGlyph};

#[cfg(target_os = "stax")]
use include_gif::include_gif;

// Display only the last 20 bytes of the address
const DISPLAY_ADDR_BYTES_LEN: usize = 20;
Expand Down Expand Up @@ -62,6 +65,9 @@ pub fn ui_display_pk(addr: &[u8]) -> Result<bool, AppSW> {

#[cfg(target_os = "stax")]
{
Ok(NbglAddressConfirm::new().show(addr_hex))
// Load glyph from 64x64 4bpp gif file with include_gif macro. Creates an NBGL compatible glyph.
const FERRIS: NbglGlyph = NbglGlyph::from_include(include_gif!("crab_64x64.gif", NBGL));
// Display the address confirmation screen.
Ok(NbglAddressConfirm::new().glyph(&FERRIS).show(addr_hex))
}
}
4 changes: 3 additions & 1 deletion src/app_ui/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ pub fn ui_menu_main(comm: &mut Comm) -> Event<Instruction> {

#[cfg(target_os = "stax")]
pub fn ui_menu_main(comm: &mut Comm) -> Event<Instruction> {
// Load glyph from 64x64 4bpp gif file with include_gif macro. Creates an NBGL compatible glyph.
const FERRIS: NbglGlyph = NbglGlyph::from_include(include_gif!("crab_64x64.gif", NBGL));
// Display the home screen.
NbglHome::new(comm)
.app_name("Boilerplate\0")
.app_name("Boilerplate")
.info_contents(env!("CARGO_PKG_VERSION"), env!("CARGO_PKG_AUTHORS"))
.glyph(&FERRIS)
.show()
Expand Down
25 changes: 11 additions & 14 deletions src/app_ui/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ use crate::handlers::sign_tx::Tx;
use crate::utils::concatenate;
use crate::AppSW;

use ledger_secure_sdk_sys::*;

#[cfg(not(target_os = "stax"))]
use ledger_device_sdk::ui::bitmaps::{CROSSMARK, EYE, VALIDATE_14};
#[cfg(not(target_os = "stax"))]
Expand Down Expand Up @@ -92,18 +90,17 @@ pub fn ui_display_tx(tx: &Tx) -> Result<bool, AppSW> {

#[cfg(target_os = "stax")]
{
// This will copy the fields into the nbgl format, not ideal
// memory-wise...
let nbgl_fields: [nbgl_layoutTagValue_t; 3] = [
my_fields[0].into(),
my_fields[1].into(),
my_fields[2].into(),
];

// Load glyph from 64x64 4bpp gif file with include_gif macro. Creates an NBGL compatible glyph.
const FERRIS: NbglGlyph = NbglGlyph::from_include(include_gif!("crab_64x64.gif", NBGL));
Ok(NbglReview::new()
.status_strings("TRANSACTION\nSIGNED\0", "Transaction\nRejected\0")
.glyph(&FERRIS)
.show(&nbgl_fields))
// Create NBGL review. Maximum number of fields and string buffer length can be customised
// with constant generic parameters of NbglReview. Default values are 32 and 1024 respectively.
let mut review: NbglReview = NbglReview::new()
.titles(
"Please review transaction",
"To send CRAB",
"Sign transaction\nto send CRAB",
)
.glyph(&FERRIS);
Ok(review.show(&my_fields))
}
}
Binary file modified tests/snapshots/stax/test_app_mainmenu/00000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_app_mainmenu/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_app_mainmenu/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_get_public_key_confirm_accepted/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_get_public_key_confirm_refused/00000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_get_public_key_confirm_refused/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file modified tests/snapshots/stax/test_sign_tx_long_tx/00000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_sign_tx_long_tx/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_sign_tx_long_tx/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_sign_tx_long_tx/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_sign_tx_long_tx/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_sign_tx_refused/00000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_sign_tx_refused/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_sign_tx_refused/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_sign_tx_refused/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/snapshots/stax/test_sign_tx_short_tx/00000.png
Binary file modified tests/snapshots/stax/test_sign_tx_short_tx/00001.png
Binary file modified tests/snapshots/stax/test_sign_tx_short_tx/00002.png
Binary file modified tests/snapshots/stax/test_sign_tx_short_tx/00003.png
4 changes: 2 additions & 2 deletions tests/test_app_mainmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def test_app_mainmenu(firmware, navigator, test_name):
]
else:
instructions = [
NavInsID.USE_CASE_HOME_INFO,
NavInsID.USE_CASE_SETTINGS_SINGLE_PAGE_EXIT
NavInsID.USE_CASE_HOME_SETTINGS,
NavInsID.USE_CASE_SUB_SETTINGS_EXIT
]
navigator.navigate_and_compare(ROOT_SCREENSHOT_PATH, test_name, instructions,
screen_change_before_first_instruction=False)
11 changes: 8 additions & 3 deletions tests/test_sign_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def test_sign_tx_short_tx(firmware, backend, navigator, test_name):
test_name)
else:
navigator.navigate_until_text_and_compare(NavInsID.USE_CASE_REVIEW_TAP,
[NavInsID.USE_CASE_REVIEW_CONFIRM],
[NavInsID.USE_CASE_REVIEW_CONFIRM,
NavInsID.WAIT_FOR_HOME_SCREEN],
"Hold to sign",
ROOT_SCREENSHOT_PATH,
test_name)
Expand Down Expand Up @@ -88,7 +89,8 @@ def test_sign_tx_long_tx(firmware, backend, navigator, test_name):
test_name)
else:
navigator.navigate_until_text_and_compare(NavInsID.USE_CASE_REVIEW_TAP,
[NavInsID.USE_CASE_REVIEW_CONFIRM],
[NavInsID.USE_CASE_REVIEW_CONFIRM,
NavInsID.WAIT_FOR_HOME_SCREEN],
"Hold to sign",
ROOT_SCREENSHOT_PATH,
test_name)
Expand Down Expand Up @@ -130,7 +132,10 @@ def test_sign_tx_refused(firmware, backend, navigator, test_name):
else:
instructions = [NavInsID.USE_CASE_REVIEW_TAP,
NavInsID.USE_CASE_REVIEW_TAP,
NavInsID.USE_CASE_REVIEW_REJECT]
NavInsID.USE_CASE_REVIEW_REJECT,
NavInsID.USE_CASE_CHOICE_CONFIRM,
NavInsID.WAIT_FOR_HOME_SCREEN
]
with pytest.raises(ExceptionRAPDU) as e:
with client.sign_tx(path=path, transaction=transaction):
navigator.navigate_and_compare(ROOT_SCREENSHOT_PATH,
Expand Down

0 comments on commit 7ac5f79

Please sign in to comment.