Skip to content

Commit

Permalink
Merge branch 'main' into feat/ledger-signing
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman authored May 2, 2024
2 parents b5fedfd + 6253b7a commit ba0a75c
Show file tree
Hide file tree
Showing 26 changed files with 756 additions and 104 deletions.
54 changes: 53 additions & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ tracing-subscriber = "0.3.16"
tracing-appender = "0.2.2"
which = "4.4.0"
wasmparser = "0.90.0"
directories = "5.0.1"
ulid = { version = "1.1" }
termcolor = "1.1.3"
termcolor_output = "1.0.1"
ed25519-dalek = "2.0.0"
Expand Down
1 change: 1 addition & 0 deletions cmd/crates/soroban-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ serde_json = "1.0.93"
which = { workspace = true }
tokio = "1.28.1"
walkdir = "2.4.0"
ulid.workspace = true

[features]
it = []
4 changes: 3 additions & 1 deletion cmd/crates/soroban-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ impl TestEnv {
.env("SOROBAN_ACCOUNT", TEST_ACCOUNT)
.env("SOROBAN_RPC_URL", &self.rpc_url)
.env("SOROBAN_NETWORK_PASSPHRASE", LOCAL_NETWORK_PASSPHRASE)
.env("XDG_CONFIG_HOME", self.temp_dir.as_os_str())
.env("XDG_CONFIG_HOME", self.temp_dir.join("config").as_os_str())
.env("XDG_DATA_HOME", self.temp_dir.join("data").as_os_str())
.current_dir(&self.temp_dir);
cmd
}
Expand Down Expand Up @@ -246,6 +247,7 @@ impl TestEnv {
verbose: false,
very_verbose: false,
list: false,
no_cache: false,
}),
Some(&config),
)
Expand Down
8 changes: 8 additions & 0 deletions cmd/crates/soroban-test/tests/it/integration/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::integration::util::extend_contract;

use super::util::{deploy_hello, extend, HELLO_WORLD};

#[allow(clippy::too_many_lines)]
#[tokio::test]
async fn invoke() {
let sandbox = &TestEnv::new();
Expand Down Expand Up @@ -63,6 +64,13 @@ async fn invoke() {
};
let id = &deploy_hello(sandbox).await;
extend_contract(sandbox, id).await;
let uid = sandbox
.new_assert_cmd("cache")
.arg("actionlog")
.arg("ls")
.assert()
.stdout_as_str();
ulid::Ulid::from_string(&uid).expect("invalid ulid");
// Note that all functions tested here have no state
invoke_hello_world(sandbox, id);

Expand Down
2 changes: 2 additions & 0 deletions cmd/soroban-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ tracing-subscriber = { workspace = true, features = ["env-filter"] }
cargo_metadata = "0.15.4"
pathdiff = "0.2.1"
dotenvy = "0.15.7"
directories = { workspace = true }
ulid = { workspace = true, features = ["serde"] }
strum = "0.17.1"
strum_macros = "0.17.1"
gix = { version = "0.58.0", default-features = false, features = [
Expand Down
44 changes: 44 additions & 0 deletions cmd/soroban-cli/src/commands/cache/actionlog/ls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use clap::command;

use super::super::super::config::locator;
use crate::commands::config::data;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Config(#[from] locator::Error),
#[error(transparent)]
Data(#[from] data::Error),
}

#[derive(Debug, clap::Parser, Clone)]
#[group(skip)]
pub struct Cmd {
#[command(flatten)]
pub config_locator: locator::Args,

#[arg(long, short = 'l')]
pub long: bool,
}

impl Cmd {
pub fn run(&self) -> Result<(), Error> {
let res = if self.long { self.ls_l() } else { self.ls() }?.join("\n");
println!("{res}");
Ok(())
}

pub fn ls(&self) -> Result<Vec<String>, Error> {
Ok(data::list_ulids()?
.iter()
.map(ToString::to_string)
.collect())
}

pub fn ls_l(&self) -> Result<Vec<String>, Error> {
Ok(data::list_actions()?
.iter()
.map(ToString::to_string)
.collect())
}
}
30 changes: 30 additions & 0 deletions cmd/soroban-cli/src/commands/cache/actionlog/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use clap::Parser;

pub mod ls;
pub mod read;

#[derive(Debug, Parser)]
pub enum Cmd {
/// List cached actions (transactions, simulations)
Ls(ls::Cmd),
/// Read cached action
Read(read::Cmd),
}

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Ls(#[from] ls::Error),
#[error(transparent)]
Read(#[from] read::Error),
}

impl Cmd {
pub fn run(&self) -> Result<(), Error> {
match self {
Cmd::Ls(cmd) => cmd.run()?,
Cmd::Read(cmd) => cmd.run()?,
};
Ok(())
}
}
39 changes: 39 additions & 0 deletions cmd/soroban-cli/src/commands/cache/actionlog/read.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use std::{fs, io, path::PathBuf};

use super::super::super::config::locator;
use crate::commands::config::data;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Config(#[from] locator::Error),
#[error(transparent)]
Data(#[from] data::Error),
#[error("failed to find cache entry {0}")]
NotFound(String),
#[error(transparent)]
SerdeJson(#[from] serde_json::Error),
}

#[derive(Debug, clap::Parser, Clone)]
#[group(skip)]
pub struct Cmd {
/// ID of the cache entry
#[arg(long)]
pub id: String,
}

impl Cmd {
pub fn run(&self) -> Result<(), Error> {
let file = self.file()?;
tracing::debug!("reading file {}", file.display());
let mut file = fs::File::open(file).map_err(|_| Error::NotFound(self.id.clone()))?;
let mut stdout = io::stdout();
let _ = io::copy(&mut file, &mut stdout);
Ok(())
}

pub fn file(&self) -> Result<PathBuf, Error> {
Ok(data::actions_dir()?.join(&self.id).with_extension("json"))
}
}
30 changes: 30 additions & 0 deletions cmd/soroban-cli/src/commands/cache/clean.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::{fs, io::ErrorKind};

use super::super::config::locator;
use crate::commands::config::data;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Config(#[from] locator::Error),
#[error(transparent)]
Data(#[from] data::Error),
#[error(transparent)]
Io(#[from] std::io::Error),
}

#[derive(Debug, clap::Parser, Clone)]
#[group(skip)]
pub struct Cmd {}

impl Cmd {
pub fn run(&self) -> Result<(), Error> {
let binding = data::project_dir()?;
let dir = binding.data_dir();
match fs::remove_dir_all(dir) {
Err(err) if err.kind() == ErrorKind::NotFound => (),
r => r?,
}
Ok(())
}
}
38 changes: 38 additions & 0 deletions cmd/soroban-cli/src/commands/cache/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use clap::Parser;

pub mod actionlog;
pub mod clean;
pub mod path;

#[derive(Debug, Parser)]
pub enum Cmd {
/// Delete the cache
Clean(clean::Cmd),
/// Show the location of the cache
Path(path::Cmd),
/// Access details about cached actions like transactions, and simulations.
/// (Experimental. May see breaking changes at any time.)
#[command(subcommand)]
Actionlog(actionlog::Cmd),
}

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Clean(#[from] clean::Error),
#[error(transparent)]
Path(#[from] path::Error),
#[error(transparent)]
Actionlog(#[from] actionlog::Error),
}

impl Cmd {
pub fn run(&self) -> Result<(), Error> {
match self {
Cmd::Clean(cmd) => cmd.run()?,
Cmd::Path(cmd) => cmd.run()?,
Cmd::Actionlog(cmd) => cmd.run()?,
};
Ok(())
}
}
21 changes: 21 additions & 0 deletions cmd/soroban-cli/src/commands/cache/path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use super::super::config::locator;
use crate::commands::config::data;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Config(#[from] locator::Error),
#[error(transparent)]
Data(#[from] data::Error),
}

#[derive(Debug, clap::Parser, Clone)]
#[group(skip)]
pub struct Cmd {}

impl Cmd {
pub fn run(&self) -> Result<(), Error> {
println!("{}", data::data_local_dir()?.to_string_lossy());
Ok(())
}
}
Loading

0 comments on commit ba0a75c

Please sign in to comment.