Skip to content

Commit

Permalink
Fix/ledger tests org update (#1343)
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman authored Jun 4, 2024
1 parent 67840a3 commit d7fdbd4
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd/crates/stellar-ledger/src/hd_path.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::Error;

#[derive(Clone, Copy)]
pub struct HdPath(pub(crate) u32);
pub struct HdPath(pub u32);

impl HdPath {
pub fn depth(&self) -> u8 {
Expand Down
19 changes: 10 additions & 9 deletions cmd/crates/stellar-ledger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@ use stellar_xdr::curr::{
};

pub use crate::signer::Blob;

mod emulator_http_transport;
mod signer;
mod speculos;

#[cfg(all(test, feature = "emulator-tests"))]
mod emulator_tests;
pub mod hd_path;
mod signer;

// this is from https://github.com/LedgerHQ/ledger-live/blob/36cfbf3fa3300fd99bcee2ab72e1fd8f280e6280/libs/ledgerjs/packages/hw-app-str/src/Str.ts#L181
const APDU_MAX_SIZE: u8 = 150;
Expand Down Expand Up @@ -300,16 +294,23 @@ fn get_transport() -> Result<TransportNativeHID, Error> {

pub const TEST_NETWORK_PASSPHRASE: &[u8] = b"Test SDF Network ; September 2015";
#[cfg(test)]
fn test_network_hash() -> Hash {
pub fn test_network_hash() -> Hash {
use sha2::Digest;
Hash(sha2::Sha256::digest(TEST_NETWORK_PASSPHRASE).into())
}

#[cfg(test)]
mod test {
mod test_helpers {
pub mod test {
include!("../tests/utils/mod.rs");
}
}
use httpmock::prelude::*;
use serde_json::json;

use crate::{emulator_http_transport::EmulatorHttpTransport, Blob};
use crate::Blob;
use test_helpers::test::emulator_http_transport::EmulatorHttpTransport;

use soroban_env_host::xdr::Transaction;
use std::vec;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use ledger_transport::Exchange;
use serde::Deserialize;
use soroban_env_host::xdr::Transaction;
use soroban_env_host::xdr::{self, Operation, OperationBody, Uint256};
use soroban_env_host::xdr::{Hash, Transaction};
use std::vec;

use crate::emulator_http_transport::EmulatorHttpTransport;
use crate::hd_path::HdPath;
use crate::speculos::Speculos;
use crate::{test_network_hash, Blob, Error, LedgerSigner};
use stellar_ledger::hd_path::HdPath;
use stellar_ledger::{Blob, Error, LedgerSigner};

use std::sync::Arc;
use std::{collections::HashMap, time::Duration};
Expand All @@ -19,10 +17,24 @@ use stellar_xdr::curr::{
use testcontainers::clients;
use tokio::time::sleep;

pub const TEST_NETWORK_PASSPHRASE: &[u8] = b"Test SDF Network ; September 2015";
pub fn test_network_hash() -> Hash {
use sha2::Digest;
Hash(sha2::Sha256::digest(TEST_NETWORK_PASSPHRASE).into())
}

fn ledger(host_port: u16) -> LedgerSigner<impl Exchange> {
LedgerSigner::new(get_http_transport("127.0.0.1", host_port).unwrap())
}

mod test_helpers {
pub mod test {
include!("../utils/mod.rs");
}
}

use test_helpers::test::{emulator_http_transport::EmulatorHttpTransport, speculos::Speculos};

#[tokio::test]
async fn test_get_public_key() {
let docker = clients::Cli::default();
Expand Down
2 changes: 2 additions & 0 deletions cmd/crates/stellar-ledger/tests/test/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[cfg(all(test, feature = "emulator-tests"))]
mod emulator_tests;
2 changes: 2 additions & 0 deletions cmd/crates/stellar-ledger/tests/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub(crate) mod emulator_http_transport;
pub(crate) mod speculos;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use testcontainers::{core::WaitFor, Image, ImageArgs};

const NAME: &str = "docker.io/zondax/builder-zemu";
const TAG: &str = "speculos-3a3439f6b45eca7f56395673caaf434c202e7005";
const TEST_SEED_PHRASE: &str =
"\"other base behind follow wet put glad muscle unlock sell income october\"";

#[allow(dead_code)]
static ENV: &Map = &Map(phf::phf_map! {
Expand All @@ -28,7 +30,10 @@ impl Speculos {
#[allow(dead_code)]
pub fn new() -> Self {
#[allow(unused_mut)]
let apps_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("apps");
let apps_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests")
.join("test_fixtures")
.join("apps");
let mut volumes = HashMap::new();
volumes.insert(
apps_dir.to_str().unwrap().to_string(),
Expand All @@ -44,7 +49,7 @@ pub struct Args;
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 command_string = format!("/home/zondax/speculos/speculos.py --log-level speculos:DEBUG --color JADE_GREEN --display headless -s {TEST_SEED_PHRASE} -m nanos {container_elf_path}");
Box::new(vec![command_string].into_iter())
}
}
Expand Down

0 comments on commit d7fdbd4

Please sign in to comment.