Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,15 @@ jobs:
- uses: taiki-e/install-action@v2
with:
tool: nextest@0.9.98
- name: Build Starknet Ledger App (Nano X)
run: |
git clone --depth 1 --branch nanox_2.7.0_2.4.0_sdk_v26.0.2 \
https://github.com/LedgerHQ/app-starknet /tmp/app-starknet
cd /tmp/app-starknet/starknet
cargo +${RUST_NIGHTLY} ledger build nanox
mkdir -p ${GITHUB_WORKSPACE}/crates/sncast/tests/data/ledger-app
cp target/nanox/release/starknet \
${GITHUB_WORKSPACE}/crates/sncast/tests/data/ledger-app/nanox.elf
- name: Run tests (nextest)
run: cargo nextest run --no-fail-fast --cargo-profile ci -p sncast --features ledger-emulator ledger --run-ignored all

Expand Down
53 changes: 3 additions & 50 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ serde_path_to_error = "0.1.20"
serde_with = "3.18.0"
wiremock = "0.6.3"
coins-ledger = "0.13.0"
speculos-client = "0.1.2"
const-hex = "1.18.1"
indicatif = "0.18.3"
shell-words = "1.1.0"
Expand Down
1 change: 0 additions & 1 deletion crates/sncast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ wiremock.workspace = true
docs = { workspace = true, features = ["testing"] }
shared = { path = "../shared", features = ["testing"] }
packages_validation = { path = "../testing/packages_validation" }
speculos-client.workspace = true

[features]
default = []
Expand Down
Binary file not shown.
23 changes: 12 additions & 11 deletions crates/sncast/tests/docs_snippets/ledger.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::e2e::ledger::{automation, setup_speculos};
use crate::e2e::ledger::{automation, set_automation, setup_speculos};
use crate::helpers::constants::URL;
use crate::helpers::runner::runner;
use docs::snippet::SnippetType;
Expand All @@ -12,20 +12,21 @@ use tempfile::TempDir;

const DOCS_SNIPPETS_PORT_BASE: u16 = 4006;

async fn setup_speculos_automation(client: &Arc<speculos_client::SpeculosClient>, args: &[&str]) {
async fn setup_speculos_automation(
client: &Arc<crate::e2e::ledger::speculos::SpeculosClient>,
args: &[&str],
) {
if args.contains(&"get-public-key") && !args.contains(&"--no-display") {
client
.automation(&[automation::APPROVE_PUBLIC_KEY])
.await
.unwrap();
set_automation(client, &[automation::APPROVE_PUBLIC_KEY]).await;
} else if args.contains(&"sign-hash") {
client
.automation(&[
set_automation(
client,
&[
automation::ENABLE_BLIND_SIGN,
automation::APPROVE_BLIND_SIGN_HASH,
])
.await
.unwrap();
],
)
.await;
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/sncast/tests/docs_snippets/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#[cfg(feature = "ledger-emulator")]
pub mod ledger;
pub mod validation;
33 changes: 12 additions & 21 deletions crates/sncast/tests/e2e/ledger/account.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::fs;

use super::speculos::AutomationRule;
use crate::e2e::ledger::{
BRAAVOS_LEDGER_PATH, LEDGER_ACCOUNT_NAME, LEDGER_PUBLIC_KEY, OZ_LEDGER_PATH, READY_LEDGER_PATH,
TEST_LEDGER_PATH, TEST_LEDGER_PATH_STORED, automation, setup_speculos,
TEST_LEDGER_PATH, TEST_LEDGER_PATH_STORED, automation, set_automation, setup_speculos,
};
use crate::helpers::constants::URL;
use crate::helpers::fixtures::mint_token;
Expand All @@ -16,19 +17,17 @@ use shared::test_utils::output_assert::{assert_stderr_contains, assert_stdout_co
use snapbox::assert_data_eq;
use sncast::helpers::account::load_accounts;
use sncast::helpers::constants::{BRAAVOS_CLASS_HASH, OZ_CLASS_HASH, READY_CLASS_HASH};
use speculos_client::AutomationRule;
use tempfile::tempdir;
use test_case::test_case;

#[test_case("oz", "open_zeppelin", OZ_CLASS_HASH.into_hex_string(), 6001, &[automation::APPROVE_PUBLIC_KEY]; "oz_account_type")]
#[test_case("ready", "ready", READY_CLASS_HASH.into_hex_string(), 6002, &[automation::APPROVE_PUBLIC_KEY]; "ready_account_type")]
#[test_case("oz", "open_zeppelin", OZ_CLASS_HASH.into_hex_string(), 6001, &[]; "oz_account_type")]
#[test_case("ready", "ready", READY_CLASS_HASH.into_hex_string(), 6002, &[]; "ready_account_type")]
// Braavos calls sign_hash twice during fee estimation (tx_hash + aux_hash) because
// is_signer_interactive() always returns false — see BraavosAccountFactory::is_signer_interactive.
// That means we need ENABLE_BLIND_SIGN + two APPROVE_BLIND_SIGN_HASH after the public key approval.
// That means we need ENABLE_BLIND_SIGN + two APPROVE_BLIND_SIGN_HASH during creation.
#[test_case(
"braavos", "braavos", BRAAVOS_CLASS_HASH.into_hex_string(), 6003,
&[
automation::APPROVE_PUBLIC_KEY,
automation::ENABLE_BLIND_SIGN,
automation::APPROVE_BLIND_SIGN_HASH, // tx_hash
automation::APPROVE_BLIND_SIGN_HASH, // aux_hash
Expand All @@ -42,12 +41,12 @@ async fn test_create_ledger_account(
saved_type: &str,
class_hash: String,
port: u16,
automations: &[speculos_client::AutomationRule<'static>],
automations: &[AutomationRule<'static>],
) {
let (client, url) = setup_speculos(port);
let tempdir = tempdir().unwrap();

client.automation(automations).await.unwrap();
set_automation(&client, automations).await;

let output = runner(&[
"--accounts-file",
Expand Down Expand Up @@ -115,14 +114,9 @@ async fn test_create_ledger_account(
#[tokio::test]
#[ignore = "requires Speculos installation"]
async fn test_create_ledger_account_add_profile() {
let (client, url) = setup_speculos(6004);
let (_client, url) = setup_speculos(6004);
let tempdir = copy_config_to_tempdir("tests/data/files/snfoundry_correct.toml", None);

client
.automation(&[automation::APPROVE_PUBLIC_KEY])
.await
.unwrap();

let output = runner(&[
"--accounts-file",
"accounts.json",
Expand Down Expand Up @@ -159,32 +153,29 @@ async fn test_create_ledger_account_add_profile() {

#[test_case(
"oz", OZ_LEDGER_PATH, 6005,
// create: public key only (OZ skips signing during fee estimation)
// create: no confirmation needed
// deploy: enable blind sign + 1 sign_hash
&[
automation::APPROVE_PUBLIC_KEY,
automation::ENABLE_BLIND_SIGN,
automation::APPROVE_BLIND_SIGN_HASH,
];
"oz_account_type"
)]
#[test_case(
"ready", READY_LEDGER_PATH, 6006,
// create: public key only (Ready skips signing during fee estimation)
// create: no confirmation needed
// deploy: enable blind sign + 1 sign_hash
&[
automation::APPROVE_PUBLIC_KEY,
automation::ENABLE_BLIND_SIGN,
automation::APPROVE_BLIND_SIGN_HASH,
];
"ready_account_type"
)]
#[test_case(
"braavos", BRAAVOS_LEDGER_PATH, 6007,
// create: public key + enable blind sign + 2x sign_hash (tx_hash + aux_hash)
// create: enable blind sign + 2x sign_hash (tx_hash + aux_hash)
// deploy: 2x sign_hash again (tx_hash + aux_hash), blind sign already enabled
&[
automation::APPROVE_PUBLIC_KEY,
automation::ENABLE_BLIND_SIGN,
automation::APPROVE_BLIND_SIGN_HASH, // create: tx_hash
automation::APPROVE_BLIND_SIGN_HASH, // create: aux_hash
Expand All @@ -203,7 +194,7 @@ async fn test_deploy_ledger_account(
) {
let (client, url) = setup_speculos(port);

client.automation(automations).await.unwrap();
set_automation(&client, automations).await;

let tempdir = tempdir().unwrap();
let accounts_file = tempdir.path().join("accounts.json");
Expand Down
15 changes: 8 additions & 7 deletions crates/sncast/tests/e2e/ledger/basic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::e2e::ledger::{TEST_LEDGER_PATH, automation, setup_speculos};
use crate::e2e::ledger::{TEST_LEDGER_PATH, automation, set_automation, setup_speculos};
use crate::helpers::runner::runner;
use shared::test_utils::output_assert::{assert_stderr_contains, assert_stdout_contains};

Expand All @@ -12,7 +12,7 @@ async fn test_get_app_version() {
.assert()
.success();

assert_stdout_contains(output, "App Version: 2.3.4");
assert_stdout_contains(output, "App Version: 2.4.0");
}

#[tokio::test]
Expand Down Expand Up @@ -63,13 +63,14 @@ async fn test_get_public_key_with_confirmation() {
async fn test_sign_hash() {
let (client, url) = setup_speculos(4004);

client
.automation(&[
set_automation(
&client,
&[
automation::ENABLE_BLIND_SIGN,
automation::APPROVE_BLIND_SIGN_HASH,
])
.await
.unwrap();
],
)
.await;

let output = runner(&[
"ledger",
Expand Down
Loading
Loading