Skip to content

Commit 3509f73

Browse files
committed
Reimplement speculos-client communication
1 parent 6065996 commit 3509f73

7 files changed

Lines changed: 236 additions & 64 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ serde_path_to_error = "0.1.20"
122122
serde_with = "3.18.0"
123123
wiremock = "0.6.3"
124124
coins-ledger = "0.13.0"
125-
speculos-client = { git = "https://github.com/MKowalski8/speculos-client", rev = "58d9523" }
126125
const-hex = "1.18.1"
127126
indicatif = "0.18.3"
128127
shell-words = "1.1.0"

crates/sncast/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ wiremock.workspace = true
8282
docs = { workspace = true, features = ["testing"] }
8383
shared = { path = "../shared", features = ["testing"] }
8484
packages_validation = { path = "../testing/packages_validation" }
85-
speculos-client.workspace = true
8685

8786
[features]
8887
default = []

crates/sncast/tests/docs_snippets/ledger.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use tempfile::TempDir;
1212

1313
const DOCS_SNIPPETS_PORT_BASE: u16 = 4006;
1414

15-
async fn setup_speculos_automation(client: &Arc<speculos_client::SpeculosClient>, args: &[&str]) {
15+
async fn setup_speculos_automation(
16+
client: &Arc<crate::e2e::ledger::speculos::SpeculosClient>,
17+
args: &[&str],
18+
) {
1619
if args.contains(&"get-public-key") && !args.contains(&"--no-display") {
1720
set_automation(client, &[automation::APPROVE_PUBLIC_KEY]).await;
1821
} else if args.contains(&"sign-hash") {

crates/sncast/tests/e2e/ledger/account.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::fs;
22

3+
use super::speculos::AutomationRule;
34
use crate::e2e::ledger::{
45
BRAAVOS_LEDGER_PATH, LEDGER_ACCOUNT_NAME, LEDGER_PUBLIC_KEY, OZ_LEDGER_PATH, READY_LEDGER_PATH,
56
TEST_LEDGER_PATH, TEST_LEDGER_PATH_STORED, automation, set_automation, setup_speculos,
@@ -16,7 +17,6 @@ use shared::test_utils::output_assert::{assert_stderr_contains, assert_stdout_co
1617
use snapbox::assert_data_eq;
1718
use sncast::helpers::account::load_accounts;
1819
use sncast::helpers::constants::{BRAAVOS_CLASS_HASH, OZ_CLASS_HASH, READY_CLASS_HASH};
19-
use speculos_client::AutomationRule;
2020
use tempfile::tempdir;
2121
use test_case::test_case;
2222

@@ -41,7 +41,7 @@ async fn test_create_ledger_account(
4141
saved_type: &str,
4242
class_hash: String,
4343
port: u16,
44-
automations: &[speculos_client::AutomationRule<'static>],
44+
automations: &[AutomationRule<'static>],
4545
) {
4646
let (client, url) = setup_speculos(port);
4747
let tempdir = tempdir().unwrap();

crates/sncast/tests/e2e/ledger/mod.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ use sncast::helpers::constants::{
1414
};
1515
use sncast::helpers::ledger::{DerivationPathParser, SncastLedgerTransport};
1616
use sncast::response::ui::UI;
17-
use speculos_client::{
18-
AutomationAction, AutomationCondition, AutomationRule, Button, DeviceModel, SpeculosClient,
19-
};
17+
use speculos::{AutomationAction, AutomationCondition, AutomationRule, Button, SpeculosClient};
2018
use starknet_rust::accounts::{AccountFactory, ArgentAccountFactory, OpenZeppelinAccountFactory};
2119
use starknet_rust::core::types::{BlockId, BlockTag};
2220
use starknet_rust::providers::Provider;
@@ -30,6 +28,7 @@ use url::Url;
3028
mod account;
3129
mod basic;
3230
mod network;
31+
pub(crate) mod speculos;
3332

3433
pub(crate) const OZ_LEDGER_PATH: &str = "m//starknet'/sncast'/0'/0'/0";
3534
pub(crate) const READY_LEDGER_PATH: &str = "m//starknet'/sncast'/0'/1'/0";
@@ -46,21 +45,19 @@ pub(crate) const LEDGER_PUBLIC_KEY: &str =
4645
pub(crate) const LEDGER_ACCOUNT_NAME: &str = "my_ledger";
4746

4847
pub(crate) fn setup_speculos(port: u16) -> (Arc<SpeculosClient>, String) {
49-
let client = Arc::new(SpeculosClient::new(DeviceModel::Nanox, port, APP_PATH).unwrap());
48+
let client = Arc::new(SpeculosClient::new(port, APP_PATH).unwrap());
5049
let url = format!("http://127.0.0.1:{port}");
5150
(client, url)
5251
}
5352

54-
/// Sets automation rules and, when `ENABLE_BLIND_SIGN` is among them, presses RIGHT to
55-
/// navigate from the home screen to "App settings" so the rule triggers immediately.
53+
/// Sets automation rules and, when `ENABLE_BLIND_SIGN` is among them, presses RIGHT so the
54+
/// blind-sign flow advances immediately.
5655
pub(crate) async fn set_automation(
5756
client: &SpeculosClient,
58-
rules: &[speculos_client::AutomationRule<'static>],
57+
rules: &[speculos::AutomationRule<'static>],
5958
) {
6059
client.automation(rules).await.unwrap();
61-
let needs_blind_sign = rules
62-
.iter()
63-
.any(|r| r.text.as_deref() == Some("App settings"));
60+
let needs_blind_sign = rules.iter().any(|r| r == &automation::ENABLE_BLIND_SIGN);
6461
if needs_blind_sign {
6562
client.click_button(Button::Right).await.unwrap();
6663
}

0 commit comments

Comments
 (0)