Skip to content

Commit

Permalink
fix: tests and clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Jun 20, 2024
1 parent 1795deb commit c5c9077
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 50 deletions.
7 changes: 6 additions & 1 deletion cmd/crates/soroban-test/tests/it/integration/custom_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions cmd/crates/soroban-test/tests/it/integration/dotenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -37,6 +38,7 @@ async fn current_env_not_overwritten() {
"CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4",
)
.arg("invoke")
.arg("--yes")
.arg("--")
.arg("hello")
.arg("--world=world")
Expand All @@ -60,6 +62,7 @@ async fn cli_args_have_priority() {
.arg("invoke")
.arg("--id")
.arg(id)
.arg("--yes")
.arg("--")
.arg("hello")
.arg("--world=world")
Expand Down
7 changes: 2 additions & 5 deletions cmd/crates/stellar-ledger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ unsafe impl<T> Sync for LedgerSigner<T> 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<LedgerSigner<TransportNativeHID>, Error> {
Ok(LedgerSigner {
Expand All @@ -100,11 +101,7 @@ where
pub fn new(transport: T) -> Self {
Self { transport }
}
pub fn native() -> Result<LedgerSigner<TransportNativeHID>, 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
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl Cmd {
let mut signers: Vec<StellarSigner> = vec![];
let mut parsed_args: Vec<ScVal> = 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);
Expand Down
45 changes: 2 additions & 43 deletions cmd/soroban-cli/src/commands/tx/sign.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 {
Expand All @@ -55,23 +31,6 @@ impl Cmd {
}

pub async fn sign(&self, tx: Transaction) -> Result<TransactionEnvelope, Error> {
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<TransactionEnvelope, Error> {
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?)
}
}

0 comments on commit c5c9077

Please sign in to comment.