Skip to content

Commit

Permalink
Test sign_tx 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 4ed97fb commit 436e915
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions cmd/crates/stellar-ledger/src/emulator_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,20 @@ async fn test_get_app_configuration(image_args: Args) {
}

#[tokio::test]
async fn test_sign_tx() {
async fn test_sign_tx_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(),
};
println!("Running test_sign_tx for {device_model}");
test_sign_tx(args).await;
}
}
async fn test_sign_tx(image_args: Args) {
let docker = clients::Cli::default();
let node = docker.run((Speculos::new(), Args::default()));
let node = docker.run((Speculos::new(), image_args.clone()));

let host_port = node.get_host_port_ipv4(9998);
let ui_host_port: u16 = node.get_host_port_ipv4(5000);

Expand Down Expand Up @@ -192,7 +203,8 @@ async fn test_sign_tx() {
let ledger = Arc::clone(&ledger);
async move { ledger.sign_transaction(path, tx).await }
});
let approve = tokio::task::spawn(approve_tx_signature(ui_host_port));
let args = image_args.clone();
let approve = tokio::task::spawn(approve_tx_signature(ui_host_port, args.ledger_device_model));

let result = sign.await.unwrap();
let _ = approve.await.unwrap();
Expand Down Expand Up @@ -428,14 +440,17 @@ async fn approve_tx_hash_signature(ui_host_port: u16) {
click(ui_host_port, "button/both").await;
}

async fn approve_tx_signature(ui_host_port: u16) {
async fn approve_tx_signature(ui_host_port: u16, device_model: String) {
println!("approving tx on the device");
let mut map = HashMap::new();
map.insert("action", "press-and-release");

// press right button 17 times
// for sp and nanox it should only be 11 times

let number_of_right_clicks = if device_model == "nanos" { 17 } else { 11 };
let client = reqwest::Client::new();
for _ in 0..17 {
for _ in 0..number_of_right_clicks {
client
.post(format!("http://localhost:{ui_host_port}/button/right"))
.json(&map)
Expand Down

0 comments on commit 436e915

Please sign in to comment.