diff --git a/Cargo.lock b/Cargo.lock index 50a60714aa..d8675167fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5033,6 +5033,7 @@ dependencies = [ "stellar-rpc-client", "stellar-strkey 0.0.8", "stellar-xdr", + "test-case", "testcontainers", "thiserror", "tokio", @@ -5285,6 +5286,39 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" +[[package]] +name = "test-case" +version = "3.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb2550dd13afcd286853192af8601920d959b14c401fcece38071d53bf0768a8" +dependencies = [ + "test-case-macros", +] + +[[package]] +name = "test-case-core" +version = "3.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adcb7fd841cd518e279be3d5a3eb0636409487998a4aff22f3de87b81e88384f" +dependencies = [ + "cfg-if", + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "test-case-macros" +version = "3.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c89e72a01ed4c579669add59014b9a524d609c0c88c6a585ce37485879f6ffb" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", + "test-case-core", +] + [[package]] name = "test_custom_types" version = "21.0.0-rc.1" diff --git a/cmd/crates/stellar-ledger/Cargo.toml b/cmd/crates/stellar-ledger/Cargo.toml index 89676db08c..8fa593a5af 100644 --- a/cmd/crates/stellar-ledger/Cargo.toml +++ b/cmd/crates/stellar-ledger/Cargo.toml @@ -49,6 +49,7 @@ once_cell = "1.19.0" pretty_assertions = "1.2.1" serial_test = "3.0.0" httpmock = "0.7.0-rc.1" +test-case = "*" [features] diff --git a/cmd/crates/stellar-ledger/tests/test/emulator_tests.rs b/cmd/crates/stellar-ledger/tests/test/emulator_tests.rs index 368510acb6..d5a1e6424b 100644 --- a/cmd/crates/stellar-ledger/tests/test/emulator_tests.rs +++ b/cmd/crates/stellar-ledger/tests/test/emulator_tests.rs @@ -33,26 +33,21 @@ mod test_helpers { } } +use test_case::test_case; use test_helpers::test::{ emulator_http_transport::EmulatorHttpTransport, speculos::{Args, Speculos}, }; +#[test_case("nanos".to_string() ; "when the device is NanoS")] +#[test_case("nanox".to_string() ; "when the device is NanoX")] +#[test_case("nanosp".to_string() ; "when the device is NanoS Plus")] #[tokio::test] -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(), - }; - println!("Running test_get_public_key for {device_model}"); - test_get_public_key(args).await; - } -} - -async fn test_get_public_key(image_args: Args) { +async fn test_get_public_key(ledger_device_model: String) { + let args = Args { + ledger_device_model, + }; let docker = clients::Cli::default(); - 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); @@ -78,21 +73,16 @@ async fn test_get_public_key(image_args: Args) { node.stop(); } +#[test_case("nanos".to_string() ; "when the device is NanoS")] +#[test_case("nanox".to_string() ; "when the device is NanoX")] +#[test_case("nanosp".to_string() ; "when the device is NanoS Plus")] #[tokio::test] -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(), - }; - println!("Running test_get_app_configuration for {device_model}"); - test_get_app_configuration(args).await; - } -} - -async fn test_get_app_configuration(image_args: Args) { +async fn test_get_app_configuration(ledger_device_model: String) { + let args = Args { + ledger_device_model, + }; let docker = clients::Cli::default(); - let node = docker.run((Speculos::new(), 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; @@ -113,21 +103,16 @@ async fn test_get_app_configuration(image_args: Args) { node.stop(); } +#[test_case("nanos".to_string() ; "when the device is NanoS")] +#[test_case("nanox".to_string() ; "when the device is NanoX")] +#[test_case("nanosp".to_string() ; "when the device is NanoS Plus")] #[tokio::test] -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) { +async fn test_sign_tx(ledger_device_model: String) { + let args = Args { + ledger_device_model, + }; let docker = clients::Cli::default(); - let node = docker.run((Speculos::new(), image_args.clone())); + let node = docker.run((Speculos::new(), args.clone())); 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; @@ -190,7 +175,6 @@ async fn test_sign_tx(image_args: Args) { let ledger = Arc::clone(&ledger); async move { ledger.sign_transaction(path, tx, test_network_hash()).await } }); - 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(); @@ -210,21 +194,17 @@ async fn test_sign_tx(image_args: Args) { node.stop(); } +#[test_case("nanos".to_string() ; "when the device is NanoS")] +#[test_case("nanox".to_string() ; "when the device is NanoX")] +#[test_case("nanosp".to_string() ; "when the device is NanoS Plus")] #[tokio::test] -async fn test_sign_tx_hash_when_hash_signing_is_not_enabled_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_hash_when_hash_signing_is_not_enabled for {device_model}"); - test_sign_tx_hash_when_hash_signing_is_not_enabled(args).await; - } -} +async fn test_sign_tx_hash_when_hash_signing_is_not_enabled(ledger_device_model: String) { + let args = Args { + ledger_device_model, + }; -async fn test_sign_tx_hash_when_hash_signing_is_not_enabled(image_args: Args) { let docker = clients::Cli::default(); - let node = docker.run((Speculos::new(), 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; @@ -246,21 +226,16 @@ async fn test_sign_tx_hash_when_hash_signing_is_not_enabled(image_args: Args) { node.stop(); } +#[test_case("nanos".to_string() ; "when the device is NanoS")] +#[test_case("nanox".to_string() ; "when the device is NanoX")] +#[test_case("nanosp".to_string() ; "when the device is NanoS Plus")] #[tokio::test] -async fn test_sign_tx_hash_when_hash_signing_is_enabled_for_different_ledger_devices() { - let device_models = ["nanos", "nanosp", "nanox"]; - for device_model in device_models.iter() { - let args = Args { - ledger_device_model: device_model.to_string(), - }; - println!("Running test_sign_tx_hash_when_hash_signing_is_enabled for {device_model}"); - test_sign_tx_hash_when_hash_signing_is_enabled(args).await; - } -} - -async fn test_sign_tx_hash_when_hash_signing_is_enabled(image_args: Args) { +async fn test_sign_tx_hash_when_hash_signing_is_enabled(ledger_device_model: String) { + let args = Args { + ledger_device_model, + }; let docker = clients::Cli::default(); - let node = docker.run((Speculos::new(), image_args.clone())); + let node = docker.run((Speculos::new(), args.clone())); let host_port = node.get_host_port_ipv4(9998); let ui_host_port: u16 = node.get_host_port_ipv4(5000); @@ -287,7 +262,6 @@ async fn test_sign_tx_hash_when_hash_signing_is_enabled(image_args: Args) { let ledger = Arc::clone(&ledger); async move { ledger.sign_transaction_hash(path, &test_hash).await } }); - let args = image_args.clone(); let approve = tokio::task::spawn(approve_tx_hash_signature( ui_host_port, args.ledger_device_model,