From 085ba0feb4a6059c0710bcc3e659fcb133afcd1f Mon Sep 17 00:00:00 2001 From: Elizabeth Engelman <4752801+elizabethengelman@users.noreply.github.com> Date: Tue, 7 May 2024 15:13:00 -0400 Subject: [PATCH] Test get_public_key and get_app_config with 3 ledger devices --- .../stellar-ledger/src/emulator_tests.rs | 33 +++++++++++++++---- cmd/crates/stellar-ledger/src/speculos.rs | 24 +++++++++++--- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/cmd/crates/stellar-ledger/src/emulator_tests.rs b/cmd/crates/stellar-ledger/src/emulator_tests.rs index dc1b4df16d..dd035aa346 100644 --- a/cmd/crates/stellar-ledger/src/emulator_tests.rs +++ b/cmd/crates/stellar-ledger/src/emulator_tests.rs @@ -6,7 +6,7 @@ use soroban_env_host::xdr::{self, Operation, OperationBody, Uint256}; use std::vec; use crate::emulator_http_transport::EmulatorHttpTransport; -use crate::speculos::Speculos; +use crate::speculos::{Args, Speculos}; use crate::{LedgerError, LedgerOptions, LedgerSigner}; use std::sync::Arc; @@ -36,12 +36,21 @@ const TEST_NETWORK_PASSPHRASE: &str = "Test SDF Network ; September 2015"; // } #[tokio::test] -async fn test_get_public_key() { +async fn test_get_public_key_for_different_ledger_devices() { + let device_models = ["nanos", "nanox", "nanosp"]; + for device_model in device_models.iter() { + let args = Args { + ledger_device_model: device_model.to_string(), + }; + test_get_public_key(args).await; + } +} +async fn test_get_public_key(image_args: Args) { let docker = clients::Cli::default(); - let node = docker.run(Speculos::new()); + let args = image_args.clone(); + let node = docker.run((Speculos::new(), args)); let host_port = node.get_host_port_ipv4(9998); let ui_host_port: u16 = node.get_host_port_ipv4(5000); - wait_for_emulator_start_text(ui_host_port).await; let transport = get_zemu_transport("127.0.0.1", host_port).unwrap(); @@ -70,9 +79,19 @@ async fn test_get_public_key() { } #[tokio::test] -async fn test_get_app_configuration() { +async fn test_get_app_configuration_for_different_ledger_devices() { + let device_models = ["nanos", "nanox", "nanosp"]; + for device_model in device_models.iter() { + let args = Args { + ledger_device_model: device_model.to_string(), + }; + test_get_app_configuration(args).await; + } +} +async fn test_get_app_configuration(image_args: Args) { let docker = clients::Cli::default(); - let node = docker.run(Speculos::new()); + let args = image_args.clone(); + let node = docker.run((Speculos::new(), args)); let host_port = node.get_host_port_ipv4(9998); let ui_host_port: u16 = node.get_host_port_ipv4(5000); @@ -102,7 +121,7 @@ async fn test_get_app_configuration() { #[tokio::test] async fn test_sign_tx() { let docker = clients::Cli::default(); - let node = docker.run(Speculos::new()); + let node = docker.run((Speculos::new(), Args::default())); let host_port = node.get_host_port_ipv4(9998); let ui_host_port: u16 = node.get_host_port_ipv4(5000); diff --git a/cmd/crates/stellar-ledger/src/speculos.rs b/cmd/crates/stellar-ledger/src/speculos.rs index 13d1542112..8bed9286dc 100644 --- a/cmd/crates/stellar-ledger/src/speculos.rs +++ b/cmd/crates/stellar-ledger/src/speculos.rs @@ -38,13 +38,29 @@ impl Speculos { } } -#[derive(Debug, Default, Clone)] -pub struct Args; +#[derive(Debug, Clone)] +pub struct Args { + pub ledger_device_model: String, +} + +impl Default for Args { + fn default() -> Self { + Self { + ledger_device_model: "nanos".to_string(), + } + } +} impl ImageArgs for Args { fn into_iterator(self) -> Box> { - let container_elf_path = format!("{DEFAULT_APP_PATH}/stellarNanosApp.elf"); - let command_string = format!("/home/zondax/speculos/speculos.py --log-level speculos:DEBUG --color JADE_GREEN --display headless -s \"other base behind follow wet put glad muscle unlock sell income october\" -m nanos {container_elf_path}"); + let device_model = self.ledger_device_model.clone(); + let container_elf_path = match device_model.as_str() { + "nanos" => format!("{DEFAULT_APP_PATH}/stellarNanoSApp.elf"), + "nanox" => format!("{DEFAULT_APP_PATH}/stellarNanoXApp.elf"), + "nanosp" => format!("{DEFAULT_APP_PATH}/stellarNanoSPApp.elf"), + _ => panic!("Unsupported device model"), + }; + let command_string = format!("/home/zondax/speculos/speculos.py --log-level speculos:DEBUG --color JADE_GREEN --display headless -s \"other base behind follow wet put glad muscle unlock sell income october\" -m {device_model} {container_elf_path}"); Box::new(vec![command_string].into_iter()) } }