Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cache sub commands and allow for proper transaction data logging #1173

Merged
merged 32 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e4319e0
feat: use data directory and store simulations and transaction responses
willemneal Mar 7, 2024
2efce94
feat: add data logging to all commands that use a transaction
willemneal Mar 7, 2024
e93a3a2
feat: add "--no-cache" global arg
willemneal Mar 9, 2024
cbf8d70
feat: add spec cache, speeding up `invoke`
willemneal Mar 11, 2024
6a8891c
fix: clippy and fmt
willemneal Mar 11, 2024
9cf10f3
feat: implement display for Dated Action to see formated list of actions
willemneal Mar 12, 2024
976825e
fix: docs
willemneal Mar 28, 2024
f5ca6dd
feat: rename to cache command
willemneal Mar 28, 2024
a1d8a50
fix: revert change to invoke test
willemneal Apr 8, 2024
4ca157c
fix: md
willemneal Apr 8, 2024
445a15d
feat: cache read
willemneal Apr 15, 2024
9210164
fix: clippy
willemneal Apr 16, 2024
38a290e
fix: docs
willemneal Apr 16, 2024
f417924
fix: fetch SAC contract spec
willemneal Apr 16, 2024
26ddb5a
fix: PR suggestions
willemneal Apr 23, 2024
ead02f2
fix: remove option when cleaning and fix up refactor
willemneal Apr 23, 2024
a9e311d
feat: create data_local_dir function to ensure consistent location
willemneal Apr 23, 2024
ed02780
fix: md
willemneal Apr 23, 2024
93c1a1c
Merge branch 'main' into feat/data_logging
leighmcculloch Apr 30, 2024
b5642c0
Merge branch 'main' into feat/data_logging
willemneal May 1, 2024
8b4d359
Merge remote-tracking branch 'origin/main' into feat/data_logging
willemneal May 1, 2024
c745de7
fix: add actionlog subcommand
willemneal May 1, 2024
eecf3e3
Merge branch 'main' into feat/data_logging
leighmcculloch May 2, 2024
a99b828
com -> org
leighmcculloch May 2, 2024
e4f03c1
fix clean erroring on not found
leighmcculloch May 2, 2024
a0e1104
rename info to path and add experimental doc
leighmcculloch May 2, 2024
6d5a5e3
use terms simulate and send for consistency with actions a user performs
leighmcculloch May 2, 2024
c0bf977
simply the actionlog cache output
leighmcculloch May 2, 2024
def7d29
use snake_case for json to match other json the cli outputs
leighmcculloch May 2, 2024
d15db7c
match names in output
leighmcculloch May 2, 2024
72ab2b7
Update soroban-cli-full-docs.md
leighmcculloch May 2, 2024
e996366
add room for more data stored with actions
leighmcculloch May 2, 2024
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
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 @@ -85,6 +85,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
Loading