From c5c9077cf1d8f10fe4ba85d6ecc8288d6d7b3eec Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Thu, 20 Jun 2024 09:41:38 -0400 Subject: [PATCH] fix: tests and clippy --- .../tests/it/integration/custom_types.rs | 7 ++- .../tests/it/integration/dotenv.rs | 3 ++ cmd/crates/stellar-ledger/src/lib.rs | 7 +-- .../src/commands/contract/invoke.rs | 2 +- cmd/soroban-cli/src/commands/tx/sign.rs | 45 +------------------ 5 files changed, 14 insertions(+), 50 deletions(-) diff --git a/cmd/crates/soroban-test/tests/it/integration/custom_types.rs b/cmd/crates/soroban-test/tests/it/integration/custom_types.rs index 6739ff3da..1e97129f6 100644 --- a/cmd/crates/soroban-test/tests/it/integration/custom_types.rs +++ b/cmd/crates/soroban-test/tests/it/integration/custom_types.rs @@ -9,7 +9,12 @@ use super::util::invoke_with_roundtrip; fn invoke_custom(e: &TestEnv, id: &str, func: &str) -> assert_cmd::Command { let mut s = e.new_assert_cmd("contract"); - s.arg("invoke").arg("--id").arg(id).arg("--").arg(func); + s.arg("invoke") + .arg("--id") + .arg(id) + .arg("--yes") + .arg("--") + .arg(func); s } diff --git a/cmd/crates/soroban-test/tests/it/integration/dotenv.rs b/cmd/crates/soroban-test/tests/it/integration/dotenv.rs index b8e76d1fc..feda11be5 100644 --- a/cmd/crates/soroban-test/tests/it/integration/dotenv.rs +++ b/cmd/crates/soroban-test/tests/it/integration/dotenv.rs @@ -18,6 +18,7 @@ async fn can_read_file() { write_env_file(e, &id); e.new_assert_cmd("contract") .arg("invoke") + .arg("--yes") .arg("--") .arg("hello") .arg("--world=world") @@ -37,6 +38,7 @@ async fn current_env_not_overwritten() { "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4", ) .arg("invoke") + .arg("--yes") .arg("--") .arg("hello") .arg("--world=world") @@ -60,6 +62,7 @@ async fn cli_args_have_priority() { .arg("invoke") .arg("--id") .arg(id) + .arg("--yes") .arg("--") .arg("hello") .arg("--world=world") diff --git a/cmd/crates/stellar-ledger/src/lib.rs b/cmd/crates/stellar-ledger/src/lib.rs index 45e8aea4c..69789b735 100644 --- a/cmd/crates/stellar-ledger/src/lib.rs +++ b/cmd/crates/stellar-ledger/src/lib.rs @@ -86,6 +86,7 @@ unsafe impl Sync for LedgerSigner where T: Exchange {} /// Returns a new `LedgerSigner` with a native HID transport, e.i. the transport is connected to the Ledger device /// /// # Errors +/// /// Returns an error if there is an issue with connecting with the device pub fn native() -> Result, Error> { Ok(LedgerSigner { @@ -100,11 +101,7 @@ where pub fn new(transport: T) -> Self { Self { transport } } - pub fn native() -> Result, Error> { - Ok(LedgerSigner { - transport: get_transport()?, - }) - } + /// Get the device app's configuration /// # Errors /// Returns an error if there is an issue with connecting with the device or getting the config from the device diff --git a/cmd/soroban-cli/src/commands/contract/invoke.rs b/cmd/soroban-cli/src/commands/contract/invoke.rs index 9ea6e9015..5065d3e3a 100644 --- a/cmd/soroban-cli/src/commands/contract/invoke.rs +++ b/cmd/soroban-cli/src/commands/contract/invoke.rs @@ -199,7 +199,7 @@ impl Cmd { let mut signers: Vec = vec![]; let mut parsed_args: Vec = Vec::new(); for i in func.inputs.iter() { - let (val, signer) = self.parse_arg(i, &matches_, config, &spec).await?; + let (val, signer) = self.parse_arg(i, matches_, config, &spec).await?; parsed_args.push(val); if let Some(signer) = signer { signers.push(signer); diff --git a/cmd/soroban-cli/src/commands/tx/sign.rs b/cmd/soroban-cli/src/commands/tx/sign.rs index e9f3a86f1..da48182a4 100644 --- a/cmd/soroban-cli/src/commands/tx/sign.rs +++ b/cmd/soroban-cli/src/commands/tx/sign.rs @@ -1,8 +1,6 @@ -use std::io; - use crate::xdr::{self, Limits, Transaction, TransactionEnvelope, WriteXdr}; -use crate::signer::{self, native, LocalKey}; +use crate::signer; #[derive(thiserror::Error, Debug)] pub enum Error { @@ -13,36 +11,14 @@ pub enum Error { #[error(transparent)] Config(#[from] super::super::config::Error), #[error(transparent)] - StellarStrkey(#[from] stellar_strkey::DecodeError), - #[error(transparent)] Xdr(#[from] xdr::Error), - #[error(transparent)] - Io(#[from] io::Error), - #[error(transparent)] - Ledger(#[from] stellar_ledger::Error), - #[error(transparent)] - Rpc(#[from] soroban_rpc::Error), - #[error("only transaction v1 is supported")] - TransactionV1Expected, } #[derive(Debug, clap::Parser, Clone)] #[group(skip)] pub struct Cmd { - /// Confirm that a signature can be signed by the given keypair automatically. - #[arg(long, short = 'y')] - pub yes: bool, #[clap(flatten)] pub config: super::super::config::Args, - /// How to sign transaction - #[arg(long, value_enum, default_value = "file")] - pub signer: SignerType, -} - -#[derive(clap::ValueEnum, Clone, Debug)] -pub enum SignerType { - File, - Ledger, } impl Cmd { @@ -55,23 +31,6 @@ impl Cmd { } pub async fn sign(&self, tx: Transaction) -> Result { - match self.signer { - SignerType::File => Ok(self - .config - .sign(&LocalKey::new(self.config.key_pair()?, !self.yes), tx) - .await?), - SignerType::Ledger => self.sign_ledger(tx).await, - } - } - - pub async fn sign_ledger(&self, tx: Transaction) -> Result { - let index: u32 = self - .config - .hd_path - .unwrap_or_default() - .try_into() - .expect("usize bigger than u32"); - let signer = native(index)?; - Ok(self.config.sign(&signer, tx).await?) + Ok(self.config.sign_with_local_key(tx).await?) } }