Skip to content

Commit

Permalink
Test get_public_key and get_app_config with 3 ledger devices
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman committed May 8, 2024
1 parent fbfcaef commit 085ba0f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
33 changes: 26 additions & 7 deletions cmd/crates/stellar-ledger/src/emulator_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
24 changes: 20 additions & 4 deletions cmd/crates/stellar-ledger/src/speculos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Iterator<Item = String>> {
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())
}
}
Expand Down

0 comments on commit 085ba0f

Please sign in to comment.